Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

Commit 357be27

Browse files
committed
Refactor GitHub stats handling and streamline issue fetching
- Renamed `refreshGithubStats` to `refreshGithub` for clarity. - Consolidated issue fetching logic into the `refreshGithub` function, removing the now redundant `refreshRepositoryIssues` function. - Updated the queue handling in `index.ts` to reflect the function name change and removed the call to the obsolete `refreshRepositoryIssues`. These changes enhance the organization of the code and improve the efficiency of GitHub stats processing.
1 parent 25661bb commit 357be27

2 files changed

Lines changed: 14 additions & 26 deletions

File tree

src/handlers.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const githubIssueWebhook = async (c: Context<{ Bindings: Env }>) => {
5757
};
5858

5959
// Background refreshers
60-
export const refreshGithubStats = async (context: AppContext) => {
60+
export const refreshGithub = async (context: AppContext) => {
6161
console.log('Fetching repositories and queueing GitHub stats tasks');
6262
const githubService = new GitHubService(context);
6363
const cacheService = new CacheService(context.env);
@@ -84,6 +84,13 @@ export const refreshGithubStats = async (context: AppContext) => {
8484
repo: repo.name,
8585
timestamp: Date.now()
8686
} as GitHubTaskMessage);
87+
88+
await context.env.GITHUB_QUEUE.send({
89+
type: 'fetch-repository-issues',
90+
owner: repo.owner.login,
91+
repo: repo.name,
92+
timestamp: Date.now()
93+
} as GitHubTaskMessage);
8794
}
8895

8996
// Queue a task to process all contributor data after the individual tasks
@@ -102,25 +109,6 @@ export const refreshGithubStats = async (context: AppContext) => {
102109
console.log('Queued GitHub stats tasks for all repositories');
103110
};
104111

105-
export const refreshRepositoryIssues = async (context: AppContext) => {
106-
console.log('Queueing Repository Issues refresh tasks');
107-
const cacheService = new CacheService(context.env);
108-
109-
const repos = await cacheService.getRepositories();
110-
111-
// Queue issue fetching for each repository
112-
for (const repo of repos) {
113-
await context.env.GITHUB_QUEUE.send({
114-
type: 'fetch-repository-issues',
115-
owner: repo.owner.login,
116-
repo: repo.name,
117-
timestamp: Date.now()
118-
} as GitHubTaskMessage);
119-
}
120-
121-
console.log('Queued Repository Issues tasks');
122-
};
123-
124112
export const refreshPackagistStats = async (context: AppContext) => {
125113
console.log('Refreshing Packagist Stats');
126114
const packagistService = new PackagistService();

src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import {
88
listRepositoryIssues,
99
listPackages,
1010
githubIssueWebhook,
11-
refreshGithubStats,
12-
refreshRepositoryIssues,
11+
refreshGithub,
1312
refreshPackagistStats
1413
} from './handlers';
1514
import { processGitHubTasks } from './queue';
@@ -51,7 +50,10 @@ export default {
5150

5251
// Queue handler - must be declared as a function, not an object
5352
async queue(batch: MessageBatch<GitHubTaskMessage>, env: Env, ctx: ExecutionContext) {
54-
await processGitHubTasks(batch, env);
53+
// Get the queue name from the batch
54+
if (batch.queue === 'github-tasks') {
55+
await processGitHubTasks(batch, env);
56+
}
5557
},
5658

5759
// Handle scheduled events
@@ -67,10 +69,8 @@ export default {
6769
// Determine which refresh operation to perform based on cron schedule
6870
if (controller.cron === '0 * * * *') {
6971
console.log('Starting Github Stats hourly job');
70-
// Hourly jobs
71-
await refreshGithubStats(context);
72+
await refreshGithub(context);
7273
await refreshPackagistStats(context);
73-
await refreshRepositoryIssues(context);
7474
}
7575
}
7676
};

0 commit comments

Comments
 (0)