diff --git a/extensions/github1s/src/adapters/ossinsight/constants.ts b/extensions/github1s/src/adapters/ossinsight/constants.ts index 40a900819..85738cadf 100644 --- a/extensions/github1s/src/adapters/ossinsight/constants.ts +++ b/extensions/github1s/src/adapters/ossinsight/constants.ts @@ -16,7 +16,7 @@ export const RankingLanguages = [ 'PHP', 'C++', 'C#', - 'Typescript', + 'TypeScript', 'Shell', 'C', 'Ruby', diff --git a/extensions/github1s/src/adapters/ossinsight/interfaces.ts b/extensions/github1s/src/adapters/ossinsight/interfaces.ts index 5a312dd84..8fb38b93f 100644 --- a/extensions/github1s/src/adapters/ossinsight/interfaces.ts +++ b/extensions/github1s/src/adapters/ossinsight/interfaces.ts @@ -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 => { 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 => { - 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 => { - const requestUrl = `${OSSInsightEndpoint}/collections`; + const requestUrl = `${OSSInsightEndpoint}/v1/collections/`; return fetch(requestUrl).then(resolveDataFromResponse); }); -export const getCollectionIdByName = async (collectionName: string): Promise => { +export const getCollectionIdByName = async (collectionName: string): Promise => { 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 => { - const requestUrl = `${OSSInsightEndpoint}/q/collection-stars-last-28-days-rank?collectionId=${collectionId}`; +export const getCollectionStarsLast28DaysRank = (collectionId: string): Promise => { + const requestUrl = `${OSSInsightEndpoint}/v1/collections/${collectionId}/ranking_by_stars/`; return fetch(requestUrl).then(resolveDataFromResponse); }; -export const getCollectionPullRequestsLast28DaysRank = (collectionId: number): Promise => { - const requestUrl = `${OSSInsightEndpoint}/q/collection-pull-requests-last-28-days-rank?collectionId=${collectionId}`; +export const getCollectionPullRequestsLast28DaysRank = (collectionId: string): Promise => { + const requestUrl = `${OSSInsightEndpoint}/v1/collections/${collectionId}/ranking_by_issues/`; return fetch(requestUrl).then(resolveDataFromResponse); }; -export const getCollectionIssuesLast28DaysRank = (collectionId: number): Promise => { - 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 => { + const requestUrl = `${OSSInsightEndpoint}/v1/collections/${collectionId}/ranking_by_prs/`; return fetch(requestUrl).then(resolveDataFromResponse); }; diff --git a/extensions/github1s/src/adapters/ossinsight/templates.ts b/extensions/github1s/src/adapters/ossinsight/templates.ts index 5b4bf4cd3..360654f23 100644 --- a/extensions/github1s/src/adapters/ossinsight/templates.ts +++ b/extensions/github1s/src/adapters/ossinsight/templates.ts @@ -34,8 +34,8 @@ 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 ? '    Built by  ' + contributorAvatars.join('  ') : ''; @@ -43,7 +43,7 @@ const createRepoItemMarkdown = (repo: RepoItem, period: RankingPeriod) => { 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 || ''} @@ -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 + ? ` (↓${absValue})` + : rank_change < 0 + ? ` (↑${absValue})` + : ''; +}; + export const createCollectionsListPageMarkdown = async () => { const collectionReposMap = new Map(); 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; @@ -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 `