Skip to content

Commit

Permalink
feat: Optimize the code for repo topic
Browse files Browse the repository at this point in the history
  • Loading branch information
imfycc committed Nov 7, 2021
1 parent f9d9511 commit 72eab9a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/full-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ jobs:
TOKEN_OF_GITHUB: ${{ secrets.TOKEN_OF_GITHUB }}
FULLSYNC_LIMIT: 2000
PARTIALSYNC_LIMIT: 10
REPO_TOPICS_LIMIT: 50
FULL_SYNC: true
run: npm start
1 change: 1 addition & 0 deletions .github/workflows/partial-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
TOKEN_OF_GITHUB: ${{ secrets.TOKEN_OF_GITHUB }}
FULLSYNC_LIMIT: 2000
PARTIALSYNC_LIMIT: 10
REPO_TOPICS_LIMIT: 50
run: npm start

- uses: actions/upload-artifact@v2
Expand Down
8 changes: 4 additions & 4 deletions libs/github.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Octokit } from '@octokit/core';
import { QueryForStarredRepository, Repo, GithubRepositoryTopic, RepositoryTopic } from './types';

const githubTopicsFirst = +process.env.REPO_TOPICS_LIMIT || 50;

export class Github {
private client: Octokit;

Expand All @@ -20,10 +22,9 @@ export class Github {
let cursor = '';
let hasNextPage = true;
const repoList = [];
const topicFirst = 50;

while (hasNextPage || repoList.length < limit) {
const data = await this.getStarredRepoAfterCursor(cursor, topicFirst);
const data = await this.getStarredRepoAfterCursor(cursor, githubTopicsFirst);
repoList.push(
...this.transformGithubStarResponse(data),
);
Expand All @@ -40,11 +41,10 @@ export class Github {
async getList() {
// @ts-ignore
const limit = +process.env.PARTIALSYNC_LIMIT || 10;
const topicFirst = 50;

console.log(`Github: Start to sync latest starred repos, limit is ${limit}`);

const data = await this.getLastStarredRepo(limit, topicFirst);
const data = await this.getLastStarredRepo(limit, githubTopicsFirst);
this.repoList.push(
...this.transformGithubStarResponse(data),
);
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Manage all your Github Starred repos with Notion Database and Github Actions;
- NOTION_API_KEY
- NOTION_DATABASE_ID
- TOKEN_OF_GITHUB
- REPO_TOPICS_LIMIT
1 change: 1 addition & 0 deletions readme.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

- `FULLSYNC_LIMIT` 全量同步的最大 Repo 个数,默认为 2000 个
- `PARTIALSYNC_LIMIT` 增量同步的最大 Repo 个数,每次增量同步会从后往前取若干条数据,默认为 10 个
- `REPO_TOPICS_LIMIT` Repo 添加的话题数量,默认取前 50 个

需要在 `github/workflows/*.yml` 中,修改这个配置

Expand Down

0 comments on commit 72eab9a

Please sign in to comment.