Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ Ideal for CI/CD workflows that need to:

## Inputs

| Name | Description | Default | Required |
| ----------- | --------------------------------------------------------------------------------- | -------------------------- | -------- |
| `token` | GitHub token (PAT or `${{ github.token }}`) used for authentication | `${{ github.token }}` | Yes |
| `mode` | Operation mode: `create` or `close` | `create` | Yes |
| `state` | Issue state filter when searching for existing issues: `open`, `closed`, or `all` | `open` | Yes |
| `title` | Title of the issue to create or update | — | Yes |
| `labels` | Comma-separated list of labels used for creation and search | — | No |
| `assignees` | Comma-separated list of users to assign the issue to | — | No |
| `body` | Custom body text for the issue (overrides `template`) | — | No |
| `comment` | Optional comment text to add to an existing issue | — | No |
| `repo` | Repository to operate on (`owner/repo`) | `${{ github.repository }}` | Yes |
| Name | Description | Default | Required |
| ----------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------------------ | -------- |
| `token` | GitHub token (or PAT) used for authentication | `${{github.token}}` | Yes |
| `mode` | Operation mode: `create` or `close` | `create` | Yes |
| `state` | Issue state filter when searching for existing issues: `open`, `closed`, or `all` | `open` | Yes |
| `title` | Title of the issue to create or update | - | Yes |
| `labels` | Comma-separated list of labels used for creation and search | - | No |
| `assignees` | Comma-separated list of users to assign the issue to | - | No |
| `body` | Optional body text for the issue | - | No |
| `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 |
| `repo` | Repository to operate on (`owner/repo`) | `${{github.repository}}` | Yes |

## Example Usage

Expand Down
23 changes: 8 additions & 15 deletions src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,20 @@ echo '::endgroup::'

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

# Perform action based on mode
case "${MODE}" in
create)
# Determine body args
if [ -n "${BODY}" ]; then
BODY_ARGS="\"${BODY}\""
else
BODY_ARGS="\"Auto-generated issue with title: ${TITLE}\""
fi

if [ -n "${ISSUE_NUMBER}" ]; then
echo "Issue already exists (#${ISSUE_NUMBER}), updating instead."
if [ -n "${COMMENT}" ]; then
echo "Adding comment to existing issue..."
gh issue comment "${ISSUE_NUMBER}" --repo "${REPO}" --body "${COMMENT}"
gh issue comment "${ISSUE_NUMBER}" --repo "${REPO}" --body "${COMMENT}" --edit-last --create-if-none --yes
else
echo "Updating issue body..."
gh issue edit "${ISSUE_NUMBER}" --repo "${REPO}" --title "${TITLE}" --body "${BODY_ARGS}"
gh issue edit "${ISSUE_NUMBER}" --repo "${REPO}" --title "${TITLE}" --body "${BODY}"
fi
else
echo "Creating new issue..."
gh issue create --repo "${REPO}" --title "${TITLE}" --body "${BODY_ARGS}" --label "${LABELS}" --assignee "${ASSIGNEES}"
gh issue create --repo "${REPO}" --title "${TITLE}" --body "${BODY}" --label "${LABELS}" --assignee "${ASSIGNEES}"
fi
;;
close)
Expand All @@ -59,11 +51,12 @@ close)
exit 0
fi
if [ -n "${COMMENT}" ]; then
echo "Adding closure comment..."
gh issue comment "${ISSUE_NUMBER}" --repo "${REPO}" --body "${COMMENT}"
echo "Closing issue #${ISSUE_NUMBER} with comment..."
gh issue close "${ISSUE_NUMBER}" --repo "${REPO}" --comment "${COMMENT}"
else
echo "Closing issue #${ISSUE_NUMBER}..."
gh issue close "${ISSUE_NUMBER}" --repo "${REPO}"
fi
echo "Closing issue #${ISSUE_NUMBER}..."
gh issue close "${ISSUE_NUMBER}" --repo "${REPO}"
;;
*)
echo "Invalid mode '${MODE}'. Valid options: create | close"
Expand Down
5 changes: 2 additions & 3 deletions tests/test-close-existing-issue-with-comment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export INPUT_MODE="close"
export INPUT_TITLE="Hello world"
export INPUT_COMMENT="Hello comment of world"
output=$(bash "${SCRIPT_PATH}" 2>&1)
assert_contains "$output" "Adding closure comment..."
assert_contains "$output" "FAKE: added comment"
assert_contains "$output" "Closing issue #42..."
assert_contains "$output" "Closing issue #42 with comment..."
assert_contains "$output" "FAKE: closed issue"
echo "passed"