-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
create-test-repo.sh
42 lines (37 loc) · 1.3 KB
/
create-test-repo.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
#!/usr/bin/env bash
# This script will create a test repository and assign a team to that repository
#
# Usage:
# NEW_TOKEN=$(./pat.sh) BOT_TOKEN=<token> bash create-test-repo.sh repo/name team new-org folder
#
# The above command will create new-org/repo and assign it to "team".
set -euo pipefail
REPOSITORY=${1:-fishtree-attempt/znk-test}
TEAM=${2:-bots}
ORG="${3:-fishtree-attempt}"
FOLDER="${4:-sandpaper}"
NAME="$(basename ${REPOSITORY})"
OUT="${FOLDER}/${REPOSITORY}-status.json"
echo "from ${REPOSITORY} to ${ORG}/${NAME} (${TEAM})"
# This does two steps:
#
# 1. create the brand new repository called ${NAME}
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${NEW_TOKEN}" \
https://api.github.com/orgs/${ORG}/repos \
-d "{\"name\":\"${NAME}\", \"homepage\":\"https://${ORG}.github.io/${NAME}/\"}" > ${OUT}
# 2. assign the ${TEAM} to that repository
curl \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${BOT_TOKEN}" \
https://api.github.com/orgs/${ORG}/teams/${TEAM}/repos/${ORG}/${NAME} \
-d '{"permission":"push"}'
URL=$(jq -r .html_url < ${OUT})
# 3. push the repository to the new lesson
cd ${FOLDER}/${REPOSITORY}
git push -u origin main
Rscript -e "usethis::use_github_pages()"
echo "Browse the repository at ${URL}"