fix: discord bot
This commit is contained in:
@@ -33,9 +33,6 @@ jobs:
|
||||
with:
|
||||
bun-version: latest
|
||||
|
||||
- name: Install mongodb dependency
|
||||
run: bun add mongodb
|
||||
|
||||
- name: Award XP and notify Discord
|
||||
run: bun run scripts/bounty-tracker.ts notify
|
||||
env:
|
||||
@@ -43,7 +40,8 @@ jobs:
|
||||
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
|
||||
GITHUB_REPOSITORY_NAME: ${{ github.event.repository.name }}
|
||||
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_BOUNTY_WEBHOOK_URL }}
|
||||
MONGODB_URI: ${{ secrets.MONGODB_URI }}
|
||||
BOT_API_URL: ${{ secrets.BOT_API_URL }}
|
||||
BOT_API_KEY: ${{ secrets.BOT_API_KEY }}
|
||||
LURKR_API_KEY: ${{ secrets.LURKR_API_KEY }}
|
||||
LURKR_GUILD_ID: ${{ secrets.LURKR_GUILD_ID }}
|
||||
PR_NUMBER: ${{ inputs.pr_number || github.event.pull_request.number }}
|
||||
|
||||
@@ -28,9 +28,6 @@ jobs:
|
||||
with:
|
||||
bun-version: latest
|
||||
|
||||
- name: Install mongodb dependency
|
||||
run: bun add mongodb
|
||||
|
||||
- name: Post leaderboard to Discord
|
||||
run: bun run scripts/bounty-tracker.ts leaderboard
|
||||
env:
|
||||
@@ -38,7 +35,8 @@ jobs:
|
||||
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
|
||||
GITHUB_REPOSITORY_NAME: ${{ github.event.repository.name }}
|
||||
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_BOUNTY_WEBHOOK_URL }}
|
||||
MONGODB_URI: ${{ secrets.MONGODB_URI }}
|
||||
BOT_API_URL: ${{ secrets.BOT_API_URL }}
|
||||
BOT_API_KEY: ${{ secrets.BOT_API_KEY }}
|
||||
LURKR_API_KEY: ${{ secrets.LURKR_API_KEY }}
|
||||
LURKR_GUILD_ID: ${{ secrets.LURKR_GUILD_ID }}
|
||||
SINCE_DATE: ${{ github.event.inputs.since_date || '' }}
|
||||
|
||||
@@ -104,7 +104,8 @@ Repo Settings > Secrets and variables > Actions:
|
||||
| `DISCORD_BOUNTY_WEBHOOK_URL` | Webhook URL from Step 5 |
|
||||
| `LURKR_API_KEY` | Lurkr API key from Step 4f |
|
||||
| `LURKR_GUILD_ID` | Your Discord server ID\* |
|
||||
| `MONGODB_URI` | MongoDB connection string |
|
||||
| `BOT_API_URL` | Discord bot API URL |
|
||||
| `BOT_API_KEY` | Discord bot API key |
|
||||
|
||||
\*Enable Developer Mode in Discord, right-click server name > Copy Server ID.
|
||||
|
||||
|
||||
+20
-20
@@ -18,7 +18,6 @@
|
||||
* PR_NUMBER — (notify mode) The merged PR number
|
||||
*/
|
||||
|
||||
import { MongoClient } from "mongodb";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Types
|
||||
@@ -151,37 +150,38 @@ async function getMergedBountyPRs(
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Identity resolution (MongoDB-backed)
|
||||
// Identity resolution (via bot API)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function loadContributors(): Promise<Map<string, Contributor>> {
|
||||
const map = new Map<string, Contributor>();
|
||||
|
||||
const uri = process.env.MONGODB_URI;
|
||||
if (!uri) {
|
||||
console.warn("Warning: MONGODB_URI not set, contributor lookups disabled");
|
||||
const apiUrl = process.env.BOT_API_URL;
|
||||
if (!apiUrl) {
|
||||
console.warn("Warning: BOT_API_URL not set, contributor lookups disabled");
|
||||
return map;
|
||||
}
|
||||
|
||||
const client = new MongoClient(uri);
|
||||
try {
|
||||
await client.connect();
|
||||
const db = client.db("hive");
|
||||
const docs = await db.collection("contributors").find().toArray();
|
||||
|
||||
for (const doc of docs) {
|
||||
map.set((doc.github as string).toLowerCase(), {
|
||||
github: (doc.githubDisplay as string) ?? (doc.github as string),
|
||||
discord: doc.discord as string,
|
||||
name: doc.name as string | undefined,
|
||||
});
|
||||
const headers: Record<string, string> = {};
|
||||
const apiKey = process.env.BOT_API_KEY;
|
||||
if (apiKey) {
|
||||
headers.Authorization = `Bearer ${apiKey}`;
|
||||
}
|
||||
|
||||
console.log(`Loaded ${map.size} contributors from MongoDB`);
|
||||
const res = await fetch(`${apiUrl}/api/contributors`, { headers });
|
||||
if (!res.ok) {
|
||||
throw new Error(`${res.status} ${res.statusText}`);
|
||||
}
|
||||
|
||||
const docs = (await res.json()) as Contributor[];
|
||||
for (const doc of docs) {
|
||||
map.set(doc.github.toLowerCase(), doc);
|
||||
}
|
||||
|
||||
console.log(`Loaded ${map.size} contributors from bot API`);
|
||||
} catch (err) {
|
||||
console.warn(`Warning: could not load contributors from MongoDB: ${err}`);
|
||||
} finally {
|
||||
await client.close();
|
||||
console.warn(`Warning: could not load contributors from bot API: ${err}`);
|
||||
}
|
||||
|
||||
return map;
|
||||
|
||||
Reference in New Issue
Block a user