From 879c4ccc28100f74412fb728bb047e5ea1d43e6b Mon Sep 17 00:00:00 2001 From: Mohan Ram Sridhar <142170808+MohanRamSridhar@users.noreply.github.com> Date: Sun, 26 May 2024 18:50:02 +0530 Subject: [PATCH] Auto comment on an issue and self assign the issue (#127) * Update and rename greetings.yaml to auto-comment.yml * Create self-assign.yml --- .github/workflows/auto-comment.yml | 22 ++++++++++++++++++++++ .github/workflows/greetings.yaml | 16 ---------------- .github/workflows/self-assign.yml | 30 ++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/auto-comment.yml delete mode 100644 .github/workflows/greetings.yaml create mode 100644 .github/workflows/self-assign.yml diff --git a/.github/workflows/auto-comment.yml b/.github/workflows/auto-comment.yml new file mode 100644 index 0000000..6a46c0a --- /dev/null +++ b/.github/workflows/auto-comment.yml @@ -0,0 +1,22 @@ +name: Comment on opening issue! +on: + issues: + types: + - opened + +jobs: + comment: + runs-on: ubuntu-latest + + steps: + - name: Issue Opened + uses: actions/github-script@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { owner, repo, number } = context.issue; + const commentauthor = context.payload.issue.user.login; + const commentBody = `Hello @${commentauthor} Thank you for creating a new issue! 🎉 Your issue is currently under review.\nIf you would like to assign this issue to yourself, please comment with the word "self" and the issue will be assigned to you.`; + + await github.issues.createComment({ owner, repo, issue_number: number, body: commentBody }); + console.log(`Commented on the issue: ${commentBody}.`); diff --git a/.github/workflows/greetings.yaml b/.github/workflows/greetings.yaml deleted file mode 100644 index 704db0e..0000000 --- a/.github/workflows/greetings.yaml +++ /dev/null @@ -1,16 +0,0 @@ -name: Greetings - -on: [pull_request_target, issues] - -jobs: - greeting: - runs-on: ubuntu-latest - permissions: - issues: write - pull-requests: write - steps: - - uses: actions/first-interaction@v1 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - issue-message: "Hi there! Thanks for opening this issue. We appreciate your contribution to this open-source project. We aim to respond or assign your issue as soon as possible." - pr-message: "Welcome to Our repository.🎊 Thank you so much for taking the time to point this out." diff --git a/.github/workflows/self-assign.yml b/.github/workflows/self-assign.yml new file mode 100644 index 0000000..6381cea --- /dev/null +++ b/.github/workflows/self-assign.yml @@ -0,0 +1,30 @@ +name: Assign Issue to Self + +on: + issue_comment: + types: [created] + +permissions: + issues: write # Ensure the workflow has write permissions for issues + +jobs: + assign: + runs-on: ubuntu-latest + + steps: + - name: Assign issue to commenter if they comment "self" + uses: actions/github-script@v6 + with: + script: | + const issueNumber = context.issue.number; + const commentBody = context.payload.comment.body.trim().toLowerCase(); + const commenter = context.payload.comment.user.login; + + if (commentBody === 'self') { + await github.rest.issues.addAssignees({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issueNumber, + assignees: [commenter] + }); + }