Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add a github action to send slack notification if number of reactions exceeds threshold in PRs and issues #222

Closed
wants to merge 46 commits into from
Closed
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3054acb
Add emoji checker to count the number of reactions
pragya-20 Mar 30, 2023
7c25d6a
Rename emoji checker
pragya-20 Mar 30, 2023
c39782f
Update actions version to Node 16
pragya-20 Mar 30, 2023
64be41c
Update emoji_checker triggers
pragya-20 Mar 30, 2023
9145c73
Add slack bot
pragya-20 Mar 30, 2023
37fabac
Update emoji checker to use slack bot
pragya-20 Mar 30, 2023
2b66090
Add init function call
pragya-20 Mar 30, 2023
861a982
Update Emoji Checker
pragya-20 Mar 30, 2023
a8f4150
Add post to slack channer
pragya-20 Mar 30, 2023
07132cc
Implement conditional slack message
pragya-20 Mar 30, 2023
88dffba
Add message print
pragya-20 Mar 30, 2023
94e3817
Test Changes 8
pragya-20 Mar 30, 2023
d4e5a8d
Add output message
pragya-20 Mar 30, 2023
2c02590
Add test message to slack
pragya-20 Mar 30, 2023
b79b381
Add non-conditional slack message
pragya-20 Mar 30, 2023
1e741e0
Add debug message
pragya-20 Mar 30, 2023
4f953eb
Update emoji checker
pragya-20 Mar 30, 2023
7cc3fbe
Update emoji-checker.yml
pragya-20 Mar 30, 2023
8e50a3f
Update emoji-checker.yml
pragya-20 Mar 30, 2023
80a32c1
Update emoji-checker.yml
pragya-20 Mar 30, 2023
ebda061
Update emoji-checker.yml
pragya-20 Mar 30, 2023
30ffff3
Update emoji-checker.yml
pragya-20 Mar 30, 2023
3e8ea2f
Update emoji-checker.yml
pragya-20 Mar 30, 2023
6e8e762
Update emoji-checker.yml
pragya-20 Mar 30, 2023
1b01b18
Update emoji-checker.yml
pragya-20 Mar 30, 2023
935dcb7
Update emoji-checker.yml
pragya-20 Mar 30, 2023
50c36a2
Update emoji-checker.yml
pragya-20 Mar 30, 2023
2ec7048
Update emoji-checker.yml
pragya-20 Mar 30, 2023
0da2b74
Update emoji-checker.yml
pragya-20 Mar 30, 2023
8b6a53f
Update emoji-checker.yml
pragya-20 Mar 30, 2023
52f923e
Update emoji-checker.yml
pragya-20 Mar 30, 2023
ba06dbc
Update emoji-checker.yml
pragya-20 Mar 30, 2023
36a9002
Update emoji-checker.yml
pragya-20 Mar 30, 2023
45cb546
Update emoji-checker.yml
pragya-20 Mar 30, 2023
8e2437e
Update emoji-checker.yml
pragya-20 Mar 30, 2023
d942bd3
Update emoji-checker.yml
pragya-20 Mar 30, 2023
2e2299c
Update emoji-checker.yml
pragya-20 Mar 30, 2023
d98c07c
Update emoji-checker.yml
pragya-20 Mar 30, 2023
439cf68
Update emoji-checker.yml
pragya-20 Mar 30, 2023
17197ff
Update emoji-checker.yml
pragya-20 Mar 30, 2023
3ad2cde
Update emoji-checker.yml
pragya-20 Mar 30, 2023
ea6591f
Update emoji-checker.yml
pragya-20 Mar 30, 2023
130d30c
Update emoji-checker.yml
pragya-20 Mar 30, 2023
710816c
Update README.md
pragya-20 Mar 30, 2023
8346e21
Delete slack-bot.js
pragya-20 Mar 30, 2023
b60103d
Removed unused comments
pragya-20 Mar 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .github/workflows/emoji-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Emoji Checker

on:
schedule:
- cron: "0 8 * * *" # run this job at 8:00 am daily
pull_request_review_comment:
types: [created, edited]
issue_comment:
types: [created, edited]
discussion_comment:
types: [created, edited]
env:
THRESHOLD_REACTIONS: 5
jobs:
check-emojis:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Check emojis
uses: actions/github-script@v6
id: check-emojis
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const query = `
query ($owner: String!, $repo: String!, $number: Int!) {
repository(owner: $owner, name: $repo) {
issueOrPullRequest(number: $number) {
... on Issue {
title
url
reactions(last: 100) {
nodes {
content
user {
login
}
}
}
}
... on PullRequest {
title
url
reactions(last: 100) {
nodes {
content
user {
login
}
}
}
}
}
}
}
`;
const variables = {
owner: context.repo.owner,
repo: context.repo.repo,
number: context.issue.number
};
const result = await github.graphql(query, variables);
const node = result.repository.issueOrPullRequest;
const reactions = node.reactions.nodes;
const reactionCounts = {};
reactions.forEach(reaction => {
const content = reaction.content;
if (content in reactionCounts) {
reactionCounts[content]++;
} else {
reactionCounts[content] = 1;
}
});
let message = '';
let totalReactions = 0;
for (const [emoji, count] of Object.entries(reactionCounts)) {
message += `${emoji}: ${count}\n`;
totalReactions += count;
}
if (message !== '' && totalReactions >= process.env.THRESHOLD_REACTIONS) {
const title = node.title;
const url = node.url;
message = `The issue/PR "${title}" (${url}) has the following emojis:\n${message}`;
console.log(message);
}
else {
message = '';
}
return message;
result-encoding: string
- name: Post to a Slack channel
id: slack
if: ${{ steps.check-emojis.outputs.result }}
uses: slackapi/slack-github-action@v1.23.0
with:
# Slack channel id, channel name, or user id to post message.
# See also: https://api.slack.com/methods/chat.postMessage#channels
# You can pass in multiple channels to post to by providing a comma-delimited list of channel IDs.
channel-id: 'C050YTTDYUS'
# For posting a simple plain text message
slack-message: ${{ steps.check-emojis.outputs.result }}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}