From 19ecb3f9a5100e9a930171199e1ed30c27def6ab Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Fri, 13 Dec 2024 19:24:09 +0100 Subject: [PATCH] feat(core): Add tracking of commits published on npm --- changelog.md | 6 ++++ package.json | 3 +- pnpm-lock.yaml | 3 ++ ts/00_commitinfo_data.ts | 2 +- ts/codefeed.plugins.ts | 2 ++ ts/index.ts | 59 +++++++++++++++++++++++++++++++++------- 6 files changed, 63 insertions(+), 12 deletions(-) diff --git a/changelog.md b/changelog.md index cfd6651..6dd0f70 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2024-12-13 - 1.1.0 - feat(core) +Add tracking of commits published on npm + +- Introduced a check for published commits on npm using smartnpm. +- Enhanced fetchAllCommitsFromInstance to include 'publishedOnNpm' status in results. + ## 2024-12-13 - 1.0.2 - fix(core) Improve error handling in fetchRecentCommitsForRepo method diff --git a/package.json b/package.json index 889e7fe..adf3766 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "@types/node": "^20.8.7" }, "dependencies": { - "@push.rocks/qenv": "^6.1.0" + "@push.rocks/qenv": "^6.1.0", + "@push.rocks/smartnpm": "^2.0.4" }, "repository": { "type": "git", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bef88a8..50b9415 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,9 @@ importers: '@push.rocks/qenv': specifier: ^6.1.0 version: 6.1.0 + '@push.rocks/smartnpm': + specifier: ^2.0.4 + version: 2.0.4 devDependencies: '@git.zone/tsbuild': specifier: ^2.1.25 diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 9996100..06dcb4b 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@foss.global/codefeed', - version: '1.0.2', + version: '1.1.0', description: 'a module for creating feeds for code development' } diff --git a/ts/codefeed.plugins.ts b/ts/codefeed.plugins.ts index 8a8c585..1d25ce4 100644 --- a/ts/codefeed.plugins.ts +++ b/ts/codefeed.plugins.ts @@ -1,6 +1,8 @@ // @push.rocks import * as qenv from '@push.rocks/qenv' +import * as smartnpm from '@push.rocks/smartnpm' export { qenv, + smartnpm, } \ No newline at end of file diff --git a/ts/index.ts b/ts/index.ts index 6799384..e03d605 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -41,11 +41,13 @@ interface CommitResult { hash: string; commitMessage: string; tagged: boolean; + publishedOnNpm: boolean; } export class CodeFeed { private baseUrl: string; private token?: string; + private npmRegistry = new plugins.smartnpm.NpmRegistry(); constructor(baseUrl: string, token?: string) { this.baseUrl = baseUrl; @@ -160,6 +162,8 @@ export class CodeFeed { public async fetchAllCommitsFromInstance(): Promise { const repos = await this.fetchAllRepositories(); + const skippedRepos: string[] = []; + console.log(`Found ${repos.length} repositories`); let allCommits: CommitResult[] = []; for (const r of repos) { @@ -171,24 +175,59 @@ export class CodeFeed { const taggedCommitShas = await this.fetchTags(org, repo); const commits = await this.fetchRecentCommitsForRepo(org, repo); console.log(`${org}/${repo} -> Found ${commits.length} commits`); + const commitResults: CommitResult[] = []; + for (const c of commits) { + const commit: CommitResult = { + baseUrl: this.baseUrl, + org, + repo, + timestamp: c.commit.author.date, + hash: c.sha, + commitMessage: c.commit.message, + tagged: taggedCommitShas.has(c.sha), + publishedOnNpm: false, + } + commitResults.push(commit); + } - const formatted = commits.map((c): CommitResult => ({ - baseUrl: this.baseUrl, - org, - repo, - timestamp: c.commit.author.date, - hash: c.sha, - commitMessage: c.commit.message, - tagged: taggedCommitShas.has(c.sha) - })); + if (commitResults.length > 0) { + try { + const packageInfo = await this.npmRegistry.getPackageInfo(`@${org}/${repo}`); + for (const commit of commitResults.filter(c => c.tagged)) { + const correspondingVersion = packageInfo.allVersions.find(versionArg => { + return versionArg.version === commit.commitMessage.replace('\n', ''); + }); + if (correspondingVersion) { + commit.publishedOnNpm = true; + } + } + } catch (error: any) { + console.error(`Failed to fetch package info for ${org}/${repo}:`, error.message); + continue; + } + } - allCommits.push(...formatted); + allCommits.push(...commitResults); } catch (error: any) { + skippedRepos.push(`${org}/${repo}`); console.error(`Skipping repository ${org}/${repo} due to error:`, error.message); continue; } } + console.log(`Found ${allCommits.length} relevant commits`); + console.log(`Skipped ${skippedRepos.length} repositories due to errors`); + for (const s of skippedRepos) { + console.log(`Skipped ${s}`); + } + for (const c of allCommits) { + console.log(`______________________________________________________ + Commit ${c.hash} by ${c.org}/${c.repo} at ${c.timestamp} + ${c.commitMessage} + Published on npm: ${c.publishedOnNpm} + `); + } + return allCommits; } } \ No newline at end of file