all-contributors-for-repository
Advanced tools
Comparing version 0.0.7 to 0.0.8
import { Octokit } from "octokit"; | ||
import { RequestDefaults } from "./api.js"; | ||
export type RepoEvent = Awaited<ReturnType<typeof collectEvents>>[number]; | ||
export declare function collectEvents(defaults: RequestDefaults, octokit: Octokit): Promise<{ | ||
@@ -4,0 +5,0 @@ id: string; |
@@ -0,5 +1,4 @@ | ||
import { ContributorsContributions } from "../ContributorsCollection.js"; | ||
import { AllContributorsForRepositoryOptions } from "../options.js"; | ||
export declare function collect(options: AllContributorsForRepositoryOptions): Promise<{ | ||
[k: string]: string[]; | ||
}>; | ||
export declare function collect(options: AllContributorsForRepositoryOptions): Promise<ContributorsContributions>; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { ContributorsCollection } from "../ContributorsCollection.js"; | ||
import { ContributorsCollection, } from "../ContributorsCollection.js"; | ||
import { createOctokit } from "./api.js"; | ||
@@ -7,2 +7,3 @@ import { collectAcceptedIssues } from "./collectAcceptedIssues.js"; | ||
import { collectMergedPulls } from "./collectMergedPulls.js"; | ||
import { eventIsPullRequestReviewEvent } from "./eventIsPullRequestReviewEvent.js"; | ||
import { parseMergedPullAuthors } from "./parsing/parseMergedPullAuthors.js"; | ||
@@ -31,7 +32,7 @@ import { parseMergedPullType } from "./parsing/parseMergedPullType.js"; | ||
if (labels.some((label) => label === labelType)) { | ||
contributors.add(acceptedIssue.user?.login, contribution); | ||
contributors.add(acceptedIssue.user?.login, acceptedIssue.number, contribution); | ||
} | ||
} | ||
} | ||
// 💻 `code`: all PR authors and co-authors | ||
// 💻 `code` & others: all PR authors and co-authors | ||
for (const mergedPull of mergedPulls) { | ||
@@ -41,3 +42,3 @@ const authors = parseMergedPullAuthors(mergedPull); | ||
for (const author of authors) { | ||
contributors.add(author, type); | ||
contributors.add(author, mergedPull.number, type); | ||
} | ||
@@ -48,4 +49,4 @@ } | ||
for (const event of issueEvents) { | ||
if (event.actor) { | ||
contributors.add(event.actor.login, "maintenance"); | ||
if (event.actor && event.issue) { | ||
contributors.add(event.actor.login, event.issue.number, "maintenance"); | ||
maintainers.add(event.actor.login); | ||
@@ -57,5 +58,5 @@ } | ||
for (const event of events) { | ||
if (event.type === "PullRequestReviewEvent" && | ||
if (eventIsPullRequestReviewEvent(event) && | ||
maintainers.has(event.actor.login)) { | ||
contributors.add(event.actor.login, "review"); | ||
contributors.add(event.actor.login, event.issue.number, "review"); | ||
} | ||
@@ -62,0 +63,0 @@ } |
export declare class Contributor { | ||
readonly contributions: Record<string, number[]>; | ||
add(id: number, type: string): void; | ||
readonly contributions: Record<string, Set<number>>; | ||
add(number: number, type: string): void; | ||
} | ||
//# sourceMappingURL=Contributor.d.ts.map |
@@ -5,6 +5,6 @@ export class Contributor { | ||
} | ||
add(id, type) { | ||
(this.contributions[type] ??= []).push(id); | ||
add(number, type) { | ||
(this.contributions[type] ??= new Set()).add(number); | ||
} | ||
} | ||
//# sourceMappingURL=Contributor.js.map |
@@ -0,9 +1,15 @@ | ||
/** | ||
* For a set of logins, the contributions under those users. | ||
*/ | ||
export type ContributorsContributions = Record<string, ContributorContributions>; | ||
/** | ||
* For each contribution under a login, the issue/PR numbers that count as that type. | ||
*/ | ||
export type ContributorContributions = Record<string, number[]>; | ||
export declare class ContributorsCollection { | ||
#private; | ||
constructor(ignoredLogins: Set<string>); | ||
add(login: string | undefined, type: string): void; | ||
collect(): { | ||
[k: string]: string[]; | ||
}; | ||
add(login: string | undefined, number: number, type: string): void; | ||
collect(): ContributorsContributions; | ||
} | ||
//# sourceMappingURL=ContributorsCollection.d.ts.map |
@@ -13,2 +13,3 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
var _ContributorsCollection_contributors, _ContributorsCollection_ignoredLogins; | ||
import { Contributor } from "./Contributor.js"; | ||
export class ContributorsCollection { | ||
@@ -20,5 +21,5 @@ constructor(ignoredLogins) { | ||
} | ||
add(login, type) { | ||
add(login, number, type) { | ||
if (login && !__classPrivateFieldGet(this, _ContributorsCollection_ignoredLogins, "f").has(login)) { | ||
(__classPrivateFieldGet(this, _ContributorsCollection_contributors, "f")[login.toLowerCase()] ??= new Set()).add(type); | ||
(__classPrivateFieldGet(this, _ContributorsCollection_contributors, "f")[login.toLowerCase()] ??= new Contributor()).add(number, type); | ||
} | ||
@@ -28,3 +29,9 @@ } | ||
return Object.fromEntries(Object.entries(__classPrivateFieldGet(this, _ContributorsCollection_contributors, "f")) | ||
.map(([contributor, types]) => [contributor, Array.from(types).sort()]) | ||
.map(([login, contributor]) => [ | ||
login, | ||
Object.fromEntries(Object.entries(contributor.contributions).map(([type, numbers]) => [ | ||
type, | ||
Array.from(numbers).sort((a, b) => a - b), | ||
])), | ||
]) | ||
.sort(([a], [b]) => a.localeCompare(b))); | ||
@@ -31,0 +38,0 @@ } |
@@ -11,17 +11,17 @@ import { describe, expect, it } from "vitest"; | ||
const contributors = new ContributorsCollection(new Set()); | ||
contributors.add("abc", "bug"); | ||
contributors.add("abc", 0, "bug"); | ||
const actual = contributors.collect(); | ||
expect(actual).toEqual({ abc: ["bug"] }); | ||
expect(actual).toEqual({ abc: { bug: [0] } }); | ||
}); | ||
it("adds sorted contributions for logins when they are added in non-alphabetical order ", () => { | ||
const contributors = new ContributorsCollection(new Set()); | ||
contributors.add("def", "tool"); | ||
contributors.add("abc", "tool"); | ||
contributors.add("abc", "bug"); | ||
contributors.add("abc", "code"); | ||
contributors.add("def", "code"); | ||
contributors.add("def", 1, "tool"); | ||
contributors.add("abc", 2, "tool"); | ||
contributors.add("abc", 3, "bug"); | ||
contributors.add("abc", 4, "code"); | ||
contributors.add("def", 5, "code"); | ||
const actual = contributors.collect(); | ||
expect(actual).toEqual({ | ||
abc: ["bug", "code", "tool"], | ||
def: ["code", "tool"], | ||
abc: { bug: [3], code: [4], tool: [2] }, | ||
def: { code: [5], tool: [1] }, | ||
}); | ||
@@ -31,7 +31,7 @@ }); | ||
const contributors = new ContributorsCollection(new Set(["ignored"])); | ||
contributors.add("abc", "bug"); | ||
contributors.add("ignored", "code"); | ||
contributors.add("abc", 1, "bug"); | ||
contributors.add("ignored", 2, "code"); | ||
const actual = contributors.collect(); | ||
expect(actual).toEqual({ | ||
abc: ["bug"], | ||
abc: { bug: [1] }, | ||
}); | ||
@@ -38,0 +38,0 @@ }); |
@@ -1,5 +0,3 @@ | ||
import { RawAllContributorsForRepositoryOptions } from "./options.js"; | ||
export declare function createAllContributorsForRepository(rawOptions: RawAllContributorsForRepositoryOptions): Promise<{ | ||
[k: string]: string[]; | ||
}>; | ||
export { ContributorContributions, ContributorsContributions, } from "./ContributorsCollection.js"; | ||
export { createAllContributorsForRepository } from "./createAllContributorsForRepository.js"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,7 +0,2 @@ | ||
import { collect } from "./collect/index.js"; | ||
import { fillInOptions, } from "./options.js"; | ||
export async function createAllContributorsForRepository(rawOptions) { | ||
const options = fillInOptions(rawOptions); | ||
return await collect(options); | ||
} | ||
export { createAllContributorsForRepository } from "./createAllContributorsForRepository.js"; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "all-contributors-for-repository", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Generates an allcontributors list for an existing repository.", | ||
@@ -59,3 +59,3 @@ "repository": { | ||
"eslint-plugin-typescript-sort-keys": "^2.1.0", | ||
"eslint-plugin-vitest": "^0.1.0", | ||
"eslint-plugin-vitest": "^0.2.0", | ||
"eslint-plugin-yml": "^1.5.0", | ||
@@ -79,3 +79,3 @@ "husky": "^8.0.3", | ||
}, | ||
"packageManager": "pnpm@8.3.1", | ||
"packageManager": "pnpm@8.4.0", | ||
"engines": { | ||
@@ -82,0 +82,0 @@ "node": ">=18" |
@@ -81,3 +81,4 @@ <h1 align="center">All Contributors For Repository</h1> | ||
> for (const [contributor, contributions] of Object.entries(contributors)) { | ||
> await $`npx all-contributors add ${contributor} ${contributions.join(",")}`; | ||
> const contributionTypes = Object.keys(contributions).join(","); | ||
> await $`npx all-contributors add ${contributor} ${contributionTypes}`; | ||
> } | ||
@@ -84,0 +85,0 @@ > ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
444778
169
9802
114
0