-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (98 loc) · 4.04 KB
/
action-issuesops.yml
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: Issue Ops Example
on:
issues:
types: [opened]
jobs:
IssueOps:
runs-on: ubuntu-latest
steps:
- name: Dump GitHub Context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Print Context
uses: actions/github-script@v4
with:
script: |
console.log(context)
- name: Create GitHub repo
uses: actions/github-script@v5
with:
github-token: ${{ secrets.CUSTOM_TOKEN }}
script: |
console.log(context.payload.issue.body)
bodySplit = context.payload.issue.body.split("\n")
console.log("New repository name: " + bodySplit[2])
console.log("Template Repository: " + bodySplit[6])
console.log("Team: " + bodySplit[10])
console.log("Enable Issue: " + bodySplit[14].includes("X"))
console.log("Enable Project: " + bodySplit[18].includes("X"))
console.log("Allow Squash Merge: " + bodySplit[22].includes("X"))
console.log("Allow Forking: " + bodySplit[26].includes("X"))
let newRepo = bodySplit[2]
let templateRepo = bodySplit[6]
let teams = bodySplit[10].split(",")
let enableIssue = bodySplit[14].includes("X")
let enableProject = bodySplit[18].includes("X")
let enableSquashMerge = bodySplit[22].includes("X")
let enableForking = bodySplit[26].includes("X")
console.log("New repo: " + newRepo + " Template Repo: " + templateRepo + " Teams: " + teams)
try {
await github.rest.repos.createUsingTemplate({
template_owner: context.payload.organization.login,
template_repo: templateRepo,
name: newRepo,
owner: context.payload.organization.login,
description: "Test",
include_all_branches: true,
private: false
})
} catch(err) {
throw err
}
try {
await github.rest.repos.update({
owner: context.payload.organization.login,
private: true,
repo: newRepo,
has_issues: enableIssue,
has_projects: enableProject,
allow_squash_merge: enableSquashMerge
})
} catch(err) {
throw err
}
try {
await github.rest.repos.updateBranchProtection({
"owner": context.payload.organization.login,
"repo": newRepo,
"branch": 'main',
"required_status_checks": { "strict": true, "contexts": [] },
"enforce_admins": true,
"required_pull_request_reviews": {"dismissal_restrictions": {"users":[], "teams":[]}, "dismiss_stale_reviews": false, "require_code_owner_reviews": true, "required_approving_review_count": 1},
"restrictions" : { "users": [], "teams": [], "apps": [] }
})
} catch(err) {
throw err
}
try {
await github.rest.teams.addOrUpdateRepoPermissionsInOrg({
org: context.payload.organization.login,
owner: context.payload.organization.login,
repo: newRepo,
team_slug: teams,
permission: 'admin'
})
} catch(err) {
throw err
}
- name: Add comment
uses: actions/github-script@v5
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Thanks for creating a repo'
})