Skip to content

Commit c9afe96

Browse files
fix: preserve existing owner contributions during transition (#2065)
## PR Checklist - [x] Addresses an existing open issue: fixes #2063 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview To work around all-contributors/cli#371, any existing owner contributions are merged with the default starters. 🎁
1 parent 86ea767 commit c9afe96

File tree

5 files changed

+240
-118
lines changed

5 files changed

+240
-118
lines changed

src/blocks/blockAllContributors.test.ts

+220-112
Original file line numberDiff line numberDiff line change
@@ -90,132 +90,240 @@ describe("blockAllContributors", () => {
9090
`);
9191
});
9292

93-
it("includes contributors when provided", () => {
93+
it("runs add including existing owner contributions when they exist", () => {
9494
const creation = testBlock(blockAllContributors, {
9595
options: {
9696
...optionsBase,
9797
contributors: [
9898
{
9999
avatar_url: "https://avatars.githubusercontent.com/u/3335181?v=4",
100-
contributions: [
101-
"bug",
102-
"code",
103-
"design",
104-
"doc",
105-
"ideas",
106-
"infra",
107-
"maintenance",
108-
"review",
109-
"test",
110-
"tool",
111-
],
100+
contributions: ["bug", "code", "design", "doc", "test", "tool"],
112101
login: "JoshuaKGoldberg",
113102
name: "Josh Goldberg",
114103
profile: "http://www.joshuakgoldberg.com",
115104
},
116105
],
106+
owner: "JoshuaKGoldberg",
117107
},
118108
});
119109

120110
expect(creation).toMatchInlineSnapshot(`
121-
{
122-
"addons": [
123-
{
124-
"addons": {
125-
"ignores": [
126-
"/.all-contributorsrc",
127-
],
128-
},
129-
"block": [Function],
130-
},
131-
{
132-
"addons": {
133-
"badges": [
134-
{
135-
"alt": "👪 All Contributors: 1",
136-
"comments": {
137-
"after": "
138-
<!-- ALL-CONTRIBUTORS-BADGE:END -->
139-
<!-- prettier-ignore-end -->",
140-
"before": "<!-- prettier-ignore-start -->
141-
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
142-
",
143-
},
144-
"href": "#contributors",
145-
"src": "https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-1-21bb42.svg",
146-
},
147-
],
148-
"sections": [
149-
"## Contributors
150-
151-
<!-- spellchecker: disable -->
152-
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
153-
<!-- prettier-ignore-start -->
154-
<!-- markdownlint-disable -->
155-
<table>
156-
<tbody>
157-
<tr>
158-
<td align="center" valign="top" width="14.28%"><a href="http://www.joshuakgoldberg.com"><img src="https://avatars.githubusercontent.com/u/3335181?v=4?s=100" width="100px;" alt="Josh Goldberg"/><br /><sub><b>Josh Goldberg</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=author%3AJoshuaKGoldberg" title="Bug reports">🐛</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=JoshuaKGoldberg" title="Code">💻</a> <a href="#design-JoshuaKGoldberg" title="Design">🎨</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=JoshuaKGoldberg" title="Documentation">📖</a> <a href="#ideas-JoshuaKGoldberg" title="Ideas, Planning, & Feedback">🤔</a> <a href="#infra-JoshuaKGoldberg" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-JoshuaKGoldberg" title="Maintenance">🚧</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/pulls?q=is%3Apr+reviewed-by%3AJoshuaKGoldberg" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=JoshuaKGoldberg" title="Tests">⚠️</a> <a href="#tool-JoshuaKGoldberg" title="Tools">🔧</a></td>
159-
</tr>
160-
</tbody>
161-
</table>
162-
163-
<!-- markdownlint-restore -->
164-
<!-- prettier-ignore-end -->
165-
166-
<!-- ALL-CONTRIBUTORS-LIST:END -->
167-
<!-- spellchecker: enable -->",
168-
],
169-
},
170-
"block": [Function],
171-
},
172-
{
173-
"addons": {
174-
"secrets": [
175-
{
176-
"description": "a GitHub PAT with repo and workflow permissions",
177-
"name": "ACCESS_TOKEN",
178-
},
179-
],
180-
},
181-
"block": [Function],
182-
},
183-
],
184-
"files": {
185-
".all-contributorsrc": "{"badgeTemplate":"\\t<a href=\\"#contributors\\" target=\\"_blank\\"><img alt=\\"👪 All Contributors: <%= contributors.length %>\\" src=\\"https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-<%= contributors.length %>-21bb42.svg\\" /></a>","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"}",
186-
".github": {
187-
"workflows": {
188-
"contributors.yml": "jobs:
189-
contributors:
190-
runs-on: ubuntu-latest
191-
steps:
192-
- uses: actions/checkout@v4
193-
with:
194-
fetch-depth: 0
195-
- uses: ./.github/actions/prepare
196-
- env:
197-
GITHUB_TOKEN: \${{ secrets.ACCESS_TOKEN }}
198-
uses: JoshuaKGoldberg/[email protected]
199-
200-
name: Contributors
201-
202-
on:
203-
push:
204-
branches:
205-
- main
206-
",
207-
},
208-
},
209-
},
210-
"scripts": [
211-
{
212-
"commands": [
213-
"pnpx all-contributors-cli add test-owner code,content,doc,ideas,infra,maintenance,projectManagement,tool",
214-
],
215-
"phase": 3,
216-
},
217-
],
218-
}
219-
`);
111+
{
112+
"addons": [
113+
{
114+
"addons": {
115+
"ignores": [
116+
"/.all-contributorsrc",
117+
],
118+
},
119+
"block": [Function],
120+
},
121+
{
122+
"addons": {
123+
"badges": [
124+
{
125+
"alt": "👪 All Contributors: 1",
126+
"comments": {
127+
"after": "
128+
<!-- ALL-CONTRIBUTORS-BADGE:END -->
129+
<!-- prettier-ignore-end -->",
130+
"before": "<!-- prettier-ignore-start -->
131+
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
132+
",
133+
},
134+
"href": "#contributors",
135+
"src": "https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-1-21bb42.svg",
136+
},
137+
],
138+
"sections": [
139+
"## Contributors
140+
141+
<!-- spellchecker: disable -->
142+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
143+
<!-- prettier-ignore-start -->
144+
<!-- markdownlint-disable -->
145+
<table>
146+
<tbody>
147+
<tr>
148+
<td align="center" valign="top" width="14.28%"><a href="http://www.joshuakgoldberg.com"><img src="https://avatars.githubusercontent.com/u/3335181?v=4?s=100" width="100px;" alt="Josh Goldberg"/><br /><sub><b>Josh Goldberg</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=author%3AJoshuaKGoldberg" title="Bug reports">🐛</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=JoshuaKGoldberg" title="Code">💻</a> <a href="#design-JoshuaKGoldberg" title="Design">🎨</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=JoshuaKGoldberg" title="Documentation">📖</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=JoshuaKGoldberg" title="Tests">⚠️</a> <a href="#tool-JoshuaKGoldberg" title="Tools">🔧</a></td>
149+
</tr>
150+
</tbody>
151+
</table>
152+
153+
<!-- markdownlint-restore -->
154+
<!-- prettier-ignore-end -->
155+
156+
<!-- ALL-CONTRIBUTORS-LIST:END -->
157+
<!-- spellchecker: enable -->",
158+
],
159+
},
160+
"block": [Function],
161+
},
162+
{
163+
"addons": {
164+
"secrets": [
165+
{
166+
"description": "a GitHub PAT with repo and workflow permissions",
167+
"name": "ACCESS_TOKEN",
168+
},
169+
],
170+
},
171+
"block": [Function],
172+
},
173+
],
174+
"files": {
175+
".all-contributorsrc": "{"badgeTemplate":"\\t<a href=\\"#contributors\\" target=\\"_blank\\"><img alt=\\"👪 All Contributors: <%= contributors.length %>\\" src=\\"https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-<%= contributors.length %>-21bb42.svg\\" /></a>","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"}",
176+
".github": {
177+
"workflows": {
178+
"contributors.yml": "jobs:
179+
contributors:
180+
runs-on: ubuntu-latest
181+
steps:
182+
- uses: actions/checkout@v4
183+
with:
184+
fetch-depth: 0
185+
- uses: ./.github/actions/prepare
186+
- env:
187+
GITHUB_TOKEN: \${{ secrets.ACCESS_TOKEN }}
188+
uses: JoshuaKGoldberg/[email protected]
189+
190+
name: Contributors
191+
192+
on:
193+
push:
194+
branches:
195+
- main
196+
",
197+
},
198+
},
199+
},
200+
"scripts": [
201+
{
202+
"commands": [
203+
"pnpx all-contributors-cli add JoshuaKGoldberg bug,code,design,doc,test,tool,content,ideas,infra,maintenance,projectManagement",
204+
],
205+
"phase": 3,
206+
},
207+
],
208+
}
209+
`);
210+
});
211+
212+
it("adds full owner contributions when no existing contributor is the owner", () => {
213+
const creation = testBlock(blockAllContributors, {
214+
options: {
215+
...optionsBase,
216+
contributors: [
217+
{
218+
avatar_url: "https://avatars.githubusercontent.com/u/3335181?v=4",
219+
contributions: ["bug", "code", "design", "doc", "test", "tool"],
220+
login: "other",
221+
name: "Other",
222+
profile: "http://www.example.com",
223+
},
224+
],
225+
},
226+
});
227+
228+
expect(creation).toMatchInlineSnapshot(`
229+
{
230+
"addons": [
231+
{
232+
"addons": {
233+
"ignores": [
234+
"/.all-contributorsrc",
235+
],
236+
},
237+
"block": [Function],
238+
},
239+
{
240+
"addons": {
241+
"badges": [
242+
{
243+
"alt": "👪 All Contributors: 1",
244+
"comments": {
245+
"after": "
246+
<!-- ALL-CONTRIBUTORS-BADGE:END -->
247+
<!-- prettier-ignore-end -->",
248+
"before": "<!-- prettier-ignore-start -->
249+
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
250+
",
251+
},
252+
"href": "#contributors",
253+
"src": "https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-1-21bb42.svg",
254+
},
255+
],
256+
"sections": [
257+
"## Contributors
258+
259+
<!-- spellchecker: disable -->
260+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
261+
<!-- prettier-ignore-start -->
262+
<!-- markdownlint-disable -->
263+
<table>
264+
<tbody>
265+
<tr>
266+
<td align="center" valign="top" width="14.28%"><a href="http://www.example.com"><img src="https://avatars.githubusercontent.com/u/3335181?v=4?s=100" width="100px;" alt="Other"/><br /><sub><b>Other</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=author%3Aother" title="Bug reports">🐛</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=other" title="Code">💻</a> <a href="#design-other" title="Design">🎨</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=other" title="Documentation">📖</a> <a href="https://github.com/JoshuaKGoldberg/create-typescript-app/commits?author=other" title="Tests">⚠️</a> <a href="#tool-other" title="Tools">🔧</a></td>
267+
</tr>
268+
</tbody>
269+
</table>
270+
271+
<!-- markdownlint-restore -->
272+
<!-- prettier-ignore-end -->
273+
274+
<!-- ALL-CONTRIBUTORS-LIST:END -->
275+
<!-- spellchecker: enable -->",
276+
],
277+
},
278+
"block": [Function],
279+
},
280+
{
281+
"addons": {
282+
"secrets": [
283+
{
284+
"description": "a GitHub PAT with repo and workflow permissions",
285+
"name": "ACCESS_TOKEN",
286+
},
287+
],
288+
},
289+
"block": [Function],
290+
},
291+
],
292+
"files": {
293+
".all-contributorsrc": "{"badgeTemplate":"\\t<a href=\\"#contributors\\" target=\\"_blank\\"><img alt=\\"👪 All Contributors: <%= contributors.length %>\\" src=\\"https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-<%= contributors.length %>-21bb42.svg\\" /></a>","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"}",
294+
".github": {
295+
"workflows": {
296+
"contributors.yml": "jobs:
297+
contributors:
298+
runs-on: ubuntu-latest
299+
steps:
300+
- uses: actions/checkout@v4
301+
with:
302+
fetch-depth: 0
303+
- uses: ./.github/actions/prepare
304+
- env:
305+
GITHUB_TOKEN: \${{ secrets.ACCESS_TOKEN }}
306+
uses: JoshuaKGoldberg/[email protected]
307+
308+
name: Contributors
309+
310+
on:
311+
push:
312+
branches:
313+
- main
314+
",
315+
},
316+
},
317+
},
318+
"scripts": [
319+
{
320+
"commands": [
321+
"pnpx all-contributors-cli add test-owner code,content,doc,ideas,infra,maintenance,projectManagement,tool",
322+
],
323+
"phase": 3,
324+
},
325+
],
326+
}
327+
`);
220328
});
221329
});

src/blocks/blockAllContributors.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import _ from "lodash";
22

33
import { base } from "../base.js";
4-
import { ownerContributions } from "../data/contributions.js";
4+
import { startingOwnerContributions } from "../data/contributions.js";
55
import { Contributor } from "../schemas.js";
66
import { resolveUses } from "./actions/resolveUses.js";
77
import { blockPrettier } from "./blockPrettier.js";
@@ -16,6 +16,20 @@ export const blockAllContributors = base.createBlock({
1616
},
1717
produce({ options }) {
1818
const contributions = options.contributors?.length;
19+
const ownerContributions = Array.from(
20+
new Set(
21+
[
22+
options.contributors?.find(
23+
(contributor) =>
24+
contributor.login.toLowerCase() === options.owner.toLowerCase(),
25+
)?.contributions,
26+
startingOwnerContributions,
27+
]
28+
.filter(Boolean)
29+
.flat(),
30+
),
31+
);
32+
1933
return {
2034
addons: [
2135
blockPrettier({

src/data/contributions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const ownerContributions = [
1+
export const startingOwnerContributions = [
22
"code",
33
"content",
44
"doc",

0 commit comments

Comments
 (0)