forked from creatorsgarten/configuration
-
Notifications
You must be signed in to change notification settings - Fork 16
/
lib.ts
70 lines (65 loc) · 1.8 KB
/
lib.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import * as github from '@pulumi/github'
/**
* Invite a GitHub user into the organization.
* @param username - The username of the user to invite.
*/
export const cunnier = (username: string) =>
new github.TeamMembership(`membership-for-${username}`, {
teamId: '6883703',
username,
})
/**
* Creates a team on the GitHub organization.
* @param key - A unique key for the team.
* @param options - The options. Please specify `name` and `description`.
* @returns An object representing the team.
*/
export const team = (key: string, options: github.TeamArgs): ITeam => {
const team = new github.Team(`team-${key}`, { privacy: 'closed', ...options })
return Object.assign(
(username: string) =>
new github.TeamMembership(`team-${key}-membership-for-${username}`, {
teamId: team.id,
username,
}),
{ key, team },
)
}
export interface ITeam {
/**
* Invite a GitHub user into the team.
*/
(username: string): github.TeamMembership
key: string
team: github.Team
}
/**
* Grant teams admin rights to a GitHub repository.
* @param name - The name of the repository.
* @param t - An object returned by the `team` function.
* @returns
*/
export const grantAdmin = (
name: string,
t: { key: string; team: github.Team },
) =>
new github.TeamRepository(`team-${t.key}-repo-${name}`, {
teamId: t.team.id,
repository: name,
permission: 'admin',
})
/**
* Grant teams write access to a GitHub repository.
* @param name - The name of the repository.
* @param t - An object returned by the `team` function.
* @returns
*/
export const grantWriteAccess = (
name: string,
t: { key: string; team: github.Team },
) =>
new github.TeamRepository(`team-${t.key}-repo-${name}`, {
teamId: t.team.id,
repository: name,
permission: 'push',
})