feat(core): Add tracking of commits published on npm
This commit is contained in:
parent
3392174169
commit
19ecb3f9a5
@ -1,5 +1,11 @@
|
|||||||
# Changelog
|
# 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)
|
## 2024-12-13 - 1.0.2 - fix(core)
|
||||||
Improve error handling in fetchRecentCommitsForRepo method
|
Improve error handling in fetchRecentCommitsForRepo method
|
||||||
|
|
||||||
|
@ -22,7 +22,8 @@
|
|||||||
"@types/node": "^20.8.7"
|
"@types/node": "^20.8.7"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@push.rocks/qenv": "^6.1.0"
|
"@push.rocks/qenv": "^6.1.0",
|
||||||
|
"@push.rocks/smartnpm": "^2.0.4"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@ -11,6 +11,9 @@ importers:
|
|||||||
'@push.rocks/qenv':
|
'@push.rocks/qenv':
|
||||||
specifier: ^6.1.0
|
specifier: ^6.1.0
|
||||||
version: 6.1.0
|
version: 6.1.0
|
||||||
|
'@push.rocks/smartnpm':
|
||||||
|
specifier: ^2.0.4
|
||||||
|
version: 2.0.4
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@git.zone/tsbuild':
|
'@git.zone/tsbuild':
|
||||||
specifier: ^2.1.25
|
specifier: ^2.1.25
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@foss.global/codefeed',
|
name: '@foss.global/codefeed',
|
||||||
version: '1.0.2',
|
version: '1.1.0',
|
||||||
description: 'a module for creating feeds for code development'
|
description: 'a module for creating feeds for code development'
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
// @push.rocks
|
// @push.rocks
|
||||||
import * as qenv from '@push.rocks/qenv'
|
import * as qenv from '@push.rocks/qenv'
|
||||||
|
import * as smartnpm from '@push.rocks/smartnpm'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
qenv,
|
qenv,
|
||||||
|
smartnpm,
|
||||||
}
|
}
|
49
ts/index.ts
49
ts/index.ts
@ -41,11 +41,13 @@ interface CommitResult {
|
|||||||
hash: string;
|
hash: string;
|
||||||
commitMessage: string;
|
commitMessage: string;
|
||||||
tagged: boolean;
|
tagged: boolean;
|
||||||
|
publishedOnNpm: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CodeFeed {
|
export class CodeFeed {
|
||||||
private baseUrl: string;
|
private baseUrl: string;
|
||||||
private token?: string;
|
private token?: string;
|
||||||
|
private npmRegistry = new plugins.smartnpm.NpmRegistry();
|
||||||
|
|
||||||
constructor(baseUrl: string, token?: string) {
|
constructor(baseUrl: string, token?: string) {
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
@ -160,6 +162,8 @@ export class CodeFeed {
|
|||||||
|
|
||||||
public async fetchAllCommitsFromInstance(): Promise<CommitResult[]> {
|
public async fetchAllCommitsFromInstance(): Promise<CommitResult[]> {
|
||||||
const repos = await this.fetchAllRepositories();
|
const repos = await this.fetchAllRepositories();
|
||||||
|
const skippedRepos: string[] = [];
|
||||||
|
console.log(`Found ${repos.length} repositories`);
|
||||||
let allCommits: CommitResult[] = [];
|
let allCommits: CommitResult[] = [];
|
||||||
|
|
||||||
for (const r of repos) {
|
for (const r of repos) {
|
||||||
@ -171,24 +175,59 @@ export class CodeFeed {
|
|||||||
const taggedCommitShas = await this.fetchTags(org, repo);
|
const taggedCommitShas = await this.fetchTags(org, repo);
|
||||||
const commits = await this.fetchRecentCommitsForRepo(org, repo);
|
const commits = await this.fetchRecentCommitsForRepo(org, repo);
|
||||||
console.log(`${org}/${repo} -> Found ${commits.length} commits`);
|
console.log(`${org}/${repo} -> Found ${commits.length} commits`);
|
||||||
|
const commitResults: CommitResult[] = [];
|
||||||
const formatted = commits.map((c): CommitResult => ({
|
for (const c of commits) {
|
||||||
|
const commit: CommitResult = {
|
||||||
baseUrl: this.baseUrl,
|
baseUrl: this.baseUrl,
|
||||||
org,
|
org,
|
||||||
repo,
|
repo,
|
||||||
timestamp: c.commit.author.date,
|
timestamp: c.commit.author.date,
|
||||||
hash: c.sha,
|
hash: c.sha,
|
||||||
commitMessage: c.commit.message,
|
commitMessage: c.commit.message,
|
||||||
tagged: taggedCommitShas.has(c.sha)
|
tagged: taggedCommitShas.has(c.sha),
|
||||||
}));
|
publishedOnNpm: false,
|
||||||
|
}
|
||||||
|
commitResults.push(commit);
|
||||||
|
}
|
||||||
|
|
||||||
allCommits.push(...formatted);
|
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) {
|
} catch (error: any) {
|
||||||
|
console.error(`Failed to fetch package info for ${org}/${repo}:`, error.message);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allCommits.push(...commitResults);
|
||||||
|
} catch (error: any) {
|
||||||
|
skippedRepos.push(`${org}/${repo}`);
|
||||||
console.error(`Skipping repository ${org}/${repo} due to error:`, error.message);
|
console.error(`Skipping repository ${org}/${repo} due to error:`, error.message);
|
||||||
continue;
|
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;
|
return allCommits;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user