File tree Expand file tree Collapse file tree 2 files changed +73
-0
lines changed Expand file tree Collapse file tree 2 files changed +73
-0
lines changed Original file line number Diff line number Diff line change 1+ const {
2+ PR_ACTION ,
3+ PR_AUTHOR ,
4+ PR_BODY ,
5+ PR_NUMBER ,
6+ IGNORE_AUTHORS ,
7+ LABEL_BLOCK ,
8+ LABEL_BLOCK_REASON
9+ } = require ( "./constants" )
10+
11+ module . exports = async ( { github, context, core} ) => {
12+ if ( IGNORE_AUTHORS . includes ( PR_AUTHOR ) ) {
13+ return core . notice ( "Author in IGNORE_AUTHORS list; skipping..." )
14+ }
15+
16+ if ( PR_ACTION != "opened" ) {
17+ return core . notice ( "Only newly open PRs are labelled to avoid spam; skipping" )
18+ }
19+
20+ const RELATED_ISSUE_REGEX = / I s s u e n u m b e r : [ ^ \d \r \n ] + (?< issue > \d + ) / ;
21+ const isMatch = RELATED_ISSUE_REGEX . exec ( PR_BODY ) ;
22+ if ( isMatch == null ) {
23+ core . info ( `No related issue found, maybe the author didn't use the template but there is one.` )
24+
25+ let msg = "No related issues found. Please ensure there is an open issue related to this change to avoid significant delays or closure." ;
26+ await github . rest . issues . createComment ( {
27+ owner : context . repo . owner ,
28+ repo : context . repo . repo ,
29+ body : msg ,
30+ issue_number : PR_NUMBER ,
31+ } ) ;
32+
33+ return await github . rest . issues . addLabels ( {
34+ issue_number : PR_NUMBER ,
35+ owner : context . repo . owner ,
36+ repo : context . repo . repo ,
37+ labels : [ LABEL_BLOCK , LABEL_BLOCK_REASON ]
38+ } )
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ name : On new PR
2+
3+ on :
4+ workflow_run :
5+ workflows : ["Record PR details"]
6+ types :
7+ - completed
8+
9+ jobs :
10+ get_pr_details :
11+ if : ${{ github.event.workflow_run.conclusion == 'success' }}
12+ uses : ./.github/workflows/reusable_export_pr_details.yml
13+ with :
14+ record_pr_workflow_id : ${{ github.event.workflow_run.id }}
15+ secrets :
16+ token : ${{ secrets.GITHUB_TOKEN }}
17+ check_related_issue :
18+ needs : get_pr_details
19+ runs-on : ubuntu-latest
20+ steps :
21+ - uses : actions/checkout@v3
22+ - name : " Ensure related issue is present"
23+ uses : actions/github-script@v6
24+ env :
25+ PR_BODY : ${{ needs.get_pr_details.outputs.prBody }}
26+ PR_NUMBER : ${{ needs.get_pr_details.outputs.prNumber }}
27+ PR_ACTION : ${{ needs.get_pr_details.outputs.prAction }}
28+ PR_AUTHOR : ${{ needs.get_pr_details.outputs.prAuthor }}
29+ with :
30+ github-token : ${{ secrets.GITHUB_TOKEN }}
31+ script : |
32+ const script = require('.github/scripts/label_missing_related_issue.js')
33+ await script({github, context, core})
You can’t perform that action at this time.
0 commit comments