-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
46 lines (40 loc) · 1000 Bytes
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { octokit } from './octokit'
export async function isTrustedUser(
owner: string,
repo: string,
username: string,
): Promise<boolean> {
try {
const { data: collaboratorPermission } =
await octokit.repos.getCollaboratorPermissionLevel({
owner,
repo,
username,
})
const trustedPermissions = ['write', 'maintain', 'admin']
return trustedPermissions.includes(collaboratorPermission.permission)
} catch (error) {
console.error(`Error checking user permission: ${error}`)
return false // 如果出现错误,默认不信任该用户
}
}
const allowPrefix = [
'feat',
'fix',
'perf',
'refactor',
'docs',
'style',
'test',
'revert',
'release',
'chore',
]
export function conventionalCommit(title: string): boolean {
const prefix = title.split(':')[0]
if (!title.includes(':')) {
return false
}
const typeWithoutScope = prefix.split('(')[0].trim()
return allowPrefix.includes(typeWithoutScope)
}