Skip to content

Commit 4f8bbff

Browse files
authored
[chore] Add workflow to check for a linked issue on non-member PRs (#15474)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Adds CI check for PRs from non-members to have a linked issue. This is a pre-requisite for us to explore implementing other workflows for flagging duplicate work or work on issues that are not ready to be worked on. This tries to start small by excluding PRs marked as `[chore]` and smalls PRs. We can make it more strict over time. <!--Authorship attestation. See AGENTS.md for details. AI agents must not check this box on behalf of the user; the human author must check it themselves before the PR is ready for review.--> #### Authorship - [x] I, a human, wrote this pull request description myself. <!--Please delete paragraphs that you did not use before submitting.-->
1 parent 21ef5d9 commit 4f8bbff

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: 'Check PR links to an issue'
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- edited
7+
- reopened
8+
- ready_for_review
9+
- synchronize
10+
branches:
11+
- main
12+
13+
permissions: read-all
14+
15+
jobs:
16+
check-pr-issue-link:
17+
runs-on: ubuntu-latest
18+
if: >-
19+
${{ github.repository_owner == 'open-telemetry'
20+
&& github.event.pull_request.user.type != 'Bot'
21+
&& github.event.pull_request.author_association != 'MEMBER'
22+
&& !contains(github.event.pull_request.title, '[chore]') }}
23+
steps:
24+
- name: Check for linked issue
25+
env:
26+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
REPO: ${{ github.repository }}
28+
PR: ${{ github.event.pull_request.number }}
29+
ADDITIONS: ${{ github.event.pull_request.additions }}
30+
DELETIONS: ${{ github.event.pull_request.deletions }}
31+
run: |
32+
# Skip trivial PRs, e.g. typo fixes.
33+
if (( ${ADDITIONS:-0} + ${DELETIONS:-0} <= 20 )); then
34+
echo "PR changes $(( ADDITIONS + DELETIONS )) line(s), trivial, skipping check."
35+
exit 0
36+
fi
37+
COUNT=$(gh pr view "$PR" --repo "$REPO" --json closingIssuesReferences --jq '.closingIssuesReferences | length')
38+
if (( COUNT > 0 )); then
39+
echo "Found a linked issue."
40+
exit 0
41+
fi
42+
echo '::error::Pull requests from non-members must have a linked issue. Link one from the description, for example "Fixes #1234".'
43+
exit 1

0 commit comments

Comments
 (0)