Skip to content

Commit 6df8958

Browse files
authored
Merge pull request #561 from gm3dmo/powersmash
Copilot makes a contribution
2 parents 9e4d044 + bcec8f5 commit 6df8958

34 files changed

Lines changed: 560 additions & 7 deletions

add-app-access-restrictions.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
. ./.gh-api-examples.conf
2+
3+
# https://docs.github.com/en/rest/branches/branch-protection?apiVersion=2022-11-28#add-app-access-restrictions
4+
# POST /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps
5+
6+
branch=${protected_branch_name}
7+
8+
if [ -z "$1" ]
9+
then
10+
app_slug="${app_slug}"
11+
else
12+
app_slug=$1
13+
fi
14+
15+
json_file=tmp/add-app-access-restrictions.json
16+
jq -n \
17+
--arg app_slug "${app_slug}" \
18+
'{
19+
apps: [ $app_slug ]
20+
}' > ${json_file}
21+
22+
curl ${curl_custom_flags} \
23+
-X POST \
24+
-H "Accept: application/vnd.github.v3+json" \
25+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
26+
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/branches/${branch}/protection/restrictions/apps" --data @${json_file}

add-collaborator-to-repo.sh

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
1-
. ./.gh-api-examples.conf
1+
. ./.gh-api-examples.conf
22

33
# https://docs.github.com/en/rest/collaborators/collaborators?apiVersion=2022-11-28#add-a-repository-collaborator
44
# PUT /repos/{owner}/{repo}/collaborators/{username}
55

66
# limits: https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-access-to-your-personal-repositories/inviting-collaborators-to-a-personal-repository
77

88

9-
username=${repo_collaborator}
9+
# If the script is passed an argument $1 use that as the name
10+
if [ -z "$1" ]
11+
then
12+
username=${repo_collaborator}
13+
else
14+
username=$1
15+
fi
16+
1017
permission=${2:-push}
1118

12-
JSON_TEMPLATE='{"permission":"%s"}'
13-
JSON_DATA=$(printf "$JSON_TEMPLATE" "$permission")
19+
json_file=tmp/add-collaborator-to-repo.json
20+
21+
jq -n \
22+
--arg permission "${permission}" \
23+
'{
24+
permission : $permission,
25+
}' > ${json_file}
26+
1427

1528
curl ${curl_custom_flags} \
1629
-X PUT \
17-
-H "Accept: application/vnd.github.v3+json" \
30+
-H "X-GitHub-Api-Version: ${github_api_version}" \
31+
-H "Accept: application/vnd.github+json" \
1832
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
19-
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/collaborators/${username}" -d ${JSON_DATA}
33+
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/collaborators/${username}" --data @${json_file}
2034

add-status-check-contexts.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
. ./.gh-api-examples.conf
2+
3+
# https://docs.github.com/en/rest/branches/branch-protection?apiVersion=2022-11-28#add-status-check-contexts
4+
# POST /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks/contexts
5+
6+
branch=${protected_branch_name}
7+
8+
json_file=tmp/add-status-check-contexts.json
9+
jq -n \
10+
--arg required_status_check_name "${required_status_check_name}" \
11+
'{
12+
contexts: [ $required_status_check_name ]
13+
}' > ${json_file}
14+
15+
curl ${curl_custom_flags} \
16+
-X POST \
17+
-H "Accept: application/vnd.github.v3+json" \
18+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
19+
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/branches/${branch}/protection/required_status_checks/contexts" --data @${json_file}

add-team-access-restrictions.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
. ./.gh-api-examples.conf
2+
3+
# https://docs.github.com/en/rest/branches/branch-protection?apiVersion=2022-11-28#add-team-access-restrictions
4+
# POST /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams
5+
6+
branch=${protected_branch_name}
7+
8+
json_file=tmp/add-team-access-restrictions.json
9+
jq -n \
10+
--arg team_slug "${team_slug}" \
11+
'{
12+
teams: [ $team_slug ]
13+
}' > ${json_file}
14+
15+
curl ${curl_custom_flags} \
16+
-X POST \
17+
-H "Accept: application/vnd.github.v3+json" \
18+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
19+
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/branches/${branch}/protection/restrictions/teams" --data @${json_file}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
. ./.gh-api-examples.conf
2+
3+
# https://docs.github.com/en/rest/collaborators/collaborators?apiVersion=2022-11-28#check-if-a-user-is-a-repository-collaborator
4+
# GET /repos/{owner}/{repo}/collaborators/{username}
5+
6+
7+
if [ -z "$1" ]
8+
then
9+
username=${repo_collaborator}
10+
else
11+
username=$1
12+
fi
13+
14+
15+
set -x
16+
curl ${curl_custom_flags} \
17+
-H "X-GitHub-Api-Version: ${github_api_version}" \
18+
-H "Accept: application/vnd.github+json" \
19+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
20+
"${GITHUB_API_BASE_URL}/repos/${owner}/${repo}/collaborators/${username}"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
. ./.gh-api-examples.conf
2+
3+
# https://docs.github.com/en/rest/branches/branch-protection?apiVersion=2022-11-28#create-commit-signature-protection
4+
# POST /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures
5+
6+
branch=${protected_branch_name}
7+
8+
curl ${curl_custom_flags} \
9+
-X POST \
10+
-H "Accept: application/vnd.github.v3+json" \
11+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
12+
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/branches/${branch}/protection/required_signatures"

delete-access-restrictions.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
. ./.gh-api-examples.conf
2+
3+
# https://docs.github.com/en/rest/branches/branch-protection?apiVersion=2022-11-28#delete-access-restrictions
4+
# DELETE /repos/{owner}/{repo}/branches/{branch}/protection/restrictions
5+
6+
branch=${protected_branch_name}
7+
8+
curl ${curl_custom_flags} \
9+
-X DELETE \
10+
-H "Accept: application/vnd.github.v3+json" \
11+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
12+
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/branches/${branch}/protection/restrictions"

delete-admin-branch-protection.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
. ./.gh-api-examples.conf
2+
3+
# https://docs.github.com/en/rest/branches/branch-protection?apiVersion=2022-11-28#delete-admin-branch-protection
4+
# DELETE /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins
5+
6+
branch=${protected_branch_name}
7+
8+
curl ${curl_custom_flags} \
9+
-X DELETE \
10+
-H "Accept: application/vnd.github.v3+json" \
11+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
12+
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/branches/${branch}/protection/enforce_admins"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
. ./.gh-api-examples.conf
2+
3+
# https://docs.github.com/en/rest/branches/branch-protection?apiVersion=2022-11-28#delete-commit-signature-protection
4+
# DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures
5+
6+
branch=${protected_branch_name}
7+
8+
curl ${curl_custom_flags} \
9+
-X DELETE \
10+
-H "Accept: application/vnd.github.v3+json" \
11+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
12+
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/branches/${branch}/protection/required_signatures"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
. ./.gh-api-examples.conf
2+
3+
# https://docs.github.com/en/rest/branches/branch-protection?apiVersion=2022-11-28#delete-pull-request-review-protection
4+
# DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews
5+
6+
branch=${protected_branch_name}
7+
8+
curl ${curl_custom_flags} \
9+
-X DELETE \
10+
-H "Accept: application/vnd.github.v3+json" \
11+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
12+
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/branches/${branch}/protection/required_pull_request_reviews"

0 commit comments

Comments
 (0)