Skip to content

Commit be51347

Browse files
committed
chore: Add getContributors to utils
1 parent b8cabe3 commit be51347

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

scripts/_utils.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import { execSync } from 'node:child_process'
12
import { promises as fsp } from 'node:fs'
3+
import { $fetch } from 'ofetch'
24
import { resolve } from 'pathe'
35
import { globby } from 'globby'
46
import { execaSync } from 'execa'
57
import { determineSemverChange, getGitDiff, loadChangelogConfig, parseCommits } from 'changelogen'
68

79
export interface Dep {
8-
name: string,
9-
range: string,
10+
name: string
11+
range: string
1012
type: string
1113
}
1214

@@ -35,7 +37,7 @@ export async function loadPackage (dir: string) {
3537
dir,
3638
data,
3739
save,
38-
updateDeps
40+
updateDeps,
3941
}
4042
}
4143

@@ -93,7 +95,7 @@ export async function loadWorkspace (dir: string) {
9395
save,
9496
find,
9597
rename,
96-
setVersion
98+
setVersion,
9799
}
98100
}
99101

@@ -112,3 +114,25 @@ export async function getLatestCommits () {
112114

113115
return parseCommits(await getGitDiff(latestTag), config)
114116
}
117+
118+
export async function getContributors () {
119+
const contributors = [] as Array<{ name: string, username: string }>
120+
const emails = new Set<string>()
121+
const latestTag = execSync('git describe --tags --abbrev=0').toString().trim()
122+
const rawCommits = await getGitDiff(latestTag)
123+
for (const commit of rawCommits) {
124+
if (emails.has(commit.author.email) || commit.author.name === 'renovate[bot]') { continue }
125+
const { author } = await $fetch<{ author: { login: string, email: string } }>(`https://api.github.com/repos/CodeDredd/pinia-orm/commits/${commit.shortHash}`, {
126+
headers: {
127+
'User-Agent': 'CodeDredd/pinia-orm',
128+
'Accept': 'application/vnd.github.v3+json',
129+
'Authorization': `token ${process.env.GITHUB_TOKEN}`,
130+
},
131+
})
132+
if (!contributors.some(c => c.username === author.login)) {
133+
contributors.push({ name: commit.author.name, username: author.login })
134+
}
135+
emails.add(author.email)
136+
}
137+
return contributors
138+
}

0 commit comments

Comments
 (0)