diff --git a/src/blocks/blockAllContributors.test.ts b/src/blocks/blockAllContributors.test.ts index 6624e50cd..a4227ae62 100644 --- a/src/blocks/blockAllContributors.test.ts +++ b/src/blocks/blockAllContributors.test.ts @@ -90,132 +90,240 @@ describe("blockAllContributors", () => { `); }); - it("includes contributors when provided", () => { + it("runs add including existing owner contributions when they exist", () => { const creation = testBlock(blockAllContributors, { options: { ...optionsBase, contributors: [ { avatar_url: "https://avatars.githubusercontent.com/u/3335181?v=4", - contributions: [ - "bug", - "code", - "design", - "doc", - "ideas", - "infra", - "maintenance", - "review", - "test", - "tool", - ], + contributions: ["bug", "code", "design", "doc", "test", "tool"], login: "JoshuaKGoldberg", name: "Josh Goldberg", profile: "http://www.joshuakgoldberg.com", }, ], + owner: "JoshuaKGoldberg", }, }); expect(creation).toMatchInlineSnapshot(` - { - "addons": [ - { - "addons": { - "ignores": [ - "/.all-contributorsrc", - ], - }, - "block": [Function], - }, - { - "addons": { - "badges": [ - { - "alt": "👪 All Contributors: 1", - "comments": { - "after": " - - ", - "before": " - - ", - }, - "href": "#contributors", - "src": "https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-1-21bb42.svg", - }, - ], - "sections": [ - "## Contributors - - - - - - - - - - - -
Josh Goldberg
Josh Goldberg

🐛 💻 🎨 📖 🤔 🚇 🚧 👀 ⚠️ 🔧
- - - - - - ", - ], - }, - "block": [Function], - }, - { - "addons": { - "secrets": [ - { - "description": "a GitHub PAT with repo and workflow permissions", - "name": "ACCESS_TOKEN", - }, - ], - }, - "block": [Function], - }, - ], - "files": { - ".all-contributorsrc": "{"badgeTemplate":"\\t\\"👪\\" src=\\"https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-<%= contributors.length %>-21bb42.svg\\" />","contributors":[{"avatar_url":"https://avatars.githubusercontent.com/u/3335181?v=4","contributions":["bug","code","design","doc","ideas","infra","maintenance","review","test","tool"],"login":"JoshuaKGoldberg","name":"Josh Goldberg","profile":"http://www.joshuakgoldberg.com"}],"contributorsSortAlphabetically":true,"projectName":"test-repository","projectOwner":"test-owner"}", - ".github": { - "workflows": { - "contributors.yml": "jobs: - contributors: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - uses: ./.github/actions/prepare - - env: - GITHUB_TOKEN: \${{ secrets.ACCESS_TOKEN }} - uses: JoshuaKGoldberg/all-contributors-auto-action@v0.5.0 - - name: Contributors - - on: - push: - branches: - - main - ", - }, - }, - }, - "scripts": [ - { - "commands": [ - "pnpx all-contributors-cli add test-owner code,content,doc,ideas,infra,maintenance,projectManagement,tool", - ], - "phase": 3, - }, - ], - } - `); + { + "addons": [ + { + "addons": { + "ignores": [ + "/.all-contributorsrc", + ], + }, + "block": [Function], + }, + { + "addons": { + "badges": [ + { + "alt": "👪 All Contributors: 1", + "comments": { + "after": " + + ", + "before": " + + ", + }, + "href": "#contributors", + "src": "https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-1-21bb42.svg", + }, + ], + "sections": [ + "## Contributors + + + + + + + + + + + +
Josh Goldberg
Josh Goldberg

🐛 💻 🎨 📖 ⚠️ 🔧
+ + + + + + ", + ], + }, + "block": [Function], + }, + { + "addons": { + "secrets": [ + { + "description": "a GitHub PAT with repo and workflow permissions", + "name": "ACCESS_TOKEN", + }, + ], + }, + "block": [Function], + }, + ], + "files": { + ".all-contributorsrc": "{"badgeTemplate":"\\t\\"👪\\" src=\\"https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-<%= contributors.length %>-21bb42.svg\\" />","contributors":[{"avatar_url":"https://avatars.githubusercontent.com/u/3335181?v=4","contributions":["bug","code","design","doc","test","tool"],"login":"JoshuaKGoldberg","name":"Josh Goldberg","profile":"http://www.joshuakgoldberg.com"}],"contributorsSortAlphabetically":true,"projectName":"test-repository","projectOwner":"JoshuaKGoldberg"}", + ".github": { + "workflows": { + "contributors.yml": "jobs: + contributors: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: ./.github/actions/prepare + - env: + GITHUB_TOKEN: \${{ secrets.ACCESS_TOKEN }} + uses: JoshuaKGoldberg/all-contributors-auto-action@v0.5.0 + + name: Contributors + + on: + push: + branches: + - main + ", + }, + }, + }, + "scripts": [ + { + "commands": [ + "pnpx all-contributors-cli add JoshuaKGoldberg bug,code,design,doc,test,tool,content,ideas,infra,maintenance,projectManagement", + ], + "phase": 3, + }, + ], + } + `); + }); + + it("adds full owner contributions when no existing contributor is the owner", () => { + const creation = testBlock(blockAllContributors, { + options: { + ...optionsBase, + contributors: [ + { + avatar_url: "https://avatars.githubusercontent.com/u/3335181?v=4", + contributions: ["bug", "code", "design", "doc", "test", "tool"], + login: "other", + name: "Other", + profile: "http://www.example.com", + }, + ], + }, + }); + + expect(creation).toMatchInlineSnapshot(` + { + "addons": [ + { + "addons": { + "ignores": [ + "/.all-contributorsrc", + ], + }, + "block": [Function], + }, + { + "addons": { + "badges": [ + { + "alt": "👪 All Contributors: 1", + "comments": { + "after": " + + ", + "before": " + + ", + }, + "href": "#contributors", + "src": "https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-1-21bb42.svg", + }, + ], + "sections": [ + "## Contributors + + + + + + + + + + + +
Other
Other

🐛 💻 🎨 📖 ⚠️ 🔧
+ + + + + + ", + ], + }, + "block": [Function], + }, + { + "addons": { + "secrets": [ + { + "description": "a GitHub PAT with repo and workflow permissions", + "name": "ACCESS_TOKEN", + }, + ], + }, + "block": [Function], + }, + ], + "files": { + ".all-contributorsrc": "{"badgeTemplate":"\\t\\"👪\\" src=\\"https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-<%= contributors.length %>-21bb42.svg\\" />","contributors":[{"avatar_url":"https://avatars.githubusercontent.com/u/3335181?v=4","contributions":["bug","code","design","doc","test","tool"],"login":"other","name":"Other","profile":"http://www.example.com"}],"contributorsSortAlphabetically":true,"projectName":"test-repository","projectOwner":"test-owner"}", + ".github": { + "workflows": { + "contributors.yml": "jobs: + contributors: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: ./.github/actions/prepare + - env: + GITHUB_TOKEN: \${{ secrets.ACCESS_TOKEN }} + uses: JoshuaKGoldberg/all-contributors-auto-action@v0.5.0 + + name: Contributors + + on: + push: + branches: + - main + ", + }, + }, + }, + "scripts": [ + { + "commands": [ + "pnpx all-contributors-cli add test-owner code,content,doc,ideas,infra,maintenance,projectManagement,tool", + ], + "phase": 3, + }, + ], + } + `); }); }); diff --git a/src/blocks/blockAllContributors.ts b/src/blocks/blockAllContributors.ts index 91f110840..0f5cf5371 100644 --- a/src/blocks/blockAllContributors.ts +++ b/src/blocks/blockAllContributors.ts @@ -1,7 +1,7 @@ import _ from "lodash"; import { base } from "../base.js"; -import { ownerContributions } from "../data/contributions.js"; +import { startingOwnerContributions } from "../data/contributions.js"; import { Contributor } from "../schemas.js"; import { resolveUses } from "./actions/resolveUses.js"; import { blockPrettier } from "./blockPrettier.js"; @@ -16,6 +16,20 @@ export const blockAllContributors = base.createBlock({ }, produce({ options }) { const contributions = options.contributors?.length; + const ownerContributions = Array.from( + new Set( + [ + options.contributors?.find( + (contributor) => + contributor.login.toLowerCase() === options.owner.toLowerCase(), + )?.contributions, + startingOwnerContributions, + ] + .filter(Boolean) + .flat(), + ), + ); + return { addons: [ blockPrettier({ diff --git a/src/data/contributions.ts b/src/data/contributions.ts index 8d4a13553..0313c9026 100644 --- a/src/data/contributions.ts +++ b/src/data/contributions.ts @@ -1,4 +1,4 @@ -export const ownerContributions = [ +export const startingOwnerContributions = [ "code", "content", "doc", diff --git a/src/options/readAllContributors.test.ts b/src/options/readAllContributors.test.ts index aac45a82b..beff9df80 100644 --- a/src/options/readAllContributors.test.ts +++ b/src/options/readAllContributors.test.ts @@ -1,7 +1,7 @@ import { createMockSystems } from "bingo-testers"; import { describe, expect, it, vi } from "vitest"; -import { ownerContributions } from "../data/contributions.js"; +import { startingOwnerContributions } from "../data/contributions.js"; import { readAllContributors } from "./readAllContributors.js"; const mockInputFromFileJSON = vi.fn(); @@ -56,7 +56,7 @@ describe(readAllContributors, () => { expect(actual).toEqual([ { avatar_url: "avatar_url", - contributions: ownerContributions, + contributions: startingOwnerContributions, login: "login", name: "name", profile: "blog", diff --git a/src/options/readAllContributors.ts b/src/options/readAllContributors.ts index 6a6d9eb29..62c219d67 100644 --- a/src/options/readAllContributors.ts +++ b/src/options/readAllContributors.ts @@ -1,7 +1,7 @@ import { TakeInput } from "bingo"; import { inputFromFileJSON } from "input-from-file-json"; -import { ownerContributions } from "../data/contributions.js"; +import { startingOwnerContributions } from "../data/contributions.js"; import { inputFromOctokit } from "../inputs/inputFromOctokit.js"; import { AllContributorsData } from "../types.js"; @@ -24,7 +24,7 @@ export async function readAllContributors(take: TakeInput) { user && [ { avatar_url: user.avatar_url, - contributions: ownerContributions, + contributions: startingOwnerContributions, login: user.login, name: user.name, profile: user.blog,