Skip to content

Commit 7aef49d

Browse files
committed
fix: handle body and comments as intented
1 parent 0ca2986 commit 7aef49d

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ Ideal for CI/CD workflows that need to:
2020

2121
## Inputs
2222

23-
| Name | Description | Default | Required |
24-
| ----------- | --------------------------------------------------------------------------------- | -------------------------- | -------- |
25-
| `token` | GitHub token (PAT or `${{ github.token }}`) used for authentication | `${{ github.token }}` | Yes |
26-
| `mode` | Operation mode: `create` or `close` | `create` | Yes |
27-
| `state` | Issue state filter when searching for existing issues: `open`, `closed`, or `all` | `open` | Yes |
28-
| `title` | Title of the issue to create or update | | Yes |
29-
| `labels` | Comma-separated list of labels used for creation and search | | No |
30-
| `assignees` | Comma-separated list of users to assign the issue to | | No |
31-
| `body` | Custom body text for the issue (overrides `template`) | | No |
32-
| `comment` | Optional comment text to add to an existing issue | | No |
33-
| `repo` | Repository to operate on (`owner/repo`) | `${{ github.repository }}` | Yes |
23+
| Name | Description | Default | Required |
24+
| ----------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------------------ | -------- |
25+
| `token` | GitHub token (or PAT) used for authentication | `${{github.token}}` | Yes |
26+
| `mode` | Operation mode: `create` or `close` | `create` | Yes |
27+
| `state` | Issue state filter when searching for existing issues: `open`, `closed`, or `all` | `open` | Yes |
28+
| `title` | Title of the issue to create or update | - | Yes |
29+
| `labels` | Comma-separated list of labels used for creation and search | - | No |
30+
| `assignees` | Comma-separated list of users to assign the issue to | - | No |
31+
| `body` | Optional body text for the issue | - | No |
32+
| `comment` | Optional comment text to add to an existing issue instead of updating the issue body, or as closing comment if closing the issue | - | No |
33+
| `repo` | Repository to operate on (`owner/repo`) | `${{github.repository}}` | Yes |
3434

3535
## Example Usage
3636

src/main.sh

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,20 @@ echo '::endgroup::'
2929

3030
ISSUE_NUMBER=$(gh issue list --repo "${REPO}" --state "${STATE}" --label "${LABELS}" --search "in:title \"${TITLE}\"" --limit 1 --json number --jq '.[].number' || true)
3131

32-
# Perform action based on mode
3332
case "${MODE}" in
3433
create)
35-
# Determine body args
36-
if [ -n "${BODY}" ]; then
37-
BODY_ARGS="\"${BODY}\""
38-
else
39-
BODY_ARGS="\"Auto-generated issue with title: ${TITLE}\""
40-
fi
41-
4234
if [ -n "${ISSUE_NUMBER}" ]; then
4335
echo "Issue already exists (#${ISSUE_NUMBER}), updating instead."
4436
if [ -n "${COMMENT}" ]; then
4537
echo "Adding comment to existing issue..."
46-
gh issue comment "${ISSUE_NUMBER}" --repo "${REPO}" --body "${COMMENT}"
38+
gh issue comment "${ISSUE_NUMBER}" --repo "${REPO}" --body "${COMMENT}" --edit-last --create-if-none --yes
4739
else
4840
echo "Updating issue body..."
49-
gh issue edit "${ISSUE_NUMBER}" --repo "${REPO}" --title "${TITLE}" --body "${BODY_ARGS}"
41+
gh issue edit "${ISSUE_NUMBER}" --repo "${REPO}" --title "${TITLE}" --body "${BODY}"
5042
fi
5143
else
5244
echo "Creating new issue..."
53-
gh issue create --repo "${REPO}" --title "${TITLE}" --body "${BODY_ARGS}" --label "${LABELS}" --assignee "${ASSIGNEES}"
45+
gh issue create --repo "${REPO}" --title "${TITLE}" --body "${BODY}" --label "${LABELS}" --assignee "${ASSIGNEES}"
5446
fi
5547
;;
5648
close)
@@ -59,11 +51,12 @@ close)
5951
exit 0
6052
fi
6153
if [ -n "${COMMENT}" ]; then
62-
echo "Adding closure comment..."
63-
gh issue comment "${ISSUE_NUMBER}" --repo "${REPO}" --body "${COMMENT}"
54+
echo "Closing issue #${ISSUE_NUMBER} with comment..."
55+
gh issue close "${ISSUE_NUMBER}" --repo "${REPO}" --comment "${COMMENT}"
56+
else
57+
echo "Closing issue #${ISSUE_NUMBER}..."
58+
gh issue close "${ISSUE_NUMBER}" --repo "${REPO}"
6459
fi
65-
echo "Closing issue #${ISSUE_NUMBER}..."
66-
gh issue close "${ISSUE_NUMBER}" --repo "${REPO}"
6760
;;
6861
*)
6962
echo "Invalid mode '${MODE}'. Valid options: create | close"

tests/test-close-existing-issue-with-comment.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ export INPUT_MODE="close"
99
export INPUT_TITLE="Hello world"
1010
export INPUT_COMMENT="Hello comment of world"
1111
output=$(bash "${SCRIPT_PATH}" 2>&1)
12-
assert_contains "$output" "Adding closure comment..."
13-
assert_contains "$output" "FAKE: added comment"
14-
assert_contains "$output" "Closing issue #42..."
12+
assert_contains "$output" "Closing issue #42 with comment..."
1513
assert_contains "$output" "FAKE: closed issue"
1614
echo "passed"
15+

0 commit comments

Comments
 (0)