Skip to content

Commit 0d5ac12

Browse files
committed
fix: add current actor to contributors
1 parent 8bea44c commit 0d5ac12

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/update.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,23 @@ const getGitHubContributors = async (token: string) => {
7373
})
7474

7575
// get the user information for each contributor
76-
const contributors = (await Promise.all(
76+
const contributors = await Promise.all(
7777
contributorList
7878
.filter(({ type }) => type === 'User')
79-
.map((user) =>
80-
octokit.request('GET /users/{username}', { username: user.login as string }).then(({ data }) => data),
81-
),
82-
)) as GitHubUser[]
79+
.map((user) => octokit.rest.users.getByUsername({ username: user.login as string }).then(({ data }) => data)),
80+
)
8381

84-
return contributors
82+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
83+
const currentActor = process.env.GITHUB_ACTOR!
84+
// add the current user to the list of contributors if needed
85+
if (!contributorList.some((user) => user.login === currentActor)) {
86+
const { data: currentUser } = await octokit.rest.users.getByUsername({ username: currentActor })
87+
if (currentUser.type === 'User') {
88+
return [...contributors, currentUser] as GitHubUser[]
89+
}
90+
}
91+
92+
return contributors as GitHubUser[]
8593
}
8694

8795
const updatePackageJson = async (contributors: string[]) => {
@@ -114,5 +122,5 @@ export const updateContributors = async (token: string) => {
114122
return createContributorString({ name: fullName, email, url })
115123
})
116124

117-
return updatePackageJson(newContributors)
125+
return updatePackageJson(newContributors.sort())
118126
}

0 commit comments

Comments
 (0)