-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Discord GFI webhook #12436
Discord GFI webhook #12436
Changes from 3 commits
13f35fe
b5e56c6
9744ef0
1e1414a
5e26735
dc66d76
6ac7d23
f8550a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: GFI Discord webhook | ||
|
||
on: | ||
schedule: | ||
- cron: "0 * * * *" | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
name: GFI Discord webhook | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@master | ||
pettinarip marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 18 | ||
pettinarip marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- run: yarn install | ||
- run: yarn discord-issues | ||
env: | ||
DISCORD_ID: ${{ secrets.DISCORD_ID }} | ||
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} | ||
ISSUES_GITHUB_TOKEN: ${{ secrets.ISSUES_GITHUB_TOKEN_READ_ONLY }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const owner = "ethereum" | ||
const repo = "ethereum-org-website" | ||
const label = "good first issue" | ||
|
||
type GHIssue = { | ||
title: string | ||
html_url: string | ||
created_at: string | ||
user: { | ||
login: string | ||
html_url: string | ||
avatar_url: string | ||
} | ||
} | ||
|
||
export const fetchGFIs = async (since: string) => { | ||
const url = `https://api.github.com/repos/${owner}/${repo}/issues?labels=${encodeURIComponent( | ||
label | ||
)}&since=${since}&state=open&sort=created&direction=desc` | ||
|
||
try { | ||
const response = await fetch(url, { | ||
headers: { | ||
Authorization: `token ${process.env.ISSUES_GITHUB_TOKEN_READ_ONLY}`, | ||
Accept: "application/vnd.github.v3+json", | ||
}, | ||
}) | ||
|
||
if (!response.ok) { | ||
throw new Error( | ||
`GitHub API responded with ${response.status}: ${response.statusText}` | ||
) | ||
} | ||
|
||
return (await response.json()) as GHIssue[] | ||
} catch (error) { | ||
console.error(error) | ||
return [] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,63 @@ | ||||||||||
import * as dotenv from "dotenv" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably we won't need this
Suggested change
|
||||||||||
|
||||||||||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the
Suggested change
|
||||||||||
import { fetchGFIs } from "../lib/api/fetchGFIs" | ||||||||||
|
||||||||||
dotenv.config({ path: `.env.local` }) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
const run = async () => { | ||||||||||
// Calculate the start of the last hour | ||||||||||
const now = new Date() | ||||||||||
const sinceDate = new Date( | ||||||||||
now.getFullYear(), | ||||||||||
now.getMonth(), | ||||||||||
now.getDate(), | ||||||||||
now.getHours() - 1 | ||||||||||
).toISOString() | ||||||||||
|
||||||||||
const issues = await fetchGFIs(sinceDate) | ||||||||||
|
||||||||||
if (!issues.length) { | ||||||||||
console.log("No new good first issues found.") | ||||||||||
return | ||||||||||
} | ||||||||||
|
||||||||||
const embeds = issues.map((issue) => ({ | ||||||||||
title: issue.title, | ||||||||||
url: issue.html_url, | ||||||||||
timestamp: issue.created_at, | ||||||||||
color: 10181046, | ||||||||||
footer: { | ||||||||||
text: "Good First Issue", | ||||||||||
}, | ||||||||||
author: { | ||||||||||
name: issue.user.login, | ||||||||||
url: issue.user.html_url, | ||||||||||
icon_url: issue.user.avatar_url, | ||||||||||
}, | ||||||||||
})) | ||||||||||
const message = { | ||||||||||
content: | ||||||||||
issues.length > 1 | ||||||||||
? `## (${issues.length}) New good first issues! 🎉` | ||||||||||
: "## New good first issue! 🎉", | ||||||||||
embeds, | ||||||||||
} | ||||||||||
|
||||||||||
const webhookUrl = `https://discord.com/api/webhooks/${process.env.DISCORD_ID}/${process.env.DISCORD_TOKEN}` | ||||||||||
|
||||||||||
const res = await fetch(webhookUrl, { | ||||||||||
method: "post", | ||||||||||
body: JSON.stringify(message), | ||||||||||
headers: { "Content-Type": "application/json" }, | ||||||||||
}) | ||||||||||
|
||||||||||
if (!res.ok) { | ||||||||||
const error = await res.json() | ||||||||||
console.log(error, res) | ||||||||||
throw new Error(`Error: ${res.status} ${res.statusText}`) | ||||||||||
} | ||||||||||
|
||||||||||
console.log("Message sent successfully!") | ||||||||||
} | ||||||||||
|
||||||||||
run() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just need to add these here: https://github.com/ethereum/ethereum-org-website/settings/secrets/actions