Skip to content

Commit

Permalink
feat: add starred at
Browse files Browse the repository at this point in the history
  • Loading branch information
lcjnil committed Jul 22, 2021
1 parent c71c9bd commit b2ca48e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 13 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/full-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ jobs:
NOTION_API_KEY: ${{ secrets.NOTION_API_KEY }}
NOTION_DATABASE_ID: ${{ secrets.NOTION_DATABASE_ID }}
TOKEN_OF_GITHUB: ${{ secrets.TOKEN_OF_GITHUB }}
FULLSYNC_LIMIT: 2000
FULLSYNC_LIMIT: 20
PARTIALSYNC_LIMIT: 10
SYNC_NOTION_FIRST: ${{ steps.cache.outputs.cache-hit != 'true' }}
FULL_SYNC: true
run: npm start
1 change: 0 additions & 1 deletion .github/workflows/partial-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ jobs:
TOKEN_OF_GITHUB: ${{ secrets.TOKEN_OF_GITHUB }}
FULLSYNC_LIMIT: 2000
PARTIALSYNC_LIMIT: 10
SYNC_NOTION_FIRST: ${{ steps.cache.outputs.cache-hit != 'true' }}
run: npm start

- uses: actions/upload-artifact@v2
Expand Down
37 changes: 29 additions & 8 deletions libs/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ export class Github {
let hasNextPage = true;
const repoList = [];

while (hasNextPage || repoList.length >= limit) {
while (hasNextPage || repoList.length < limit) {
const data = await this.getStarredRepoAfterCursor(cursor);
repoList.push(...data.starredRepositories.nodes);
repoList.push(
...(data.starredRepositories.edges || []).map(({ node, starredAt }) => ({
...node,
starredAt,
})),
);

hasNextPage = data.starredRepositories.pageInfo.hasNextPage;
cursor = data.starredRepositories.pageInfo.endCursor;
Expand All @@ -36,11 +41,16 @@ export class Github {

async getList() {
// @ts-ignore
const limit = +process.env.PARTIALSYNC_LIMIT || 2000;
const limit = +process.env.PARTIALSYNC_LIMIT || 10;
console.log(`Github: Start to sync latest starred repos, limit is ${limit}`);

const data = await this.getLastStarredRepo(10);
this.repoList.push(...data.starredRepositories.nodes);
this.repoList.push(
...(data.starredRepositories.edges || []).map(({ node, starredAt }) => ({
...node,
starredAt,
})),
);
}

private async getStarredRepoAfterCursor(cursor: string) {
Expand All @@ -54,10 +64,13 @@ export class Github {
endCursor
hasNextPage
}
nodes {
nameWithOwner
url
description
edges {
starredAt
node {
nameWithOwner
url
description
}
}
}
}
Expand Down Expand Up @@ -87,6 +100,14 @@ export class Github {
url
description
}
edges {
starredAt
node {
nameWithOwner
url
description
}
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions libs/notion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ export class Notion {
},
],
},
'Starred At': {
type: 'date',
date: {
start: repo.starredAt,
end: repo.starredAt,
},
},
},
});

Expand Down
8 changes: 6 additions & 2 deletions libs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface Repo {
nameWithOwner: string;
url: string;
description: string;
starredAt: string;
}

export interface QueryForStarredRepository {
Expand All @@ -13,13 +14,16 @@ export interface QueryForStarredRepository {
endCursor: string;
hasNextPage: boolean;
};
nodes: Repo[];
edges: Array<{
starredAt: string;
node: Omit<Repo, 'starredAt'>;
}>;
};
}

export interface NotionPage extends Page {
properties: {
Name: TitlePropertyValue;
Url: URLPropertyValue;
Link: URLPropertyValue;
};
}

0 comments on commit b2ca48e

Please sign in to comment.