From fc91c92cf482b5b4e0ce6b243bae941a8312582a Mon Sep 17 00:00:00 2001 From: Hiroyuki Kusu Date: Sun, 26 May 2024 19:14:16 +0900 Subject: [PATCH 1/2] Ad merge-commit-only option --- README.md | 12 ++++++++++++ action.yml | 9 +++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5be35dc..f734c7e 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/action.yml b/action.yml index 8f004ba..9069419 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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 != 'flase' && '2' || '1' }} HEAD_PR_NUMBER: ${{ github.event.pull_request.number || '-1' }} FORMAT: ${{ inputs.format }} GH_REPO: ${{ github.repository }} # for GitHub CLI @@ -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 From 094e744905cd4435a0f7a7abb8b05e5e5be4709a Mon Sep 17 00:00:00 2001 From: Hiroyuki Kusu Date: Sun, 26 May 2024 21:00:27 +0900 Subject: [PATCH 2/2] Fix bug --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 9069419..ad7c781 100644 --- a/action.yml +++ b/action.yml @@ -53,7 +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 != 'flase' && '2' || '1' }} + 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