diff --git a/.github/scripts/pr-draft-nudge.js b/.github/scripts/pr-draft-nudge.js index 7b5c0c8..786ef5d 100644 --- a/.github/scripts/pr-draft-nudge.js +++ b/.github/scripts/pr-draft-nudge.js @@ -13,15 +13,19 @@ module.exports = async ({ github, context, core }) => { } // We only want to comment on PRs that are opened ready for review with reviewers. - if ( - context.payload.action !== "opened" || - pr.draft || - !pr.requested_reviewers || - pr.requested_reviewers.length === 0 - ) { - core.info( - 'PR is a draft, has no reviewers, or this is not an "opened" event. Skipping.' - ); + const hasIndividualReviewers = pr.requested_reviewers && pr.requested_reviewers.length > 0; + const hasTeamReviewers = pr.requested_teams && pr.requested_teams.length > 0; + + // Debug reviewer information + core.debug(`PR requested_reviewers: ${JSON.stringify(pr.requested_reviewers || [])}`); + core.debug(`PR requested_teams: ${JSON.stringify(pr.requested_teams || [])}`); + core.debug(`Has individual reviewers: ${hasIndividualReviewers}`); + core.debug(`Has team reviewers: ${hasTeamReviewers}`); + core.debug(`PR action: ${context.payload.action}`); + core.debug(`PR is draft: ${pr.draft}`); + + if (context.payload.action !== "opened" || pr.draft || (!hasIndividualReviewers && !hasTeamReviewers)) { + core.info('PR is a draft, has no reviewers (individual or team), or this is not an "opened" event. Skipping.'); return; } @@ -36,9 +40,7 @@ module.exports = async ({ github, context, core }) => { issue_number: pr.number, }); - const existingComment = comments.find((comment) => - comment.body.includes(commentIdentifier) - ); + const existingComment = comments.find((comment) => comment.body.includes(commentIdentifier)); if (existingComment) { core.info("A PR draft nudge comment already exists on this PR."); diff --git a/.github/workflows/do-not-merge-block.yml b/.github/workflows/do-not-merge-block.yml index 4f64056..40a768c 100644 --- a/.github/workflows/do-not-merge-block.yml +++ b/.github/workflows/do-not-merge-block.yml @@ -17,6 +17,9 @@ on: permissions: {} +env: + PATH_TO_REPO_SELF: gha-org-workflows + jobs: do-not-merge-block: name: Do Not Merge Block @@ -27,7 +30,12 @@ jobs: # Skip on merge group events if: ${{ github.event_name == 'pull_request' }} steps: - - uses: actions/checkout@v4 + - name: Checkout org workflows + uses: actions/checkout@v4 + with: + repository: smartcontractkit/${{ env.PATH_TO_REPO_SELF}} + path: ${{ env.PATH_TO_REPO_SELF}} + persist-credentials: false - name: Fail if blocking label present uses: actions/github-script@v7 @@ -35,5 +43,6 @@ jobs: FAIL_LABELS: ${{ vars.DO_NOT_MERGE_LABELS || 'do-not-merge' }} with: script: | - const script = require('./.github/scripts/do-not-merge-block.js'); + const pathToRepoSelf = process.env.PATH_TO_REPO_SELF || 'gha-org-workflows'; + const script = require(`./${pathToRepoSelf}/.github/scripts/do-not-merge-block.js`); await script({ context, core }); diff --git a/.github/workflows/pr-draft-nudge.yml b/.github/workflows/pr-draft-nudge.yml index a6061c7..b41a2d1 100644 --- a/.github/workflows/pr-draft-nudge.yml +++ b/.github/workflows/pr-draft-nudge.yml @@ -15,6 +15,9 @@ on: permissions: {} +env: + PATH_TO_REPO_SELF: gha-org-workflows + jobs: pr-draft-nudge: name: PR Draft Nudge @@ -24,7 +27,12 @@ jobs: contents: read pull-requests: write steps: - - uses: actions/checkout@v4 + - name: Checkout org workflows + uses: actions/checkout@v4 + with: + repository: smartcontractkit/${{ env.PATH_TO_REPO_SELF}} + path: ${{ env.PATH_TO_REPO_SELF}} + persist-credentials: false - name: Run uses: actions/github-script@v7 @@ -32,5 +40,6 @@ jobs: PR_DRAFT_NUDGE_COMMENT_DISABLE: ${{ vars.PR_DRAFT_NUDGE_COMMENT_DISABLE || 'false' }} with: script: | - const script = require('./.github/scripts/pr-draft-nudge.js'); + const pathToRepoSelf = process.env.PATH_TO_REPO_SELF || 'gha-org-workflows'; + const script = require(`./${pathToRepoSelf}/.github/scripts/pr-draft-nudge.js`); await script({ github, context, core });