Skip to content

Commit

Permalink
Merge pull request #5 from yumemi-inc/add_option
Browse files Browse the repository at this point in the history
Ad merge-commit-only option
  • Loading branch information
hkusu authored May 26, 2024
2 parents 2a7af7a + 094e744 commit 65a0b08
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ If you want to output in JSON or Markdown instead of plain text like above, spec
format: 'json' # or markdown
```

By default, list pull requests associated with merge commits.
To list pull requests associated with all commits, specify `true` for `merge-commit-only` input.

However, in this case, more pull requests can be detected, but the number of API calls will increase, so be careful when using it when the commit history is long.

```yaml
- uses: yumemi-inc/associated-pull-requests@v1
id: associated-pr
with:
merge-commit-only: false
```

### Specify comparison targets

Commits between `head-ref` input and `base-ref` input references are used to search for associated pull requests.
Expand Down
9 changes: 7 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ inputs:
description: 'Output format for list of pull request numbers. One of plain, json, markdown.'
required: false
default: 'plain'
merge-commit-only:
description: 'List pull requests associated with merge commits only.'
required: false
default: 'true'
head-ref:
description: 'Current branch, tag, or commit SHA to compare with base.'
required: false
Expand Down Expand Up @@ -49,6 +53,7 @@ runs:
IS_VALID_FORMAT: ${{ inputs.format != null && contains(fromJSON('["plain","json","markdown"]'), inputs.format) }}
HEAD_REF: ${{ inputs.head-ref }}
BASE_REF: ${{ inputs.base-ref }}
PARENTS_MIN_LENGTH: ${{ inputs.merge-commit-only != 'false' && '2' || '1' }}
HEAD_PR_NUMBER: ${{ github.event.pull_request.number || '-1' }}
FORMAT: ${{ inputs.format }}
GH_REPO: ${{ github.repository }} # for GitHub CLI
Expand All @@ -72,10 +77,10 @@ runs:
# ref: https://zenn.dev/yumemi_inc/articles/3ed5a217cf3cbb
# on windows, jq's return contains CR
sha_list="$(gh api "repos/{owner}/{repo}/compare/${base_sha}...${head_sha}" --paginate | jq -r '.commits[]|select(.parents|length>1)|.sha' | tr -d '\r')"
sha_list="$(gh api "repos/{owner}/{repo}/compare/${base_sha}...${head_sha}" --paginate | jq -r '.commits[]|select(.parents|length>='"$PARENTS_MIN_LENGTH"')|.sha' | tr -d '\r')"
for sha in $sha_list ; do
pr_number_list="$(gh api "repos/{owner}/{repo}/commits/${sha}/pulls" | jq '.[].number|select(.!='"${HEAD_PR_NUMBER}"')' | tr -d '\r')"
pr_number_list="$(gh api "repos/{owner}/{repo}/commits/${sha}/pulls" | jq '.[].number|select(.!='"$HEAD_PR_NUMBER"')' | tr -d '\r')"
for pr_number in $pr_number_list ; do
pr_number_array+=("$pr_number")
done
Expand Down

0 comments on commit 65a0b08

Please sign in to comment.