Skip to content

Commit

Permalink
Merge pull request #534 from conwnet/master
Browse files Browse the repository at this point in the history
release 0.19.0
  • Loading branch information
conwnet authored Oct 23, 2023
2 parents 597ca7f + ecb9ce6 commit ec58f0d
Show file tree
Hide file tree
Showing 17 changed files with 325 additions and 182 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-wtih-vscode-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-20.04]
node-version: [18.x]
node-version: [18.16.0]

runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion extensions/github1s/src/adapters/ossinsight/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const RankingLanguages = [
'PHP',
'C++',
'C#',
'Typescript',
'TypeScript',
'Shell',
'C',
'Ruby',
Expand Down
80 changes: 29 additions & 51 deletions extensions/github1s/src/adapters/ossinsight/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,104 +12,82 @@ const resolveDataFromResponse = (response: Response) => {
if (response.status < 200 || response.status >= 300) {
return [];
}
return response.json().then((body) => body?.data || []);
return response.json().then((body) => body?.data?.rows || []);
};

export type RepoItem = {
collection_names?: string;
contributor_logins?: string;
description?: string;
forks?: number;
forks: string;
language?: string;
repo_name: string;
stars?: number;
total_score?: number;
stars: string;
total_score: string;
};

export const getTrendingRepos = (period: RankingPeriod, language: string): Promise<RepoItem[]> => {
const encodedLanguage = encodeURIComponent(language) || 'All';
const periodValue =
period === RankingPeriod.Today ? 'past_24_hours' : RankingPeriod.ThisWeek ? 'past_week' : 'past_month';
const requestUrl = `${OSSInsightEndpoint}/q/trending-repos?language=${encodedLanguage}&period=${periodValue}`;
const requestUrl = `${OSSInsightEndpoint}/v1/trends/repos/?language=${encodedLanguage}&period=${periodValue}`;
return fetch(requestUrl).then(resolveDataFromResponse);
};

export type RecentHotCollectionItem = {
id: number;
last_2nd_month_rank: number;
last_month_rank: number;
id: string;
name: string;
rank: number;
rank_changes: number;
repo_id: number;
repos: string;
repo_id: string;
repo_name: string;
repos: number;
visits: number;
repo_rank_changes: string;
repo_past_period_rank: string;
repo_current_period_rank: string;
};

export const getRecentHotCollections = (): Promise<RecentHotCollectionItem[]> => {
const requestUrl = `${OSSInsightEndpoint}/q/recent-hot-collections`;
const requestUrl = `${OSSInsightEndpoint}/v1/collections/hot/`;
return fetch(requestUrl).then(resolveDataFromResponse);
};

export type CollectionItem = {
id: number;
id: string;
name: string;
public: number;
};

export const getCollections = memorize((): Promise<CollectionItem[]> => {
const requestUrl = `${OSSInsightEndpoint}/collections`;
const requestUrl = `${OSSInsightEndpoint}/v1/collections/`;
return fetch(requestUrl).then(resolveDataFromResponse);
});

export const getCollectionIdByName = async (collectionName: string): Promise<number | null> => {
export const getCollectionIdByName = async (collectionName: string): Promise<string | null> => {
const collections = await getCollections();
return collections.find((item) => item.name === collectionName)?.id || null;
};

export type Last28DaysRankItem = {
last_2nd_period_rank: number;
last_2nd_period_total: number;
last_period_rank: number;
last_period_total: number;
rank_pop: number;
repo_id: number;
repo_id: string;
repo_name: string;
total: number;
total_pop: number;
current_period_growth: string;
past_period_growth: string;
growth_pop: string;
rank_pop: string;
total: string;
current_period_rank: string;
past_period_rank: string;
};

export const getCollectionStarsLast28DaysRank = (collectionId: number): Promise<Last28DaysRankItem[]> => {
const requestUrl = `${OSSInsightEndpoint}/q/collection-stars-last-28-days-rank?collectionId=${collectionId}`;
export const getCollectionStarsLast28DaysRank = (collectionId: string): Promise<Last28DaysRankItem[]> => {
const requestUrl = `${OSSInsightEndpoint}/v1/collections/${collectionId}/ranking_by_stars/`;
return fetch(requestUrl).then(resolveDataFromResponse);
};

export const getCollectionPullRequestsLast28DaysRank = (collectionId: number): Promise<Last28DaysRankItem[]> => {
const requestUrl = `${OSSInsightEndpoint}/q/collection-pull-requests-last-28-days-rank?collectionId=${collectionId}`;
export const getCollectionPullRequestsLast28DaysRank = (collectionId: string): Promise<Last28DaysRankItem[]> => {
const requestUrl = `${OSSInsightEndpoint}/v1/collections/${collectionId}/ranking_by_issues/`;
return fetch(requestUrl).then(resolveDataFromResponse);
};

export const getCollectionIssuesLast28DaysRank = (collectionId: number): Promise<Last28DaysRankItem[]> => {
const requestUrl = `${OSSInsightEndpoint}/q/collection-issues-last-28-days-rank?collectionId=${collectionId}`;
return fetch(requestUrl).then(resolveDataFromResponse);
};

export type CollectionStarsMonthRankItem = {
current_month: string;
current_month_rank: number;
current_month_total: number;
last_month: string;
last_month_rank: number;
last_month_total: number;
rank_mom: number;
repo_id: number;
repo_name: string;
total: number;
total_mom: number;
};

export const getCollectionStarsMonthRank = (collectionId: number) => {
const requestUrl = `https://api.ossinsight.io/q/collection-stars-last-28-days-rank?collectionId=${collectionId}`;
export const getCollectionIssuesLast28DaysRank = (collectionId: string): Promise<Last28DaysRankItem[]> => {
const requestUrl = `${OSSInsightEndpoint}/v1/collections/${collectionId}/ranking_by_prs/`;
return fetch(requestUrl).then(resolveDataFromResponse);
};
39 changes: 25 additions & 14 deletions extensions/github1s/src/adapters/ossinsight/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ const createRepoItemMarkdown = (repo: RepoItem, period: RankingPeriod) => {
`[![LastCommit](https://img.shields.io/github/last-commit/${repo.repo_name})](https://github.com/${repo.repo_name}/commits)`,
];

const increaseStarsText = (repo.stars || 0) >= 0 ? `+${repo.stars || 0}` : `-${repo.stars}`;
const increaseForksText = (repo.forks || 0) >= 0 ? `+${repo.forks || 0}` : `-${repo.forks}`;
const increaseStarsText = (+repo.stars || 0) >= 0 ? `+${repo.stars || 0}` : `-${repo.stars}`;
const increaseForksText = (+repo.forks || 0) >= 0 ? `+${repo.forks || 0}` : `-${repo.forks}`;
const contributorsMarkdown = contributorAvatars.length
? ' &nbsp;&nbsp; Built by &nbsp;' + contributorAvatars.join('&nbsp;&nbsp;')
: '';
const collectionMarkdown = repo.collection_names ? ` &nbsp;&nbsp; <i>${repo.collection_names}</i>` : '';
const fireThreshold = period === RankingPeriod.ThisWeek ? 5000 : period === RankingPeriod.ThisMonth ? 12000 : 1000;

return `
## ${(repo.total_score || 0) >= fireThreshold ? '🔥' : '🚀'} [${repo.repo_name}](${buildRepoLink(repo.repo_name)})
## ${(+repo.total_score || 0) >= fireThreshold ? '🔥' : '🚀'} [${repo.repo_name}](${buildRepoLink(repo.repo_name)})
${repo.description || ''}
Expand Down Expand Up @@ -126,12 +126,23 @@ const getPopCountText = (pop_count: number, percentage = false) => {
: '';
};

const getRankChangeText = (rank_change: number) => {
const absValue = Math.abs(rank_change);
return rank_change > 0
? ` <span style="color: #ff453a">(↓${absValue})</span>`
: rank_change < 0
? ` <span style="color: #30d158">(↑${absValue})</span>`
: '';
};

export const createCollectionsListPageMarkdown = async () => {
const collectionReposMap = new Map<string, [string, string][]>();
const [hotCollections, allCollections] = await Promise.all([getRecentHotCollections(), getCollections()]);
const sortedCollections = hotCollections.sort((itemA, itemB) => itemA.rank - itemB.rank);
const sortedCollections = hotCollections.sort(
(itemA, itemB) => +itemA.repo_current_period_rank - +itemB.repo_current_period_rank
);
const uniqueCollections = sortedCollections.filter((collection) => {
const relativeRankText = getPopCountText(collection.last_2nd_month_rank - collection.last_month_rank);
const relativeRankText = getRankChangeText(+collection.repo_rank_changes);
if (!collectionReposMap.has(collection.name)) {
collectionReposMap.set(collection.name, [[collection.repo_name, relativeRankText]]);
return true;
Expand Down Expand Up @@ -192,24 +203,24 @@ export const createCollectionPageMarkdown = async (collectionName: string) => {
]);

const starRankListMarkdown = starsData.map((item) => {
const rankMarkdown = ` ${item.last_period_rank}${getPopCountText(item.rank_pop)}`;
const rankMarkdown = ` ${item.current_period_rank}${getRankChangeText(+item.rank_pop)}`;
const repoMarkdown = ` [${item.repo_name}](${buildRepoLink(item.repo_name)})`;
const starsMarkdown = ` ${item.last_period_total}${getPopCountText(item.total_pop, true)}`;
return `|${rankMarkdown} |${repoMarkdown} |${starsMarkdown} | ${item.last_2nd_period_total} | ${item.total} |`;
const starsMarkdown = ` ${item.current_period_growth}${getPopCountText(+item.growth_pop, true)}`;
return `|${rankMarkdown} |${repoMarkdown} |${starsMarkdown} | ${item.past_period_growth} | ${item.total} |`;
});

const pullRankListMarkdown = pullsData.map((item) => {
const rankMarkdown = ` ${item.last_period_rank}${getPopCountText(item.rank_pop)}`;
const rankMarkdown = ` ${item.current_period_rank}${getRankChangeText(+item.rank_pop)}`;
const repoMarkdown = ` [${item.repo_name}](${buildRepoLink(item.repo_name)})`;
const starsMarkdown = ` ${item.last_period_total}${getPopCountText(item.total_pop, true)}`;
return `|${rankMarkdown} |${repoMarkdown} |${starsMarkdown} | ${item.last_2nd_period_total} | ${item.total} |`;
const starsMarkdown = ` ${item.current_period_growth}${getPopCountText(+item.growth_pop, true)}`;
return `|${rankMarkdown} |${repoMarkdown} |${starsMarkdown} | ${item.past_period_growth} | ${item.total} |`;
});

const issuesRankListMarkdown = issuesData.map((item) => {
const rankMarkdown = ` ${item.last_period_rank}${getPopCountText(item.rank_pop)}`;
const rankMarkdown = ` ${item.current_period_rank}${getRankChangeText(+item.rank_pop)}`;
const repoMarkdown = ` [${item.repo_name}](${buildRepoLink(item.repo_name)})`;
const starsMarkdown = ` ${item.last_period_total}${getPopCountText(item.total_pop, true)}`;
return `|${rankMarkdown} |${repoMarkdown} |${starsMarkdown} | ${item.last_2nd_period_total} | ${item.total} |`;
const starsMarkdown = ` ${item.current_period_growth}${getPopCountText(+item.growth_pop, true)}`;
return `|${rankMarkdown} |${repoMarkdown} |${starsMarkdown} | ${item.past_period_growth} | ${item.total} |`;
});

return `
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"lib": "lib"
},
"devDependencies": {
"@github1s/vscode-web": "0.13.0",
"@github1s/vscode-web": "0.14.0",
"@typescript-eslint/eslint-plugin": "^5.40.1",
"@typescript-eslint/parser": "^5.40.1",
"chokidar": "^3.5.3",
Expand Down
Loading

1 comment on commit ec58f0d

@vercel
Copy link

@vercel vercel bot commented on ec58f0d Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.