From 5d1c8580f1eccecbac3f6d94d1c7386c396edfbf Mon Sep 17 00:00:00 2001 From: sy-b <94835959+sy-b@users.noreply.github.com> Date: Sun, 3 Jul 2022 01:22:29 +0530 Subject: [PATCH 1/4] add commentComand add-label-duplicate --- .github/workflows/assignme.yml | 20 -------------- .github/workflows/commentCommands.yml | 38 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 20 deletions(-) delete mode 100644 .github/workflows/assignme.yml create mode 100644 .github/workflows/commentCommands.yml diff --git a/.github/workflows/assignme.yml b/.github/workflows/assignme.yml deleted file mode 100644 index 586033d..0000000 --- a/.github/workflows/assignme.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Assign issue/pull to the commenter - -on: - issue_comment: - types: created - -jobs: - assign: - runs-on: ubuntu-latest - if: | - github.event.comment.body == '/assignme' - steps: - - name: Assigning to commentor - run: | - curl \ - -X POST \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/assignees \ - -d '{"assignees":["${{ github.event.comment.user.login }}"]}' diff --git a/.github/workflows/commentCommands.yml b/.github/workflows/commentCommands.yml new file mode 100644 index 0000000..dd94e84 --- /dev/null +++ b/.github/workflows/commentCommands.yml @@ -0,0 +1,38 @@ +name: commentCommands + +on: + issue_comment: + types: created + +jobs: + + assign-commentor: + runs-on: ubuntu-latest + if: | + github.event.comment.body == '/assignme' + steps: + - name: Assigning to commenter + run: | + curl \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/assignees \ + -d '{"assignees":["${{ github.event.comment.user.login }}"]}' + + add-label-duplicate: + runs-on: ubuntu-latest + if: | + startsWith(github.event.comment.body, "/duplicate") == '/add' && ( + github.event.comment.author_association == 'OWNER' || + github.event.comment.author_association == 'COLLABORATOR' || + github.event.comment.author_association == 'CONTRIBUTOR' ) + steps: + - name: add-label-duplicate + run: | + curl \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/label \ + -d '{"labels":["duplicate"]}' From 8eeeae0bfd295231796001cc00edba98d8e0d041 Mon Sep 17 00:00:00 2001 From: sy-b <94835959+sy-b@users.noreply.github.com> Date: Sun, 3 Jul 2022 11:47:45 +0530 Subject: [PATCH 2/4] Execute if comment contains command startsWith() --> contains() Signed-off-by: sy-b <94835959+sy-b@users.noreply.github.com> --- .github/workflows/commentCommands.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/commentCommands.yml b/.github/workflows/commentCommands.yml index dd94e84..d835522 100644 --- a/.github/workflows/commentCommands.yml +++ b/.github/workflows/commentCommands.yml @@ -23,7 +23,7 @@ jobs: add-label-duplicate: runs-on: ubuntu-latest if: | - startsWith(github.event.comment.body, "/duplicate") == '/add' && ( + contains(github.event.comment.body, "/duplicate") == '/add' && ( github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'CONTRIBUTOR' ) From 630a271e9ddd126e94d381bba09505e9ff34c82b Mon Sep 17 00:00:00 2001 From: sy-b <94835959+sy-b@users.noreply.github.com> Date: Sun, 3 Jul 2022 13:06:29 +0530 Subject: [PATCH 3/4] fix wrong expression & url Signed-off-by: sy-b <94835959+sy-b@users.noreply.github.com> --- .github/workflows/commentCommands.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/commentCommands.yml b/.github/workflows/commentCommands.yml index d835522..89bf1c0 100644 --- a/.github/workflows/commentCommands.yml +++ b/.github/workflows/commentCommands.yml @@ -23,7 +23,7 @@ jobs: add-label-duplicate: runs-on: ubuntu-latest if: | - contains(github.event.comment.body, "/duplicate") == '/add' && ( + contains(github.event.comment.body, "/duplicate") && ( github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'CONTRIBUTOR' ) @@ -34,5 +34,5 @@ jobs: -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/label \ + https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/labels \ -d '{"labels":["duplicate"]}' From 00fd96e9ade585d91fa269246210d90b0bda6626 Mon Sep 17 00:00:00 2001 From: sy-b <94835959+sy-b@users.noreply.github.com> Date: Tue, 12 Jul 2022 18:07:19 +0530 Subject: [PATCH 4/4] Improve - assign-commenter Signed-off-by: sy-b <94835959+sy-b@users.noreply.github.com> --- .github/workflows/commentCommands.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/commentCommands.yml b/.github/workflows/commentCommands.yml index 89bf1c0..6344344 100644 --- a/.github/workflows/commentCommands.yml +++ b/.github/workflows/commentCommands.yml @@ -9,7 +9,8 @@ jobs: assign-commentor: runs-on: ubuntu-latest if: | - github.event.comment.body == '/assignme' + contains(github.event.comment.body, '/assignme') || + contains(github.event.comment.body, '/assign me') steps: - name: Assigning to commenter run: | @@ -23,10 +24,10 @@ jobs: add-label-duplicate: runs-on: ubuntu-latest if: | - contains(github.event.comment.body, "/duplicate") && ( + contains(github.event.comment.body, '/duplicate') && ( github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'COLLABORATOR' || - github.event.comment.author_association == 'CONTRIBUTOR' ) + github.event.comment.author_association != 'CONTRIBUTOR' ) steps: - name: add-label-duplicate run: |