Skip to content
Merged
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
83 changes: 35 additions & 48 deletions .github/workflows/verify-pull-request.yml
Original file line number Diff line number Diff line change
@@ -1,77 +1,64 @@
name: Verify Pull Request meets Requirements
on:
pull_request_target: # need write permission
pull_request: # need write permission
branches:
- main
types: [opened, edited]
jobs:
mirror-linked-issue:
runs-on: ubuntu-latest # find-linked-issue GitHub Action is only supported on Linux
permissions:
contents: read
issues: read
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: add-issue-to-body
with:
sparse-checkout: |
.github
token: ${{ secrets.GITHUB_TOKEN }}
- id: add-issue-to-body
name: Link issue in body
run: | # get the title, take the first word which should be the issue number, and add this to the body
title=$(gh pr view ${{ github.event.pull_request.number }} --json title --jq '.title')
issue_number=$title[(ws: :)1]
body=$(gh pr view ${{ github.event.pull_request.number }} --json body --jq '.body')
new_body="Closes #$issue_number" >> $body
gh pr edit -b $new_body
title="${{ github.event.pull_request.title }}"
issue_number=${title%% *}
new_body="Closes #$issue_number"$'\n\n'"${{ github.event.pull_request.body }}"
gh pr edit ${{ github.event.pull_request.number }} --body "$new_body"
echo "Edited the body to include the issue number $issue_number"
echo "issue_number=$issue_number" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ github.token }}
- name: find-linked-issues
uses: Ismoh-Games/find-linked-issues@v1.0.6
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- id: copy-issue-labels
name: Copy Issue Labels
uses: michalvankodev/copy-issue-labels@v1.2.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
pull-request-number: ${{ github.event.pull_request.number }}
pull-request-body: ${{ github.event.pull_request.body }}
copy-issues-labels: true
include-closed-issues: false

# Use the output from the `find-linked-issues` step
- name: Use the output
run: |
echo "is-pull-request-linked-to-issues: ${{ steps.find-linked-issues.outputs.is-pull-request-linked-to-issues }}"
echo "linked-issues: ${{ steps.find-linked-issues.outputs.linked-issues }}"
echo "pull-request-labels: ${{ steps.find-linked-issues.outputs.pull-request-labels }}"
repo-token: ${{ secrets.GITHUB_TOKEN }}
from-title: true

- name: Get issue assignee
id: get-issue-assignee
run: |
first_issue=gh issue view ${{ steps.find-linked-issues.outputs.linked-issues[1] }} --json assignees --jq '
.assignees'
echo "first_assignee=$(fromJson(first_issue)[1].login" >> "$GITHUB_OUTPUT"

first_assignee=$(gh issue view "${{ steps.add-issue-to-body.outputs.issue_number }}" \
--json assignees \
--jq '.assignees[0].login')
echo "first_assignee=$first_assignee" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set PR assignee
run: |
gh pr edit ${{ github.event.pull_request.number }} \
--add-assignee ${{ steps.get-issue-assignee.outputs.first_assignee }}
run: gh pr edit ${{ github.event.pull_request.number }} --add-assignee "${{ env.ISSUE_ASSIGNEE }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE_ASSIGNEE: ${{ steps.get-issue-assignee.outputs.first_assignee }}

- name: Set PR reviewer to Declan
if: ${{ steps.get-issue-assignee.outputs.first_assignee == 'varunsingh87' }}
run: |
gh pr edit ${{ github.event.pull_request.number }} \
--add-reviewer "Datoneguy246"
run: gh pr edit ${{ github.event.pull_request.number }} --add-reviewer "Datoneguy246"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set PR reviewer to Varun
if: ${{ steps.get-issue-assignee.outputs.first_assignee == 'Datoneguy246' }}
run: |
gh pr edit ${{ github.event.pull_request.number }} \
--add-reviewer "varunsingh87"

- name: Announce Success
if: ${{ steps.find-linked-issues.outputs.is-pull-request-linked-to-issues == 'True' }}
run: |
echo "Pull request is linked to issues"

- name: Announce Failure
if: ${{ steps.find-linked-issues.outputs.is-pull-request-linked-to-issues == 'False' }}
run: |
echo "::warning Pull request must have a linked issue before merging"
exit 1
run: gh pr edit ${{ github.event.pull_request.number }} --add-reviewer "varunsingh87"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading