Skip to content

Commit 3152552

Browse files
authored
Merge pull request #284 from heitorlessa/chore/dummy
2 parents 0bdac56 + 879fcbe commit 3152552

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 = /Issue number:[^\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+
}

.github/workflows/label_pr_on_title.yml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ jobs:
1414
uses: ./.github/workflows/reusable_export_pr_details.yml
1515
with:
1616
record_pr_workflow_id: ${{ github.event.workflow_run.id }}
17+
workflow_origin: ${{ github.event.repository.full_name }}
1718
secrets:
1819
token: ${{ secrets.GITHUB_TOKEN }}
1920
label_pr:

.github/workflows/on_merged_pr.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
uses: ./.github/workflows/reusable_export_pr_details.yml
1313
with:
1414
record_pr_workflow_id: ${{ github.event.workflow_run.id }}
15+
workflow_origin: ${{ github.event.repository.full_name }}
1516
secrets:
1617
token: ${{ secrets.GITHUB_TOKEN }}
1718
release_label_on_merge:

.github/workflows/on_opened_pr.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ jobs:
1010
get_pr_details:
1111
if: ${{ github.event.workflow_run.conclusion == 'success' }}
1212
uses: ./.github/workflows/reusable_export_pr_details.yml
13+
env:
1314
with:
1415
record_pr_workflow_id: ${{ github.event.workflow_run.id }}
16+
workflow_origin: ${{ github.event.repository.full_name }}
1517
secrets:
1618
token: ${{ secrets.GITHUB_TOKEN }}
1719
check_related_issue:
@@ -20,7 +22,7 @@ jobs:
2022
steps:
2123
- uses: actions/checkout@v3
2224
- name: "Debug workflow_run event"
23-
run: echo ${{ toJSON(github.event) }}
25+
run: echo "${{ github }}"
2426
- name: "Ensure related issue is present"
2527
uses: actions/github-script@v6
2628
env:

.github/workflows/reusable_export_pr_details.yml

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ on:
66
record_pr_workflow_id:
77
required: true
88
type: number
9+
# this protects from anyone mimicking "Record PR details" dependency
10+
# regardless of our untrusted input validation
11+
workflow_origin:
12+
required: true
13+
type: string
914
secrets:
1015
token:
1116
required: true
@@ -32,6 +37,7 @@ on:
3237

3338
jobs:
3439
export_pr_details:
40+
if: inputs.workflow_origin == "bla/bla"
3541
runs-on: ubuntu-latest
3642
env:
3743
FILENAME: pr.txt

0 commit comments

Comments
 (0)