Skip to content

Commit

Permalink
Auto comment on an issue and self assign the issue (#127)
Browse files Browse the repository at this point in the history
* Update and rename greetings.yaml to auto-comment.yml

* Create self-assign.yml
  • Loading branch information
MohanRamSridhar authored May 26, 2024
1 parent 7b7212e commit 879c4cc
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/auto-comment.yml
Original file line number Diff line number Diff line change
@@ -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}.`);
16 changes: 0 additions & 16 deletions .github/workflows/greetings.yaml

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/self-assign.yml
Original file line number Diff line number Diff line change
@@ -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]
});
}

0 comments on commit 879c4cc

Please sign in to comment.