feat(core): Add tracking of commits published on npm
This commit is contained in:
59
ts/index.ts
59
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<CommitResult[]> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user