forked from lcjnil/github-notion-star
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
38 lines (30 loc) · 949 Bytes
/
main.ts
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
import { github } from './libs/github';
import { notion } from './libs/notion';
import assert from 'assert';
async function fullSync() {
await Promise.all([github.fullSync(), notion.fullSyncIfNeeded()]);
for (const repo of github.repoList) {
if (!notion.hasPage(repo.nameWithOwner)) {
await notion.insertPage(repo);
}
}
}
async function partialSync() {
await Promise.all([github.getList(), notion.fullSyncIfNeeded()]);
for (const repo of github.repoList.reverse()) {
if (notion.hasPage(repo.nameWithOwner)) {
console.log(`Skip saved page ${repo.nameWithOwner}`);
continue;
}
await notion.insertPage(repo);
}
}
const ENVS = ['NOTION_API_KEY', 'NOTION_DATABASE_ID', 'TOKEN_OF_GITHUB'];
ENVS.forEach((env) => {
assert(process.env[env], `${env} must be added`);
});
if (process.env.FULL_SYNC) {
fullSync();
} else {
partialSync();
}