-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b54550
commit 97fed9e
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# action.yml | ||
name: 'Link Pull Request to Issue' | ||
on: | ||
workflow_call: | ||
inputs: | ||
pr_number: | ||
description: 'Pull Request number' | ||
type: number | ||
required: true | ||
pr_branch: | ||
description: 'Pull Request branch' | ||
type: string | ||
required: true | ||
validate_merge: | ||
description: 'Validate merge' | ||
type: boolean | ||
required: false | ||
default: true | ||
|
||
jobs: | ||
link-pr-to-issue: | ||
runs-on: ubuntu-20.04 | ||
continue-on-error: true | ||
steps: | ||
- run: echo 'GitHub context' | ||
env: | ||
GITHUB_CONTEXT: ${{ toJson(github) }} | ||
|
||
- name: Link PR to Issue | ||
shell: bash | ||
run: | | ||
pr_json=$(\ | ||
gh api \ | ||
--method GET \ | ||
repos/${{ github.repository }}/pulls/${{ inputs.pr_number }} \ | ||
| jq -c -r \ | ||
) | ||
pr_merged=$(echo "${pr_json}" | jq '.merged') | ||
[[ "${{ inputs.validate_merge }}" == 'true' && "${pr_merged}" != 'true' ]] && echo "PR [${{ inputs.pr_number }}] is not merged" && exit 1 | ||
echo "pr_merged=${pr_merged}" | ||
pr_branch=${{ inputs.pr_branch }} | ||
[[ ${pr_branch} =~ ^[0-9]+- ]] && issue_number=${pr_branch%%-*} || issue_number=${pr_branch} | ||
[[ -z "${issue_number}" ]] && echo 'Issue number could not be resolved' && exit 2 | ||
echo "issue_number=${issue_number}" | ||
issue_json=$(\ | ||
gh api \ | ||
--method GET \ | ||
repos/${{ github.repository }}/issues/${issue_number} \ | ||
) | ||
fetched_issue_number=$(echo "${issue_json}" | jq -r '.number') | ||
[[ -z "${fetched_issue_number}" ]] && echo "Issue [${issue_number}] could not be resolved" && exit 3 | ||
pr_body=$(echo "${pr_json}" | jq -r '.body') | ||
pr_body="${pr_body}"$'\n\n'"This PR fixes: #${issue_number}" | ||
echo "pr_body=${pr_body}" | ||
gh api \ | ||
--method PATCH \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
/repos/${{ github.repository }}/pulls/${{ inputs.pr_number }} \ | ||
-f "body=\"${pr_body}\"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Post PR Merge | ||
on: | ||
pull_request: | ||
branches: | ||
- 28716-test | ||
types: | ||
- closed | ||
|
||
jobs: | ||
post-pr-merge: | ||
name: Post Merge PR | ||
if: github.event.pull_request.merged == true | ||
uses: ./.github/workflows/link-pr-to-issue.yml | ||
with: | ||
pr_number: ${{ github.event.pull_request.number }} | ||
pr_branch: ${{ github.event.pull_request.head.ref }} | ||
validate_merge: false |