Skip to content

Commit 3dd0995

Browse files
authored
Fix path to scripts by checking out self (#8)
* Fix path to scripts by checking out self * Check for teams or individuals
1 parent 4bef67a commit 3dd0995

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

.github/scripts/pr-draft-nudge.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ module.exports = async ({ github, context, core }) => {
1313
}
1414

1515
// We only want to comment on PRs that are opened ready for review with reviewers.
16-
if (
17-
context.payload.action !== "opened" ||
18-
pr.draft ||
19-
!pr.requested_reviewers ||
20-
pr.requested_reviewers.length === 0
21-
) {
22-
core.info(
23-
'PR is a draft, has no reviewers, or this is not an "opened" event. Skipping.'
24-
);
16+
const hasIndividualReviewers = pr.requested_reviewers && pr.requested_reviewers.length > 0;
17+
const hasTeamReviewers = pr.requested_teams && pr.requested_teams.length > 0;
18+
19+
// Debug reviewer information
20+
core.debug(`PR requested_reviewers: ${JSON.stringify(pr.requested_reviewers || [])}`);
21+
core.debug(`PR requested_teams: ${JSON.stringify(pr.requested_teams || [])}`);
22+
core.debug(`Has individual reviewers: ${hasIndividualReviewers}`);
23+
core.debug(`Has team reviewers: ${hasTeamReviewers}`);
24+
core.debug(`PR action: ${context.payload.action}`);
25+
core.debug(`PR is draft: ${pr.draft}`);
26+
27+
if (context.payload.action !== "opened" || pr.draft || (!hasIndividualReviewers && !hasTeamReviewers)) {
28+
core.info('PR is a draft, has no reviewers (individual or team), or this is not an "opened" event. Skipping.');
2529
return;
2630
}
2731

@@ -36,9 +40,7 @@ module.exports = async ({ github, context, core }) => {
3640
issue_number: pr.number,
3741
});
3842

39-
const existingComment = comments.find((comment) =>
40-
comment.body.includes(commentIdentifier)
41-
);
43+
const existingComment = comments.find((comment) => comment.body.includes(commentIdentifier));
4244

4345
if (existingComment) {
4446
core.info("A PR draft nudge comment already exists on this PR.");

.github/workflows/do-not-merge-block.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ on:
1717

1818
permissions: {}
1919

20+
env:
21+
PATH_TO_REPO_SELF: gha-org-workflows
22+
2023
jobs:
2124
do-not-merge-block:
2225
name: Do Not Merge Block
@@ -27,13 +30,19 @@ jobs:
2730
# Skip on merge group events
2831
if: ${{ github.event_name == 'pull_request' }}
2932
steps:
30-
- uses: actions/checkout@v4
33+
- name: Checkout org workflows
34+
uses: actions/checkout@v4
35+
with:
36+
repository: smartcontractkit/${{ env.PATH_TO_REPO_SELF}}
37+
path: ${{ env.PATH_TO_REPO_SELF}}
38+
persist-credentials: false
3139

3240
- name: Fail if blocking label present
3341
uses: actions/github-script@v7
3442
env:
3543
FAIL_LABELS: ${{ vars.DO_NOT_MERGE_LABELS || 'do-not-merge' }}
3644
with:
3745
script: |
38-
const script = require('./.github/scripts/do-not-merge-block.js');
46+
const pathToRepoSelf = process.env.PATH_TO_REPO_SELF || 'gha-org-workflows';
47+
const script = require(`./${pathToRepoSelf}/.github/scripts/do-not-merge-block.js`);
3948
await script({ context, core });

.github/workflows/pr-draft-nudge.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ on:
1515

1616
permissions: {}
1717

18+
env:
19+
PATH_TO_REPO_SELF: gha-org-workflows
20+
1821
jobs:
1922
pr-draft-nudge:
2023
name: PR Draft Nudge
@@ -24,13 +27,19 @@ jobs:
2427
contents: read
2528
pull-requests: write
2629
steps:
27-
- uses: actions/checkout@v4
30+
- name: Checkout org workflows
31+
uses: actions/checkout@v4
32+
with:
33+
repository: smartcontractkit/${{ env.PATH_TO_REPO_SELF}}
34+
path: ${{ env.PATH_TO_REPO_SELF}}
35+
persist-credentials: false
2836

2937
- name: Run
3038
uses: actions/github-script@v7
3139
env:
3240
PR_DRAFT_NUDGE_COMMENT_DISABLE: ${{ vars.PR_DRAFT_NUDGE_COMMENT_DISABLE || 'false' }}
3341
with:
3442
script: |
35-
const script = require('./.github/scripts/pr-draft-nudge.js');
43+
const pathToRepoSelf = process.env.PATH_TO_REPO_SELF || 'gha-org-workflows';
44+
const script = require(`./${pathToRepoSelf}/.github/scripts/pr-draft-nudge.js`);
3645
await script({ github, context, core });

0 commit comments

Comments
 (0)