From cd1815373c6014235998e39e7143cdc9244a28b6 Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Fri, 1 Nov 2024 20:41:56 -0500 Subject: [PATCH] Updated bot to include a team check and allow maintainers to apply certain key labels to PRs Signed-off-by: Whit Waldo --- .github/workflows/dapr-bot.yml | 55 +++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dapr-bot.yml b/.github/workflows/dapr-bot.yml index 3e8665eb2df..4addd553566 100644 --- a/.github/workflows/dapr-bot.yml +++ b/.github/workflows/dapr-bot.yml @@ -8,7 +8,60 @@ jobs: name: bot-processor runs-on: ubuntu-latest steps: - - name: Comment analyzer + - name: Check if user is part of any of the maintainers teams + id: checkIfUserIsMaintainer + uses: tspascoal/get-user-teams-membership@v3 + with: + username: ${{ github.actor }} + organization: ${{ github.repository_owner }} + team: 'maintainers-blog,maintainers-cli,maintainers-community,maintainers-components-contrib,maintainers-cpp-sdk,maintainers-dapr,maintainers-dapr-shared,maintainers-dart-sdk,maintainers-dashboard,maintainers-docs,maintainers-docs-zh,maintainers-dotnet-sdk,maintainers-go-sdk,maintainers-java-sdk,maintainers-js-sdk,maintainers-kit,Maintainers-kubernetes-operator,maintainers-php-sdk,maintainers-python-sdk,maintainers-quickstarts,maintainers-rust-sdk,maintainers-samples,maintainers-sig-api,maintainers-sig-sdk-spec,maintainers-test-infra,maintainers-workflows' + GITHUB_TOKEN: ${{secrets.DAPR_BOT_TOKEN}} + - name: Allow maintainer actions from comments + uses: actions/github-script@v1 + if: ${{ steps.checkUserMember.outputs.isTeamMember == 'true' }} + with: + github-token: ${{secrets.DAPR_BOT_TOKEN}} + script: | + // Returns a boolean based on whether the specified label already exists on the issue/PR + async function labelExists(labelName) { + const issueLabels = await github.issues.listLabelsOnIssue({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + return issueLabels.data.some(label => label.name == labelName); + } + + // Adds the indicated label to the issue/PR if it doesn't already exist + async function addLabel(labelName) { + if (!(await labelExists(labelName))) { + await github.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + labels: [labelName] + }); + } + } + + // Maps the comments to their associated labels + const labelsMap = { + "/do-not-merge": "do-not-merge", + "/waiting-on-pr": "waiting-on-code-pr", + "/missing-docs": "feature-in-release-no-docs", + "/required": "release-requirement" + }; + + // If coming from a pull request, evaluate the comment against the mapping and if a match, apply the indicated label + const commentBody = context.payload.comment.body; + if (!!context.payload.pull_request && commentBody) { + for (const [key, value] of Object.entries(labelsMap)) { + if (commentBody.indexOf(key) == 0) { + await addLabel(value); + } + } + } + - name: Allow assignments from everyone in comments uses: actions/github-script@v1 with: github-token: ${{secrets.DAPR_BOT_TOKEN}}