You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/06/27 20:54:24 UTC

[GitHub] [beam] damccorm commented on a diff in pull request #22067: Update issue bot to javascript and add label management

damccorm commented on code in PR #22067:
URL: https://github.com/apache/beam/pull/22067#discussion_r907789281


##########
.github/workflows/self-assign.yml:
##########
@@ -23,29 +23,102 @@ 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]
+              });
+            } else if (bodyString == '.close-issue') {
+              console.log('Closing issue');

Review Comment:
   Oh wow - this does work. I was expecting there to be some validation on the octokit end preventing this since its not documented, but it doesn't look like there is



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org