From 2f8e279909a3fb7418db3d5aa20537bfd6318c0c Mon Sep 17 00:00:00 2001 From: Disha Modi Date: Wed, 27 Sep 2023 22:42:41 +0530 Subject: [PATCH] Added self assign issue workflow --- .github/workflows/issue_open_greet.yml | 2 +- .github/workflows/self_assign_issue.yml | 75 +++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/self_assign_issue.yml diff --git a/.github/workflows/issue_open_greet.yml b/.github/workflows/issue_open_greet.yml index 479ada3..8628481 100644 --- a/.github/workflows/issue_open_greet.yml +++ b/.github/workflows/issue_open_greet.yml @@ -16,7 +16,7 @@ jobs: script: | const { owner, repo, number } = context.issue; const commentauthor = context.payload.issue.user.login; - const commentBody = `Greetings @${commentauthor}๐ŸŽ€ ! , We are excited to have you dive into another issue with us!๐Ÿš€\nYour involvement in our project has been invaluable, and we're confident that your skills and insights will help us conquer this challenge๐Ÿ˜‡. This issue represents an exciting opportunity for us to improve and enhance our project, and we are thrilled to have you on board.\n We request you to follow [CONTRIBUTING GUIDELINES](../blob/master/CONTRIBUTING.md).\nLooking for your PR soon! \n In case of any issues, you can contact us on [Discord](https://discord.gg/mv4NTzN).โฃ๏ธ`; + const commentBody = `Greetings @${commentauthor}๐ŸŽ€ ! , We are excited to have you dive into another issue with us!๐Ÿš€\nYour involvement in our project has been invaluable, and we're confident that your skills and insights will help us conquer this challenge๐Ÿ˜‡.

Use command /gdsc to self assign the issue.

This issue represents an exciting opportunity for us to improve and enhance our project, and we are thrilled to have you on board.\n We request you to follow [CONTRIBUTING GUIDELINES](../blob/master/CONTRIBUTING.md).\nLooking for your PR soon! \n In case of any issues, you can contact us on [Discord](https://discord.gg/mv4NTzN).โฃ๏ธ`; await github.issues.createComment({ owner, repo, issue_number: number, body: commentBody }); console.log(`Commented on the issue: ${commentBody}.`); diff --git a/.github/workflows/self_assign_issue.yml b/.github/workflows/self_assign_issue.yml new file mode 100644 index 0000000..b458904 --- /dev/null +++ b/.github/workflows/self_assign_issue.yml @@ -0,0 +1,75 @@ +name: self assign issue +on: + issue_comment: + types: + - created +jobs: + assign: + runs-on : ubuntu-latest + steps: + - name: Check for command + id: find_command + uses: actions/github-script@v4 + with: + github-token: ${{secrets.APIVerse_SECRET}} + script: | + const commentbody = context.payload.comment.body; + const assignUsing = '/gdsc'; + const isCommandPresent = commentbody.includes(assignUsing); + const commentor = context.payload.comment.user.login; + const Repoowner = context.payload.repository.owner.login; + console.log(`${Repoowner}`); + console.log(`${commentor}`); + const isSelf = commentor === context.payload.repository.owner.login; + console.log(`${isSelf}`); + console.log(`${context.payload.issue.assignees.map(assignee => assignee.login)}`); + + const noOfAssignees = context.payload.issue.assignees.length>0; + console.log(`No of Assignees : ${noOfAssignees}`); + if(isCommandPresent && isSelf) + { + console.log('Instruction given to contributor comment, so ignore'); + console.log(`::set-output name=toAssign::false`); + console.log(`Ins from repo owner end`); + } + else if(isCommandPresent && noOfAssignees) + { + console.log('Issue is already assigned'); + const { owner,repo, number} = context.issue; + const commentbody = `Hey @${commentor}, The issue is already assigned and couldn't be assigned to you again.You can work on some other issue or create your own issue.๐Ÿš€๐Ÿ’—`; + github.issues.createComment({ owner, repo, issue_number: number, body: commentbody }); + console.log(`::set-output name=toAssign::false`); + console.log('Command present and issue already assigned'); + } + else if(isCommandPresent) + { + console.log(`::set-output name=toAssign::true`); + console.log('Command present and issue not assigned'); + } + else + { + console.log(`::set-output name=toAssign::false`); + console.log('Command not present'); + } + - name: Assign the issue + if: steps.find_command.outputs.toAssign == 'true' + id: assign_issue + uses: actions/github-script@v4 + with: + github-token: ${{ secrets.APIVerse_SECRET}} + script: | + console.log('Demo Text'); + const { owner, repo, number } = context.issue; + const assignee = context.payload.comment.user.login; + await github.issues.addAssignees({ owner, repo, issue_number: number, assignees: [assignee] }); + console.log(`Assigned the issue to ${assignee}.`); + + + + + + + + + +