From 72058700d13df01ad575f56115a45c6a7587702b Mon Sep 17 00:00:00 2001 From: "Leona B. Campbell" <3880403+runleonarun@users.noreply.github.com> Date: Wed, 4 Oct 2023 10:20:14 -0700 Subject: [PATCH] Update label.yml (#4182) ## What are you changing in this pull request and why? - Added some logging to print so we know which step the script got to - Added `github` to get proper context - Moved permissions to the secret token. ## Checklist - [ ] Review the [Content style guide](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/content-style-guide.md) and [About versioning](https://github.com/dbt-labs/docs.getdbt.com/blob/current/contributing/single-sourcing-content.md#adding-a-new-version) so my content adheres to these guidelines. - [ ] Add a checklist item for anything that needs to happen before this PR is merged, such as "needs technical review" or "change base branch." Adding new pages (delete if not applicable): - [ ] Add page to `website/sidebars.js` - [ ] Provide a unique filename for the new page Removing or renaming existing pages (delete if not applicable): - [ ] Remove page from `website/sidebars.js` - [ ] Add an entry `website/static/_redirects` - [ ] [Ran link testing](https://github.com/dbt-labs/docs.getdbt.com#running-the-cypress-tests-locally) to update the links that point to the deleted page --- .github/workflows/label.yml | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index 4de2203647f..67a509f1c2f 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -2,22 +2,22 @@ name: Add/Remove Labels on: pull_request_target: - types: [ opened ] + types: [opened] jobs: add_new_contributor_label: if: github.event.action == 'opened' - permissions: - contents: read - pull-requests: write runs-on: ubuntu-latest steps: - - uses: actions/github-script@v6 - with: - script: | - const creator = context.payload.sender.login; - const opts = github.rest.issues.listForRepo.endpoint.merge({ - ...context.issue, + - name: Add new contributor label + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + async function run() { + const creator = github.context.payload.sender.login; + const opts = github.context.repo.issues.listForRepo.endpoint.merge({ + ...github.context.issue, creator, state: 'all', }); @@ -27,7 +27,7 @@ jobs: let isAlreadyContributor = false; for (const issue of issues) { - if (issue.number === context.issue.number) { + if (issue.number === github.context.issue.number) { continue; } if (issue.pull_request && issue.user.login === creator) { @@ -37,10 +37,16 @@ jobs: } if (!isAlreadyContributor) { + console.log('Adding label: new contributor'); await github.rest.issues.addLabels({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, + issue_number: github.context.issue.number, + owner: github.context.repo.owner, + repo: github.context.repo.repo, labels: ['new contributor'], }); + } else { + console.log('User is already a contributor, no label added.'); } + } + + run(); // Call the async function to execute the code