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

added workflows for bounty and new issue discord notifications #227

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 41 additions & 0 deletions .github/workflows/bounty.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Discord Notification for Bounty

on:
issue_comment:
types: [created]

jobs:
bounty-notification:
if: ${{ github.event.issue.pull_request && !startsWith(github.event.comment.body, '>') && github.event.comment.user.login == 'hkirat'}}
runs-on: [ubuntu-latest]
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Get Comment Text
id: get-comment
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const commentBody = context.payload.comment.body;
const regex = /\/bounty\s+\$([0-9]+)/;
const validatedText = commentBody.match(regex);
const amount = validatedText ? validatedText[1] : false
return amount

- name: Send Discord notification
if: steps.get-comment.outputs.result != 'false'
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISORD_WEBHOOK_URL }}
run: |
curl -X POST -H "Content-Type: application/json" -d '{
"username": "Bounty Bot",
"avatar_url": "https://i.imgur.com/dy2uNAS.png",
"embeds": [
{
"title": "🎉 We have a new bounty winner 🎉",
"description": "Bounty of $'${{ steps.get-comment.outputs.result }}' will be dispensed to [@${{ github.event.issue.user.login }}](${{github.event.issue.user.html_url}}) for successful Pull request ${{ github.event.issue.pull_request.html_url }}."
}
]
}' $DISCORD_WEBHOOK_URL
16 changes: 16 additions & 0 deletions .github/workflows/new-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Discord Notification on New Issue

on:
issues:
types: [opened]

jobs:
send_discord_notification:
runs-on: ubuntu-latest

steps:
- name: Send Discord Notification
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISORD_WEBHOOK_URL }}
run: |
curl -X POST -H "Content-Type: application/json" -d '{"content": "New issue opened: '${{ github.event.issue.html_url }}'"}' $DISCORD_WEBHOOK_URL
11 changes: 7 additions & 4 deletions src/db/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ export class Cache {
return this.instance;
}

set(type: string, args: string[], value: any, expirySeconds: number = parseInt(process.env.CACHE_EXPIRE_S || '100', 10)) {
set(
type: string,
args: string[],
value: any,
expirySeconds: number = parseInt(process.env.CACHE_EXPIRE_S || '100', 10),
) {
this.inMemoryDb.set(`${type} ${JSON.stringify(args)}`, {
value,
expiry: new Date().getTime() + expirySeconds * 1000,
Expand All @@ -46,7 +51,5 @@ export class Cache {
return entry.value;
}

evict() {

}
evict() {}
}