[READ-ONLY] Mirror of https://github.com/shuuji3/github-contribution-recorder. 馃摴 A tool to record GitHub activities (commits, issues, PRs, comments) into a local SQLite database.
1.6 kB
53 lines
1import { getRepos, fetch } from './github.ts'
2import { saveActivity, saveRepository } from './db.ts'
3import { config } from './config.ts'
4
5const username = process.argv[2]
6if (username === '--help' || !username || !config.users[username]) {
7 console.log(`Usage: node main.ts <username>`)
8 console.log(`Available users: ${Object.keys(config.users).join(', ')}`)
9 process.exit(0)
10}
11
12const repos = getRepos(username)
13
14for (const repo of repos) {
15 const [owner, name] = repo.fullName.split('/')
16 saveRepository(repo.id, repo.fullName)
17 console.log(`Syncing ${repo.fullName}...`)
18
19 const commits = fetch(username, owner, name, 'commits', () => true)
20 for (const commit of commits) {
21 saveActivity(
22 repo.id,
23 'commit',
24 commit,
25 commit.sha,
26 commit.commit.author.date,
27 username,
28 commit.html_url
29 )
30 }
31 const issues = fetch(username, owner, name, 'issues?state=all', (i: any) => !i.pull_request)
32 for (const issue of issues) {
33 saveActivity(repo.id, 'issue', issue, issue.node_id, issue.created_at, username, issue.html_url)
34 }
35 const prs = fetch(username, owner, name, 'pulls?state=all', () => true)
36 for (const pr of prs) {
37 saveActivity(repo.id, 'pull_request', pr, pr.node_id, pr.created_at, username, pr.html_url)
38 }
39 const comments = fetch(username, owner, name, 'issues/comments', () => true)
40 for (const comment of comments) {
41 saveActivity(
42 repo.id,
43 'issue_comment',
44 comment,
45 comment.node_id,
46 comment.created_at,
47 username,
48 comment.html_url
49 )
50 }
51}
52
53console.log('Sync complete!')