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


##########
.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'
+                });
+              }
+              
+              github.rest.issues.update({

Review Comment:
   Good catch - updated!



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to