Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1f7b3f7
List app installs with all pages fetched
guperrot Jul 18, 2025
60d99c1
get install token with installid parameter
guperrot Jul 18, 2025
d20d844
Install app on a many orgs
guperrot Jul 18, 2025
e78da21
Create 10 private repos on every org app install
guperrot Jul 18, 2025
5aacc44
Assign roles script
guperrot Jul 18, 2025
183768c
Install app on all orgs, not hardcoded
guperrot Jul 18, 2025
8feabd8
Add comment
guperrot Jul 18, 2025
db6b753
Proxima workaround
guperrot Jul 18, 2025
f172698
Change back to name
guperrot Jul 18, 2025
cc5aa46
Fix pagination size
guperrot Jul 18, 2025
3156600
scripts for scale testing
fmacar3na Jul 23, 2025
d2eec3a
List enterprise team members
guperrot Jul 23, 2025
e08b48c
Merge pull request #2 from fmacar3na/fmacar3na/scripts
guperrot Jul 23, 2025
e1e5d65
assign roles to all team members
guperrot Jul 23, 2025
5385a88
Add org suffix filter
guperrot Jul 23, 2025
b573016
Fail username loop after first username failure
guperrot Jul 23, 2025
864b798
Fix prefix matching
guperrot Jul 23, 2025
29af7d7
Handle suffix better
guperrot Jul 23, 2025
eb783c7
Minor cleanup
guperrot Jul 23, 2025
0cf1f3b
Fix operator
guperrot Jul 24, 2025
3202c39
Fix filter
guperrot Jul 24, 2025
b7bd6ac
Print error if not github token set
guperrot Jul 24, 2025
b68d6be
Parallelize username loop
guperrot Jul 24, 2025
d988608
updated script for repo roles
fmacar3na Jul 24, 2025
37c9cb3
Merge pull request #3 from fmacar3na/fmacar3na/scripts
guperrot Jul 24, 2025
7c7dbe7
Remove -v
guperrot Jul 24, 2025
3c488d8
Fix assign roles list teams error handling
guperrot Jul 28, 2025
1fa95ca
Assign role to team
guperrot Jul 29, 2025
267e115
Check error for listing team members in assign repo role to user
guperrot Jul 30, 2025
91561a8
Use repo from config
guperrot Jul 30, 2025
92c466c
updated repo role scripts
fmacar3na Jul 31, 2025
5807117
Merge branch 'guperrot/tnt-batch-scripts' into fmacar3na/scripts
guperrot Jul 31, 2025
df467d8
Merge pull request #4 from fmacar3na/fmacar3na/scripts
guperrot Jul 31, 2025
8744d89
Fix team/repo params
guperrot Jul 31, 2025
1da4260
Use login for orgs
guperrot Oct 3, 2025
13be11b
Fix perms
guperrot Oct 3, 2025
3e58e96
Parallel repo creation
guperrot Oct 3, 2025
fdb97bb
Do not assume batch-org format
guperrot Oct 8, 2025
c698a39
Bump sleep delay for proxima
guperrot Oct 8, 2025
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
70 changes: 70 additions & 0 deletions assign-repo-role-to-team.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#add-or-update-team-repository-permissions

if [ -z "$GITHUB_TOKEN" ]; then
echo "GITHUB_TOKEN is not set, please provide a PAT with admin:enterprise scope."
exit 1
fi

if [ -n "$1" ]; then
ending_org=$1
fi

if [ -n "$2" ]; then
starting_org=$2
fi

list_enterprise_team_members_output=$(./list-enterprise-team-members.sh "$team")
if [ $? -ne 0 ]; then
echo $list_enterprise_team_members_output
exit 1
fi
usernames=$list_enterprise_team_members_output
app_installs=$(./tiny-list-app-installations.sh)

repo=${repo:-"private-repo-1"}

# Sort app installations by account login and iterate
echo "$app_installs" | jq -c '. | sort_by(.account.login) | .[]' | while read -r install; do
install_id=$(echo "$install" | jq -r '.id')
org=$(echo "$install" | jq -r '.account.login')
if [ -z "$org" ] || [ "$org" = "null" ]; then
continue
fi

if [ -n "$starting_org" ]; then
if [[ "$org" < "$starting_org" ]]; then
continue
fi
fi

if [ -n "$ending_org" ]; then
if [[ "$org" > "$ending_org" ]]; then
continue
fi
fi

echo "➡️ Assigning repo permissions for $org (install_id: $install_id)"
GITHUB_TOKEN=$(./ent-call-get-installation-token.sh $install_id | jq -r '.token')

response=$(curl -s -w "\n%{http_code}" -X PUT \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
-d "{\"permission\":\"triage\"}" \
"$GITHUB_API_BASE_URL/orgs/$org/teams/$team/repos/$org/$repo")
http_code=$(echo "$response" | tail -n1)
json_body=$(echo "$response" | sed '$d')

if [[ "$http_code" == "201" ]] || [[ "$http_code" == "204" ]]; then
echo " ✅ Repo permissions assigned to $team"
else
echo " ❌ Failed to assign repo permissions (HTTP $http_code) for $team"
echo " Response: $json_body"
fi
wait
done

echo "🎉 Done assigning repo permissions."
75 changes: 75 additions & 0 deletions assign-repo-role-to-user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/collaborators/collaborators?apiVersion=2022-11-28#add-a-repository-collaborator

if [ -z "$GITHUB_TOKEN" ]; then
echo "GITHUB_TOKEN is not set, please provide a PAT with admin:enterprise scope."
exit 1
fi

if [ -n "$1" ]; then
ending_org=$1
fi

if [ -n "$2" ]; then
starting_org=$2
fi

list_enterprise_team_members_output=$(./list-enterprise-team-members.sh "$team")
if [ $? -ne 0 ]; then
echo $list_enterprise_team_members_output
exit 1
fi
usernames=$list_enterprise_team_members_output
app_installs=$(./tiny-list-app-installations.sh)

repo=${repo:-"private-repo-1"}

# Iterate over each installation
echo "$app_installs" | jq -c '. | sort_by(.account.login) | .[]' | while read -r install; do
install_id=$(echo "$install" | jq -r '.id')
org=$(echo "$install" | jq -r '.account.login')
if [ -z "$org" ] || [ "$org" = "null" ]; then
continue
fi

if [ -n "$starting_org" ]; then
if [[ "$org" < "$starting_org" ]]; then
continue
fi
fi

if [ -n "$ending_org" ]; then
if [[ "$org" > "$ending_org" ]]; then
continue
fi
fi

echo "➡️ Assigning repo permissions for $org (install_id: $install_id)"
GITHUB_TOKEN=$(./ent-call-get-installation-token.sh $install_id | jq -r '.token')

for username in $usernames; do
(
response=$(curl -s -w "\n%{http_code}" -X PUT \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
-d "{\"permission\":\"triage\"}" \
"$GITHUB_API_BASE_URL/repos/$org/$repo/collaborators/$username")
http_code=$(echo "$response" | tail -n1)
json_body=$(echo "$response" | sed '$d')

if [[ "$http_code" == "201" ]] || [[ "$http_code" == "204" ]]; then
echo " ✅ Repo permissions assigned to $username"
else
echo " ❌ Failed to assign repo permissions (HTTP $http_code) for $username"
#echo " Response: $json_body"
fi
) &
sleep 0.019
done
wait
done

echo "🎉 Done assigning repo permissions."
101 changes: 101 additions & 0 deletions assign-roles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/bin/bash

. ./.gh-api-examples.conf

if [ -z "$GITHUB_TOKEN" ]; then
echo "GITHUB_TOKEN is not set, please provide a PAT with admin:enterprise scope."
exit 1
fi

if [ -n "$1" ]; then
ending_org=$1
fi

if [ -n "$2" ]; then
starting_org=$2
fi

list_enterprise_team_members_output=$(./list-enterprise-team-members.sh "$team")
if [ $? -ne 0 ]; then
echo $list_enterprise_team_members_output
exit 1
fi
usernames=$list_enterprise_team_members_output
app_installs=$(./tiny-list-app-installations.sh)

# Iterate over each installation
echo "$app_installs" | jq -c '. | sort_by(.account.login) | .[]' | while read -r install; do
install_id=$(echo "$install" | jq -r '.id')
org=$(echo "$install" | jq -r '.account.login')

if [ -z "$org" ] || [ "$org" = "null" ]; then
continue
fi

if [ -n "$starting_org" ]; then
if [[ "$org" < "$starting_org" ]]; then
continue
fi
fi

if [ -n "$ending_org" ]; then
if [[ "$org" > "$ending_org" ]]; then
continue
fi
fi

echo "➡️ Assigning roles for $org (install_id: $install_id)"
GITHUB_TOKEN=$(./ent-call-get-installation-token.sh $install_id | jq -r '.token')

# Get first org role
response=$(curl -s -w "\n%{http_code}" \
-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")
http_code=$(echo "$response" | tail -n1)
json_body=$(echo "$response" | sed '$d')
if [[ "$http_code" -lt 300 ]]; then
first_role_id=$(echo "$json_body" | jq -r '.roles[0].id')
echo " ➡️ Got first role id for $org: $first_role_id"
else
echo " ❌ Failed to get roles for $org (HTTP $http_code)"
fi

# Assign it to the team
# put /organizations/:organization_id/organization-roles/team/:team_id/:role_id
response=$(curl -s -w "\n%{http_code}" -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}/${first_role_id}")
http_code=$(echo "$response" | tail -n1)
json_body=$(echo "$response" | sed '$d')
if [[ "$http_code" -lt 300 ]]; then
echo " ✅ Assigned role to team $team in $org"
else
echo " ❌ Failed to assign role to team $team in $org (HTTP $http_code)"
fi

# Assign to every user, its redundant but we are just using this to scale test performances
for username in $usernames; do
(
response=$(curl -s -w "\n%{http_code}" -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}/${first_role_id}")
http_code=$(echo "$response" | tail -n1)
json_body=$(echo "$response" | sed '$d')
if [[ "$http_code" -lt 300 ]]; then
echo " ✅ Assigned role to $username in $org"
else
echo " ❌ Failed to assign role to $username in $org (HTTP $http_code)"
fi
) &
sleep 0.019
done
wait
done

echo "🎉 Done assigning roles."
36 changes: 36 additions & 0 deletions assign-security-manager-org-role-to-team.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
# This script won't work without updates to the Orgs API to support BTs.

. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/orgs/organization-roles?apiVersion=2022-11-28#assign-an-organization-role-to-a-team

APP_INSTALLS=$(./tiny-list-app-installations.sh)
team_slug="testing"
role_id=138

# Iterate over each installation
echo "$APP_INSTALLS" | jq -c '.[]' | while read -r install; do
install_id=$(echo "$install" | jq -r '.id')
org=$(echo "$install" | jq -r '.account.login')
if [ -z "$org" ] || [ "$org" = "null" ]; then
continue
fi

echo "➡️ Assigning Security Manager role for $org (install_id: $install_id)"
GITHUB_TOKEN=$(./ent-call-get-installation-token.sh $install_id | jq -r '.token')
response=$(curl -s -w "\n%{http_code}" -X PUT \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
"$GITHUB_API_BASE_URL/orgs/$org/organization-roles/teams/$team_slug/$role_id")
http_code=$(echo "$response" | tail -n1)
json_body=$(echo "$response" | sed '$d')
if [[ "$http_code" == "204" ]]; then
echo " ✅ Security manager role assigned to $team_slug"
else
echo " ❌ Failed to assign security manager role (HTTP $http_code)"
#echo " Response: $json_body"
fi
done

echo "🎉 Done assigning security manager role."
35 changes: 35 additions & 0 deletions assign-security-manager-org-role-to-user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/orgs/organization-roles?apiVersion=2022-11-28#assign-an-organization-role-to-a-user

APP_INSTALLS=$(./tiny-list-app-installations.sh)
user="fmacar3na-alt_tntmd2"
role_id=138

# Iterate over each installation
echo "$APP_INSTALLS" | jq -c '.[]' | while read -r install; do
install_id=$(echo "$install" | jq -r '.id')
org=$(echo "$install" | jq -r '.account.login')
if [ -z "$org" ] || [ "$org" = "null" ]; then
continue
fi

echo "➡️ Assigning Security Manager role for $org (install_id: $install_id)"
GITHUB_TOKEN=$(./ent-call-get-installation-token.sh $install_id | jq -r '.token')
response=$(curl -s -w "\n%{http_code}" -X PUT \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
"$GITHUB_API_BASE_URL/orgs/$org/organization-roles/users/$user/$role_id")
http_code=$(echo "$response" | tail -n1)
json_body=$(echo "$response" | sed '$d')
if [[ "$http_code" == "204" ]]; then
echo " ✅ Security manager role assigned to $user"
else
echo " ❌ Failed to assign security manager role (HTTP $http_code)"
#echo " Response: $json_body"
fi
done

echo "🎉 Done assigning security manager role."
37 changes: 37 additions & 0 deletions create-repos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

. ./.gh-api-examples.conf

APP_INSTALLS=$(./tiny-list-app-installations.sh)

# Iterate over each installation
echo "$APP_INSTALLS" | jq -c '.[]' | while read -r install; do
install_id=$(echo "$install" | jq -r '.id')
org=$(echo "$install" | jq -r '.account.login')
if [ -z "$org" ] || [ "$org" = "null" ]; then
continue
fi

echo "➡️ Creating repos for $org (install_id: $install_id)"
GITHUB_TOKEN=$(./ent-call-get-installation-token.sh $install_id | jq -r '.token')
for repo_num in $(seq 1 10); do
(
repo="private-repo-$repo_num"
response=$(curl -s -w "\n%{http_code}" -X POST "$GITHUB_API_BASE_URL/orgs/$org/repos" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
-d "{\"name\":\"$repo\",\"private\":true,\"auto_init\":true}")
http_code=$(echo "$response" | tail -n1)
json_body=$(echo "$response" | sed '$d')
if [[ "$http_code" == "201" ]]; then
echo " ✅ Created $org/$repo"
else
echo " ❌ Failed to create $org/$repo (HTTP $http_code)"
#echo " Response: $json_body"
fi
) &
done
wait
done

echo "🎉 Done creating repositories."
8 changes: 7 additions & 1 deletion ent-call-get-installation-token.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@

# rate_limits: https://docs.github.com/en/developers/apps/building-github-apps/rate-limits-for-github-apps


JWT=$(./ent-call-get-jwt.sh ${ent_app_id} 2>/dev/null)

installation_id=${ent_app_installation_id}
# Allow passing installation_id as $1, fallback to ent_app_installation_id
if [ -n "$1" ]; then
installation_id="$1"
else
installation_id="${ent_app_installation_id}"
fi

curl --silent ${curl_custom_flags} \
-X POST \
Expand Down
Loading