@@ -11,20 +11,31 @@ TEMPLATE_REPO=${TEMPLATE_REPO:-''}
1111REPO_NAME=$1
1212CD_USERNAME=${CD_USERNAME:- ' ' }
1313CD_GITHUB_TOKEN=${CD_GITHUB_TOKEN:- ' ' }
14- PORTX_TENANT_FLUX_ADMINS=${PORTX_TENANT_FLUX_ADMINS:- ' ' }
15- PORTX_INFRASTRUCTURE=${PORTX_INFRASTRUCTURE:- ' ' }
14+ REPO_ADMIN=${REPO_ADMIN:- ' admins example' }
15+ REPO_WRITE=${REPO_WRITE:- ' write example2' }
16+
17+ # Check if GITHUB_TOKEN is empty
18+ if [ -z " ${GITHUB_TOKEN} " ]
19+ then
20+ echo " GITHUB_TOKEN is empty. Please set your token and try again"
21+ exit 1
22+ fi
1623
1724# Create repo from template
18- curl -X POST -H " Authorization: token ${GITHUB_TOKEN} " -H " Accept: application/vnd.github.baptiste-preview+json" " ${API_URL_PREFIX} /repos/${ORG} /${TEMPLATE_REPO} /generate" -d ' {"name":"' ${REPO_NAME} ' ", "owner":"' ${ORG} ' ", "private":true, "include_all_branches":true}' ;
25+ curl -s - X POST -H " Authorization: token ${GITHUB_TOKEN} " -H " Accept: application/vnd.github.baptiste-preview+json" " ${API_URL_PREFIX} /repos/${ORG} /${TEMPLATE_REPO} /generate" -d ' {"name":"' ${REPO_NAME} ' ", "owner":"' ${ORG} ' ", "private":true, "include_all_branches":true}' ;
1926
2027# Give internal teams permissions on the new repo
21- curl -X PUT -H " Authorization: token ${GITHUB_TOKEN} " -H " Accept: application/vnd.github.v3+json" " ${API_URL_PREFIX} /orgs/${ORG} /teams/${PORTX_TENANT_FLUX_ADMINS} /repos/${ORG} /${REPO_NAME} " -d ' {"permission":"admin"}' ;
22- curl -X PUT -H " Authorization: token ${GITHUB_TOKEN} " -H " Accept: application/vnd.github.v3+json" " ${API_URL_PREFIX} /orgs/${ORG} /teams/${PORTX_INFRASTRUCTURE} /repos/${ORG} /${REPO_NAME} " -d ' {"permission":"admin"}' ;
28+ for ADMIN_TEAM in ${REPO_ADMIN} ; do
29+ curl -s -X PUT -H " Authorization: token ${GITHUB_TOKEN} " -H " Accept: application/vnd.github.v3+json" " ${API_URL_PREFIX} /orgs/${ORG} /teams/${ADMIN_TEAM} /repos/${ORG} /${REPO_NAME} " -d ' {"permission":"admin"}' ;
30+ done
2331
32+ for WRITE_TEAM in ${REPO_WRITE} ; do
33+ curl -s -X PUT -H " Authorization: token ${GITHUB_TOKEN} " -H " Accept: application/vnd.github.v3+json" " ${API_URL_PREFIX} /orgs/${ORG} /teams/${WRITE_TEAM} /repos/${ORG} /${REPO_NAME} " -d ' {"permission":"push"}' ;
34+ done
2435# Give cd user write permissions on the new repo
25- curl -X PUT -H " Authorization: token ${GITHUB_TOKEN} " -H " Accept: application/vnd.github.v3+json" " ${API_URL_PREFIX} /repos/${ORG} /${REPO_NAME} /collaborators/${CD_USERNAME} " -d ' {"permission":"push"}' ;
36+ curl -s - X PUT -H " Authorization: token ${GITHUB_TOKEN} " -H " Accept: application/vnd.github.v3+json" " ${API_URL_PREFIX} /repos/${ORG} /${REPO_NAME} /collaborators/${CD_USERNAME} " -d ' {"permission":"push"}' ;
2637
2738# Accept the invite automatically
28- CD_INVITES=$( curl -H " Authorization: token ${CD_GITHUB_TOKEN} " -H " Accept: application/vnd.github.v3+json" " ${API_URL_PREFIX} /user/repository_invitations" )
39+ CD_INVITES=$( curl -s - H " Authorization: token ${CD_GITHUB_TOKEN} " -H " Accept: application/vnd.github.v3+json" " ${API_URL_PREFIX} /user/repository_invitations" )
2940CD_INVITES_INVITE_ID=$( echo " $CD_INVITES " | jq -r --arg REPO_NAME " ${REPO_NAME} " ' select(.[].repository.name==$REPO_NAME) | .[].id' )
30- curl -X PATCH -H " Authorization: token ${CD_GITHUB_TOKEN} " -H " Accept: application/vnd.github.v3+json" " ${API_URL_PREFIX} /user/repository_invitations/${CD_INVITES_INVITE_ID} "
41+ curl -s - X PATCH -H " Authorization: token ${CD_GITHUB_TOKEN} " -H " Accept: application/vnd.github.v3+json" " ${API_URL_PREFIX} /user/repository_invitations/${CD_INVITES_INVITE_ID} "
0 commit comments