Skip to content

Commit 076e02a

Browse files
authored
feat: add running user to all-contributors (#407)
<!-- 👋 Hi, thanks for sending a PR to template-typescript-node-package! 💖. Please fill out all fields below and make sure each item is true and [x] checked. Otherwise we may not be able to review your PR. --> ## PR Checklist - [x] Addresses an existing open issue: fixes #156 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/template-typescript-node-package/blob/main/.github/CONTRIBUTING.md) were taken ## Overview I added some logic to add the running user to the `all-contributors` list (according to the authenticated GitHub CLI account). At first, I tried only to use the owner variable that the user prompted, but it failed the tests, where a fabricated owner name was provided; if you prefer to only use the provided owner name without reaching out to gh CLI, we might need to adjust the tests a little bit.
1 parent 2ad0f2a commit 076e02a

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

script/setup-test-e2e.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { promises as fs } from "fs";
55
import { globby } from "globby";
66

77
const description = "New Description Test";
8-
const owner = "NewOwnerTest";
8+
const owner = "RNR1";
99
const title = "New Title Test";
1010
const repository = "new-repository-test";
1111

script/setup.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,29 @@ try {
169169

170170
await withSpinner(
171171
async () => {
172+
let user;
173+
try {
174+
user = JSON.parse((await $`gh api user`).stdout).login;
175+
} catch (err) {
176+
console.warn(
177+
chalk.gray(
178+
`Couldn't authenticate GitHub user, falling back to the provided owner name '${owner}'`
179+
)
180+
);
181+
user = owner;
182+
}
183+
184+
await $`all-contributors add ${user} ${[
185+
"code",
186+
"content",
187+
"doc",
188+
"ideas",
189+
"infra",
190+
"maintenance",
191+
"projectManagement",
192+
"tool",
193+
].join(",")}`;
194+
172195
const existingContributors = await readFileAsJSON(
173196
"./.all-contributorsrc"
174197
);
@@ -178,14 +201,13 @@ try {
178201
prettier.format(
179202
JSON.stringify({
180203
...existingContributors,
181-
contributors: [
182-
{
183-
...existingContributors.contributors.find(
184-
({ login }) => login === "JoshuaKGoldberg"
185-
),
186-
contributions: ["tool"],
187-
},
188-
],
204+
contributors: existingContributors.contributors
205+
.filter(({ login }) => [user, "JoshuaKGoldberg"].includes(login))
206+
.map((contributor) =>
207+
contributor.login === "JoshuaKGoldberg"
208+
? { ...contributor, contributions: ["tool"] }
209+
: contributor
210+
),
189211
}),
190212
{ parser: "json" }
191213
)

0 commit comments

Comments
 (0)