You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by da...@apache.org on 2022/06/28 15:21:24 UTC
[beam] branch master updated: Update issue bot to javascript and add label management (#22067)
This is an automated email from the ASF dual-hosted git repository.
damccorm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/master by this push:
new f5da4a91763 Update issue bot to javascript and add label management (#22067)
f5da4a91763 is described below
commit f5da4a9176316930db5095a46154e90f032bd5fa
Author: Danny McCormick <da...@google.com>
AuthorDate: Tue Jun 28 11:21:17 2022 -0400
Update issue bot to javascript and add label management (#22067)
* Update issue bot to javascript and add label management
* Templates docs and script updates
* Update .github/workflows/self-assign.yml
Co-authored-by: Yi Hu <ya...@google.com>
* Update .github/workflows/self-assign.yml
Co-authored-by: Yi Hu <ya...@google.com>
* Extraneous line
* state_reason fix
* Fix close reason
* Close issue else
Co-authored-by: Yi Hu <ya...@google.com>
---
.github/ACTIONS.md | 3 +
.github/ISSUE_TEMPLATE/bug.yml | 2 +
.github/ISSUE_TEMPLATE/feature.yml | 2 +
.github/ISSUE_TEMPLATE/task.yml | 2 +
.github/workflows/self-assign.yml | 141 ++++++++++++++++++++++++++++++-------
5 files changed, 124 insertions(+), 26 deletions(-)
diff --git a/.github/ACTIONS.md b/.github/ACTIONS.md
index 0b664022d3f..7aecf895871 100644
--- a/.github/ACTIONS.md
+++ b/.github/ACTIONS.md
@@ -29,3 +29,6 @@ Phrases for self-assign and close the issue:
| `.take-issue` | Self-assign the issue |
| `.close-issue` | Close the issue as completed |
| `.close-issue not_planned` | Close the issue as not-planned |
+| `.add-labels` | Add comma separated labels to the issue (e.g. `add-labels l1, 'l2 with spaces'`) |
+| `.remove-labels` | Remove comma separated labels to the issue (e.g. `remove-labels l1, 'l2 with spaces'`) |
+| `.set-labels` | Sets comma separated labels to the issue and removes any other labels (e.g. `set-labels l1, 'l2 with spaces'`) |
diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml
index 2bdbcca83d1..4291dee914d 100644
--- a/.github/ISSUE_TEMPLATE/bug.yml
+++ b/.github/ISSUE_TEMPLATE/bug.yml
@@ -26,6 +26,8 @@ body:
attributes:
value: |
Thanks for taking the time to fill out this bug report! Once you've created an issue, you can self-assign by commenting `.take-issue` and you can close by commenting `.close-issue`.
+ You can also add/remove labels by commenting `.add-labels label1,label2,'label 3 with spaces'` or `.remove-labels label1,label2,'label 3 with spaces'`,
+ or with `.set-labels label1,label2,'label 3 with spaces'` (which removes any labels not in that set).
- type: textarea
id: what-happened
attributes:
diff --git a/.github/ISSUE_TEMPLATE/feature.yml b/.github/ISSUE_TEMPLATE/feature.yml
index 7ccb86ff8eb..40de93f3ca5 100644
--- a/.github/ISSUE_TEMPLATE/feature.yml
+++ b/.github/ISSUE_TEMPLATE/feature.yml
@@ -26,6 +26,8 @@ body:
attributes:
value: |
Thanks for taking the time to fill out this feature request! Once you've created an issue, you can self-assign by commenting `.take-issue` and you can close by commenting `.close-issue`.
+ You can also add/remove labels by commenting `.add-labels label1,label2,'label 3 with spaces'` or `.remove-labels label1,label2,'label 3 with spaces'`,
+ or with `.set-labels label1,label2,'label 3 with spaces'` (which removes any labels not in that set).
- type: textarea
id: what-happened
attributes:
diff --git a/.github/ISSUE_TEMPLATE/task.yml b/.github/ISSUE_TEMPLATE/task.yml
index b430e7cd8bf..98252938708 100644
--- a/.github/ISSUE_TEMPLATE/task.yml
+++ b/.github/ISSUE_TEMPLATE/task.yml
@@ -26,6 +26,8 @@ body:
attributes:
value: |
Thanks for taking the time to fill out this task! Once you've created an issue, you can self-assign by commenting `.take-issue` and you can close by commenting `.close-issue`.
+ You can also add/remove labels by commenting `.add-labels label1,label2,'label 3 with spaces'` or `.remove-labels label1,label2,'label 3 with spaces'`,
+ or with `.set-labels label1,label2,'label 3 with spaces'` (which removes any labels not in that set).
- type: textarea
id: what-happened
attributes:
diff --git a/.github/workflows/self-assign.yml b/.github/workflows/self-assign.yml
index f939237c974..45e53def972 100644
--- a/.github/workflows/self-assign.yml
+++ b/.github/workflows/self-assign.yml
@@ -23,29 +23,118 @@ jobs:
if: ${{ !github.event.issue.pull_request }}
runs-on: ubuntu-latest
steps:
- - run: |
- BODY="$(jq '.comment.body' $GITHUB_EVENT_PATH)"
- ISSUE_NUMBER="$(jq '.issue.number' $GITHUB_EVENT_PATH)"
- LOGIN="$(jq '.comment.user.login' $GITHUB_EVENT_PATH | tr -d \")"
- REPO="$(jq '.repository.full_name' $GITHUB_EVENT_PATH | tr -d \")"
- ISSUE_JSON="$(jq '.issue' $GITHUB_EVENT_PATH)"
- if [[ $BODY == *"$INPUT_TAKE"* && $BODY != *"\`$INPUT_TAKE\`"* ]]; then
- echo "Assigning issue $ISSUE_NUMBER to $LOGIN"
- echo "Using the link: https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER/assignees"
- curl -H "Authorization: token $GITHUB_TOKEN" -d '{"assignees":["'"$LOGIN"'"]}' https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER/assignees
- curl -X DELETE -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER/labels/awaiting%20triage
- fi
- if [[ $BODY == *"$INPUT_CLOSE"* && $BODY != *"\`$INPUT_CLOSE\`"* ]]; then
- ISSUE_CLOSE_CONFIG='"state":"closed"'
- if [[ $BODY == *"not_planned"* ]]; then
- ISSUE_CLOSE_CONFIG='"state":"closed","state_reason":"not_planned"'
- fi
- echo "Closing issue $ISSUE_NUMBER as {$ISSUE_CLOSE_CONFIG}"
- echo "Using the link: https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER"
- curl -X PATCH -H "Authorization: token $GITHUB_TOKEN" -d "{$ISSUE_CLOSE_CONFIG}" https://api.github.com/repos/$REPO/issues/$ISSUE_NUMBER
- fi
- shell: bash
- env:
- INPUT_TAKE: ".take-issue"
- INPUT_CLOSE: ".close-issue"
- GITHUB_TOKEN: ${{ github.token }}
\ No newline at end of file
+ - uses: actions/github-script@v6
+ with:
+ script: |
+ const body = context.payload.comment.body.split(' ');
+ for (let i = 0; i < body.length; i++) {
+ const bodyString = body[i].toLowerCase();
+ if (bodyString == '.take-issue') {
+ console.log(`Assigining issue to ${context.payload.comment.user.login}`);
+ github.rest.issues.addAssignees({
+ issue_number: context.issue.number,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ assignees: [context.payload.comment.user.login]
+ });
+ github.rest.issues.removeLabel({
+ issue_number: context.issue.number,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ name: 'awaiting triage'
+ });
+ } else if (bodyString == '.close-issue') {
+ console.log('Closing issue');
+ if (i + 1 < body.length && body[i+1].toLowerCase() == 'not_planned') {
+ github.rest.issues.update({
+ issue_number: context.issue.number,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ state: 'closed',
+ state_reason: 'not_planned'
+ });
+ } else {
+ github.rest.issues.update({
+ issue_number: context.issue.number,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ state: 'closed'
+ });
+ }
+ } else if (bodyString == '.set-labels' || bodyString == '.add-labels' || bodyString == '.remove-labels') {
+ console.log('Updating labels');
+ if (i + 1 >= body.length) {
+ console.log(`Invalid input ${body}`);
+ github.rest.issues.createComment({
+ issue_number: context.issue.number,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ body: '.<update>-labels command detected, but no labels provided.'
+ });
+ return;
+ } else {
+ const labelsInRepo = (await github.paginate(github.rest.issues.listLabelsForRepo, {
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ })).map(l => l.name);
+ let j = i+1;
+ let partsToConsider = body[j];
+ while ((partsToConsider.match(/'/g) || []).length % 2 == 1) {
+ j++;
+ if (j >= body.length) {
+ console.log(`Invalid input ${body}`);
+ github.rest.issues.createComment({
+ issue_number: context.issue.number,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ body: '.<update>-labels command detected with mismatched set of \' quotes'
+ });
+ return;
+ }
+ partsToConsider += ' ' + body[j];
+ }
+ const labelsToActionOn = partsToConsider.split(',').map(l => l.replaceAll('\'', ''));
+ for (label of labelsToActionOn) {
+ if (labelsInRepo.indexOf(label) < 0) {
+ console.log(`Invalid label ${body}`);
+ github.rest.issues.createComment({
+ issue_number: context.issue.number,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ body: `Label ${label} cannot be managed because it does not exist in the repo. Please check your spelling.`
+ });
+ return;
+ }
+ }
+
+ if (bodyString == '.set-labels') {
+ console.log(`Setting labels to ${labelsToActionOn}`);
+ github.rest.issues.setLabels({
+ issue_number: context.issue.number,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ labels: labelsToActionOn
+ });
+ } else if (bodyString == '.add-labels') {
+ console.log(`Adding labels ${labelsToActionOn}`);
+ github.rest.issues.addLabels({
+ issue_number: context.issue.number,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ labels: labelsToActionOn
+ });
+ } else if (bodyString == '.remove-labels') {
+ console.log(`Removing labels ${labelsToActionOn}`);
+ // There's no true removeLabels command, we'll remove them one by one
+ for (const label of labelsToActionOn) {
+ github.rest.issues.removeLabel({
+ issue_number: context.issue.number,
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ name: label
+ });
+ }
+ }
+ }
+ }
+ }