-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
10,528 additions
and
7,823 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// import { Octokit } from "@octokit/rest"; | ||
// import axios from "axios"; | ||
(async () => { | ||
const { Octokit } = await import("@octokit/rest") | ||
const { default: axios } = await import('axios'); | ||
|
||
// Configuration | ||
const GITHUB_TOKEN = process.env.GITHUB_TOKEN; | ||
const SLACK_WEBHOOK_URL = process.env.SLACK_ISSUE_NOTIFY_WEBHOOK_URL; | ||
const MANAGER_SLACK_ID = process.env.DEVELOPER_MANAGER_SLACK_ID; | ||
const REPO_OWNER = "GreptimeTeam"; | ||
const REPO_NAME = "docs"; | ||
const GITHUB_TO_SLACK = JSON.parse(process.env.GITHUBID_SLACKID_MAPPING); | ||
|
||
const octokit = new Octokit({ | ||
auth: GITHUB_TOKEN | ||
}); | ||
|
||
// Function to fetch open issues from the GitHub repository | ||
async function fetchOpenIssues() { | ||
try { | ||
const issues = await octokit.issues.listForRepo({ | ||
owner: REPO_OWNER, | ||
repo: REPO_NAME, | ||
state: "open", // Only fetch open issues | ||
per_page: 100 // Fetch 100 issues at a time | ||
}); | ||
return issues.data; | ||
} catch (error) { | ||
console.error("Error fetching issues:", error); | ||
return []; | ||
} | ||
} | ||
|
||
// Function to count issues per assignee | ||
function countIssuesByAssignee(issues) { | ||
const issueCountByAssignee = {}; | ||
|
||
issues.forEach(issue => { | ||
const assignees = issue.assignees; | ||
assignees.forEach(assignee => { | ||
const username = assignee.login; | ||
if (!issueCountByAssignee[username]) { | ||
issueCountByAssignee[username] = 0; | ||
} | ||
issueCountByAssignee[username] += 1; | ||
}); | ||
}); | ||
|
||
const sortedIssueCounts = Object.entries(issueCountByAssignee).sort((a, b) => b[1] - a[1]); | ||
|
||
const sortedIssueCountByAssignee = {}; | ||
sortedIssueCounts.forEach(([username, count]) => { | ||
sortedIssueCountByAssignee[username] = count; | ||
}); | ||
|
||
return sortedIssueCountByAssignee; | ||
} | ||
|
||
// Function to send a notification to Slack | ||
async function sendSlackNotification(issueCounts) { | ||
const messageLines = [`*🌼 Weekly GitHub Issue Report: 🌼* \n <@${MANAGER_SLACK_ID}>: Hey guys, let's close these issues together! 😉\n`]; | ||
for (const [githubUser, count] of Object.entries(issueCounts)) { | ||
const slackUserId = GITHUB_TO_SLACK[githubUser]; | ||
const slackMention = slackUserId ? `<@${slackUserId}>` : githubUser; | ||
|
||
const issueLink = `https://github.com/${REPO_OWNER}/${REPO_NAME}/issues?q=is%3Aissue+is%3Aopen+assignee%3A${githubUser}`; | ||
const formattedLine = `${slackMention}: <${issueLink}|${count} open issues>`; | ||
|
||
messageLines.push(formattedLine); | ||
} | ||
|
||
const message = messageLines.join("\n"); | ||
|
||
try { | ||
const response = await axios.post(SLACK_WEBHOOK_URL, { | ||
text: message | ||
}); | ||
|
||
if (response.status !== 200) { | ||
throw new Error(`Error sending Slack notification: ${response.status}`); | ||
} | ||
console.log("Notification sent to Slack successfully."); | ||
} catch (error) { | ||
console.error("Error sending notification to Slack:", error); | ||
} | ||
} | ||
|
||
async function run() { | ||
const issues = await fetchOpenIssues(); | ||
const issueCounts = countIssuesByAssignee(issues); | ||
await sendSlackNotification(issueCounts); | ||
} | ||
|
||
run(); | ||
})() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Weekly GitHub Issue Notifier | ||
|
||
on: | ||
schedule: | ||
- cron: '0 2 * * 1' # Run every Monday at 2:00 AM UTC | ||
|
||
jobs: | ||
notify: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install pnpm | ||
uses: pnpm/action-setup@v4 | ||
with: | ||
version: 8.6.0 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'pnpm' | ||
- run: pnpm install | ||
|
||
- name: Run the notifier script | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # GitHub token for API access | ||
SLACK_ISSUE_NOTIFY_WEBHOOK_URL: ${{ vars.SLACK_ISSUE_NOTIFY_WEBHOOK_URL }} # Slack webhook URL | ||
DEVELOPER_MANAGER_SLACK_ID: ${{ vars.DEVELOPER_MANAGER_SLACK_ID }} # Slack ID of the manager | ||
GITHUBID_SLACKID_MAPPING: ${{ vars.GITHUBID_SLACKID_MAPPING }} # JSON string mapping GitHub to Slack usernames | ||
run: node .github/scripts/issue-notification.js | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.DS_Store | ||
.docusaurus | ||
node_modules | ||
build | ||
build | ||
.envrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.