-
Notifications
You must be signed in to change notification settings - Fork 29
/
create-a-repository-ruleset-branch-pattern-github-app-override-org-owner-override.sh
executable file
·89 lines (69 loc) · 2.24 KB
/
create-a-repository-ruleset-branch-pattern-github-app-override-org-owner-override.sh
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
. ./.gh-api-examples.conf
# https://docs.github.com/en/enterprise-cloud@latest/rest/repos/rules?apiVersion=2022-11-28#create-a-repository-ruleset
# POST /repos/{owner}/{repo}/rulesets
# If the script is passed an argument $1 use that as the name
if [ -z "$1" ]
then
repo=$repo
else
repo=$1
fi
team_id=$(curl ${curl_custom_flags} --silent -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_API_BASE_URL}/orgs/${org}/teams/$team_slug | jq '.id')
json_file=tmp/create-a-repository-ruleset.json
enforcement=active
jq -n \
--arg name "the-power-branch-allow-github-app-override" \
--arg target "branch" \
--arg default_app_id ${default_app_id} \
--arg bypass_mode "${bypass_mode}" \
--arg enforcement "${enforcement}" \
--arg source "${owner}/${repo}" \
'{
name : $name,
target : $target,
"source_type": "Repository",
"source": $source,
enforcement: $enforcement,
"conditions": {
"ref_name": {
"exclude": [
],
"include": [
"~DEFAULT_BRANCH"
]
}
},
"rules": [
{
"type": "deletion"
},
{
"type": "non_fast_forward"
},
{
"type": "creation"
},
{
"type": "update"
}
],
"bypass_actors": [
{
"actor_id": $default_app_id | tonumber,
"actor_type": "Integration",
"bypass_mode": "always"
},
{
"actor_id": 1,
"actor_type": "OrganizationAdmin",
"bypass_mode": "always"
}
],
}' > ${json_file}
cat $json_file | jq -r
#exit
curl ${curl_custom_flags} \
-H "X-GitHub-Api-Version: ${github_api_version}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${GITHUB_API_BASE_URL}/repos/${owner}/${repo}/rulesets" --data @${json_file}