forked from abensur/github-activity-digest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
141 lines (123 loc) · 4.02 KB
/
index.ts
File metadata and controls
141 lines (123 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env bun
import { defineCommand, runMain } from 'citty';
import { Octokit } from '@octokit/rest';
import { loadConfig, type Config } from './lib/config';
import { initializeAIClient, generateSummary, type AIClient } from './lib/ai';
import { getAllRepositories, getRateLimitInfo, displayRateLimitInfo } from './lib/github';
import { trackRepositoryActivities } from './lib/activity';
import { getCachedActivity, setCachedActivity } from './lib/cache';
import { mkdir } from 'fs/promises';
import { join } from 'path';
import { logger } from './lib/logger';
const main = defineCommand({
meta: {
name: 'github-activity-digest',
description: 'Generate AI-powered summaries of GitHub repository activity',
version: '2.0.0'
},
args: {
org: {
type: 'string',
description: 'GitHub organization name'
},
user: {
type: 'string',
description: 'GitHub username'
},
topics: {
type: 'string',
description: 'Comma-separated list of topics'
},
file: {
type: 'string',
description: 'Path to file with repository list'
},
repos: {
type: 'string',
description: 'Comma-separated list of owner/repo'
},
days: {
type: 'string',
description: 'Number of days to look back',
default: '7'
},
'no-cache': {
type: 'boolean',
description: 'Bypass cache and fetch fresh data',
default: false
}
},
async run({ args }) {
logger.box('GitHub Weekly Activity Report Generator');
const config: Config = await loadConfig({
org: args.org,
user: args.user,
topics: args.topics,
file: args.file,
repos: args.repos,
days: args.days ? parseInt(args.days, 10) : undefined,
noCache: args['no-cache']
});
const octokit = new Octokit({
auth: config.github.token,
log: {
debug: () => {},
info: () => {},
warn: () => {},
error: () => {}
}
});
const aiClient: AIClient = initializeAIClient(config);
logger.start('Fetching repositories...');
const repos = await getAllRepositories(octokit, config);
if (repos.length === 0) {
logger.error('No repositories found matching the criteria');
process.exit(1);
}
logger.success(`Found ${repos.length} repositories matching the criteria`);
const since = new Date(config.period.startDate);
let repoActivities = config.noCache ? null : getCachedActivity(repos, since);
if (repoActivities) {
logger.info('Using cached activity data');
} else {
if (config.noCache) {
logger.info('Cache bypassed (--no-cache flag)');
}
repoActivities = await trackRepositoryActivities(octokit, repos, since);
if (!config.noCache) {
await setCachedActivity(repos, since, repoActivities);
}
}
const activeRepos = Object.entries(repoActivities).filter(
([_, activity]) => activity.mergedPRs.length > 0 || activity.directCommits.length > 0
);
if (activeRepos.length === 0) {
logger.warn('No activity found in the specified period');
process.exit(0);
}
logger.success(`Activity found in ${activeRepos.length} repositories`);
logger.start('Generating AI summary...');
const summary = await generateSummary(
aiClient,
config,
repoActivities,
config.period.startDate,
config.period.endDate
);
logger.success('Summary generated successfully!');
logger.log('\n' + summary + '\n');
if (config.output.archiveDir) {
const archiveDir = config.output.archiveDir;
const timestamp = new Date().toISOString().split('T')[0];
const filename = `weekly-report-${timestamp}.md`;
const filepath = join(archiveDir, filename);
await mkdir(archiveDir, { recursive: true });
await Bun.write(filepath, summary);
logger.success(`Saved to: ${filepath}`);
}
// Display rate limit info at the end
const rateLimit = await getRateLimitInfo(octokit);
displayRateLimitInfo(rateLimit);
}
});
runMain(main);