Skip to content

Commit

Permalink
Merge pull request #81 from MohanRamSridhar/main
Browse files Browse the repository at this point in the history
Auto comment on issue and self assign the issue
  • Loading branch information
PayalKumari10 authored Jul 1, 2024
2 parents 20aecaa + afea7ea commit f6cb888
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 16 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/closed-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Close issue comment
on:
issues:
types:
- closed

jobs:
comment:
runs-on: ubuntu-latest

steps:
- name: Issue close
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 = `Hey @${commentauthor} ! Just wanted to inform you that the issue has been closed\nWould like to see you again.`;
await github.issues.createComment({ owner, repo, issue_number: number, body: commentBody });
console.log(`Commented on the issue: ${commentBody}.`);
41 changes: 41 additions & 0 deletions .github/workflows/closed-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Comment on PR Closure

on:
pull_request_target:
types:
- closed

jobs:
comment:
runs-on: ubuntu-latest

steps:
- name: Check PR Merge Status
id: pr_status
run: echo "::set-output name=merged::${{ github.event.pull_request.merged }}"

- name: Comment on PR Closure
if: steps.pr_status.outputs.merged == 'true'
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo, number } = context.issue;
const commentAuthor = context.payload.pull_request.user.login;
const commentBody = `Hey @${ commentAuthor } Super Happy to inform you that your PR has been merged!!!!!!\nWould like to see you again super soon.`;
await github.issues.createComment({ owner, repo, issue_number: number, body: commentBody });
console.log(`Commented on the closed PR: ${commentBody}.`);
- name: Comment on PR Closure
if: steps.pr_status.outputs.merged != 'true'
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo, number } = context.issue;
const commentAuthor = context.payload.pull_request.user.login;
const commentBody = `Hey @${ commentAuthor } ,Wanted to let you know that we have decided to close your pull request.
In case of any issues, you can contact me.
Thank you!`;
await github.issues.createComment({ owner, repo, issue_number: number, body: commentBody });
console.log(`Commented on the closed PR: ${commentBody}.`);
16 changes: 0 additions & 16 deletions .github/workflows/greetings.yaml

This file was deleted.

23 changes: 23 additions & 0 deletions .github/workflows/issue-comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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}.`);
22 changes: 22 additions & 0 deletions .github/workflows/pr-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Pull Request related comments
on:
pull_request_target:
types:
- opened

jobs:
comment:
runs-on: ubuntu-latest
steps:
- name: Comment on Opening Pull Request
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const {owner, repo, number} = context.issue;
const commentAuthor = context.payload.sender.login;
const commentBody = `Hey @${ commentAuthor }, Thank you for creating PR! Will review it super soon.
Don’t forget to ⭐ the repository!
Will see you soon!`;
await github.issues.createComment({owner, repo, issue_number : number, body: commentBody});
console.log('Commented on PR');
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 f6cb888

Please sign in to comment.