Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions assign-an-organization-role-to-a-team.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/organization-roles?apiVersion=2022-11-28#assign-an-organization-role-to-a-team
# PUT /orgs/{org}/organization-roles/teams/{team_slug}/{role_id}


role_id=$1


curl ${curl_custom_flags} \
-X PUT \
-H "X-GitHub-Api-Version: ${github_api_version}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${GITHUB_API_BASE_URL}/orgs/${org}/organization-roles/teams/${team_slug}/${role_id}"

23 changes: 23 additions & 0 deletions assign-an-organization-role-to-a-user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/organization-roles?apiVersion=2022-11-28#assign-an-organization-role-to-a-user
# PUT /orgs/{org}/organization-roles/users/{username}/{role_id}


# If the script is passed an argument $1 use that as the name
if [ -z "$1" ]
then
role_id=1
else
role_id=$1
fi

username=${pr_approver_name}

curl ${curl_custom_flags} \
-X PUT \
-H "X-GitHub-Api-Version: ${github_api_version}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${GITHUB_API_BASE_URL}/orgs/${org}/organization-roles/users/${username}/${role_id}"

5 changes: 5 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ def main(args):
# https://docs.github.com/en/developers/apps/guides/creating-ci-tests-with-the-checks-api
default_check_run_id=1

### [Organization Roles](https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/organization-roles?apiVersion=2022-11-28)
cr_name="pwr-custom-role"
cr_description="A custom role created by the power"
cr_permissions='["write_organization_custom_repo_role","write_organization_custom_org_role","read_organization_custom_repo_role","read_organization_custom_org_role"]'


### [Pagination](https://docs.github.com/en/rest/guides/traversing-with-pagination)
per_page=30
Expand Down
21 changes: 13 additions & 8 deletions create-a-custom-organization-role.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/orgs/organization-roles?apiVersion=2022-11-28#create-a-custom-organization-role
# https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/organization-roles?apiVersion=2022-11-28#create-a-custom-organization-role
# POST /orgs/{org}/organization-roles


# If the script is passed an argument $1 use that as the name
if [ -z "$1" ]
then
org=$org
org=${org}
else
org=$1
fi


json_file=tmp/create-a-custom-organization-role.json
name=${cr_name}
description=${cr_description}
permissions=${cr_permissions}


json_file=tmp/create-a-custom-organization-role.sh
jq -n \
--arg name "Custom Role Manager" \
--arg description "Permissions to manage custom roles within an org" \
--arg name "${name}" \
--arg description "${description}" \
--argjson permissions "${permissions}" \
'{
name : $name,
descrption : $description,
permissions : ["write_organization_custom_repo_role","write_organization_custom_org_role","read_organization_custom_repo_role","read_organization_custom_org_role"]
description: $description,
permissions: $permissions,
}' > ${json_file}


curl ${curl_custom_flags} \
-H "X-GitHub-Api-Version: ${github_api_version}" \
-H "Accept: application/vnd.github.v3+json" \
Expand Down
16 changes: 16 additions & 0 deletions delete-a-custom-organization-role.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/organization-roles?apiVersion=2022-11-28#delete-a-custom-organization-role
# DELETE /orgs/{org}/organization-roles/{role_id}


role_id=$1


curl ${curl_custom_flags} \
-X DELETE \
-H "X-GitHub-Api-Version: ${github_api_version}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${GITHUB_API_BASE_URL}/orgs/${org}/organization-roles/${role_id}"

5 changes: 3 additions & 2 deletions get-all-organization-roles-for-an-organization.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/orgs/organization-roles?apiVersion=2022-11-28#get-all-organization-roles-for-an-organization
# https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/organization-roles?apiVersion=2022-11-28#get-all-organization-roles-for-an-organization
# GET /orgs/{org}/organization-roles


# If the script is passed an argument $1 use that as the name
if [ -z "$1" ]
then
org=$org
org=$org
else
org=$1
fi
Expand All @@ -19,3 +19,4 @@ curl ${curl_custom_flags} \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${GITHUB_API_BASE_URL}/orgs/${org}/organization-roles"


9 changes: 2 additions & 7 deletions list-custom-repository-roles-in-an-organization.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@
# GET /orgs/{org}/custom-repository-roles


# Query: is this a docs error? I can only get this to work
# with

if [ -z "$1" ]
then
#org=${org}
organization_id=$(./list-organization.sh | jq -r '.id')
org=${org}
else
#org=$1
organization_id=$1
fi

Expand All @@ -21,5 +16,5 @@ 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}/organizations/${organization_id}/custom_roles"
"${GITHUB_API_BASE_URL}/orgs/${org}/custom-repository-roles"

21 changes: 21 additions & 0 deletions list-organization-fine-grained-permissions-for-an-organization.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/organization-roles?apiVersion=2022-11-28#list-organization-fine-grained-permissions-for-an-organization
# GET /orgs/{org}/organization-fine-grained-permissions


# If the script is passed an argument $1 use that as the name
if [ -z "$1" ]
then
org=$org
else
org=$1
fi


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}/orgs/${org}/organization-fine-grained-permissions"

15 changes: 15 additions & 0 deletions list-teams-that-are-assigned-to-an-organization-role.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/organization-roles?apiVersion=2022-11-28#list-teams-that-are-assigned-to-an-organization-role
# GET /orgs/{org}/organization-roles/{role_id}/teams


role_id=$1

set -x
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}/orgs/${org}/organization-roles/${role_id}/teams"

11 changes: 2 additions & 9 deletions list-users-that-are-assigned-to-an-organization-role.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/orgs/organization-roles?apiVersion=2022-11-28#list-users-that-are-assigned-to-an-organization-role
# https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/organization-roles?apiVersion=2022-11-28#list-users-that-are-assigned-to-an-organization-role
# GET /orgs/{org}/organization-roles/{role_id}/users


if [ -z "$1" ]
then
role_id=$organization_role_id
else
role_id=$1
fi

role_id=$1

curl ${curl_custom_flags} \
-H "X-GitHub-Api-Version: ${github_api_version}" \
Expand Down
6 changes: 2 additions & 4 deletions remove-all-organization-roles-for-a-team.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/orgs/organization-roles?apiVersion=2022-11-28#remove-all-organization-roles-for-a-team
# https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/organization-roles?apiVersion=2022-11-28#remove-all-organization-roles-for-a-team
# DELETE /orgs/{org}/organization-roles/teams/{team_slug}


# If the script is passed an argument $1 use that as the name
if [ -z "$1" ]
then
team_slug=$team_slug
team_slug=${team_slug}
else
team_slug=$1
fi


curl ${curl_custom_flags} \
-X DELETE \
-H "X-GitHub-Api-Version: ${github_api_version}" \
Expand Down
16 changes: 16 additions & 0 deletions remove-an-organization-role-from-a-team.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/organization-roles?apiVersion=2022-11-28#remove-an-organization-role-from-a-team
# DELETE /orgs/{org}/organization-roles/teams/{team_slug}/{role_id}


role_id=$1


curl ${curl_custom_flags} \
-X DELETE \
-H "X-GitHub-Api-Version: ${github_api_version}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${GITHUB_API_BASE_URL}/orgs/${org}/organization-roles/teams/${team_slug}/${role_id}"

25 changes: 25 additions & 0 deletions remove-an-organization-role-from-a-user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/organization-roles?apiVersion=2022-11-28#remove-an-organization-role-from-a-user
# DELETE /orgs/{org}/organization-roles/users/{username}/{role_id}


if [ -z "$1" ]
then
role_id=1
else
role_id=$1
fi


# a username of your choice
username=${pr_approver_name}


curl ${curl_custom_flags} \
-X DELETE \
-H "X-GitHub-Api-Version: ${github_api_version}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
"${GITHUB_API_BASE_URL}/orgs/${org}/organization-roles/users/${username}/${role_id}"