Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github bot update - allow Dapr maintainers to apply labels via bot comments #4417

Open
wants to merge 5 commits into
base: v1.14
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/dapr-bot-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
labels:
- roles:
- maintainers
- contributors
commands:
"/waiting-on-pr": "waiting-on-code-pr"
"/do-not-merge": "do-not-merge"
types:
- pr
- roles:
- maintainers
commands:
"/missing-docs": "feature-in-release-no-docs",
"/requirement": "release-requirement"
types:
- issue
- pr
56 changes: 55 additions & 1 deletion .github/workflows/dapr-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,61 @@ 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.checkIfUserIsMaintainer.outputs.isTeamMember == 'true' }}
with:
github-actor: ${{ github.actor }}
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}}
Expand Down
Loading
Loading