Skip to content

Commit 70ec6fc

Browse files
committed
Open a browser to generate github tokens
1 parent 1213a35 commit 70ec6fc

1 file changed

Lines changed: 48 additions & 32 deletions

File tree

tools/reset_github_user_token_and_update_circleci.sh

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,30 @@
1111
# * CIRCLECI_TOKEN: a CircleCI token for the Exchange organization.
1212
#
1313

14-
if [[ ! $# -eq 1 ]];
14+
if [[ ! $# -gt 0 ]];
1515
then
16-
echo "Usage: $0 <pack>"
16+
echo "Usage: $0 <pack> [<pack> <pack> ...]"
1717
exit 1
1818
fi
1919

20-
PACK="$1"
20+
BROWSER_NAME=firefox
21+
BROWSER="/Applications/Firefox.app/Contents/MacOS/firefox -private-window"
22+
2123
EXCHANGE_ORG="${EXCHANGE_ORG:-StackStorm-Exchange}"
2224
EXCHANGE_PREFIX="${EXCHANGE_PREFIX:-stackstorm}"
23-
# Add the stackstorm- prefix to the repo name if it doesn't exist already
24-
if [[ "$PACK" = ${EXCHANGE_PREFIX}-* ]];
25-
then
26-
REPO_NAME="$PACK"
27-
else
28-
REPO_NAME="${EXCHANGE_PREFIX}-${PACK}"
29-
fi
25+
26+
function repo_name() {
27+
local pack="$1"
28+
local repo_name=""
29+
# Add the stackstorm- prefix to the repo name if it doesn't exist already
30+
if [[ "$pack" = ${EXCHANGE_PREFIX}-* ]];
31+
then
32+
repo_name="$pack"
33+
else
34+
repo_name="${EXCHANGE_PREFIX}-${pack}"
35+
fi
36+
echo ${repo_name}
37+
}
3038

3139
DEFAULT_USERNAME="stackstorm-neptr"
3240
if [[ -z "$USERNAME" ]];
@@ -55,28 +63,36 @@ fi
5563

5664
# GitHub: create a user-scope token
5765
# TODO: Delete any existing token for that repo
58-
echo "Github: Creating a Github user-scoped token"
59-
GITHUB_USER_TOKEN=$(curl -sS --fail -u "${USERNAME}:${PASSWORD}" -X POST \
60-
--header "Content-Type: application/json" \
61-
-d '{"scopes": ["public_repo"], "note": "CircleCI: '"${REPO_NAME}"'"}' \
62-
"https://api.github.com/authorizations" | jq --raw-output ".token")
66+
echo "Github: Creating a Github user-scoped token for each pack"
67+
echo
6368

64-
if [[ -z "$GITHUB_USER_TOKEN" ]];
65-
then
66-
echo "Could not create a GitHub Personal Access Token."
67-
exit 1
68-
fi
69+
for PACK in $@; do
70+
REPO_NAME=$(repo_name ${PACK})
71+
echo "REPO_NAME=${REPO_NAME}"
72+
echo
6973

70-
echo "GitHub Personal Access Token for ${USERNAME}:"
71-
echo
72-
echo " ${GITHUB_USER_TOKEN}"
73-
echo
74+
echo "Please click 'Generate Token' when ${BROWSER_NAME} opens."
75+
echo "Then copy the Github PAT token and paste it here:"
76+
${BROWSER} "https://github.com/settings/tokens/new?scopes=public_repo&description=CircleCI%3A%20${REPO_NAME}"
77+
read -s GITHUB_USER_TOKEN
78+
79+
if [[ -z "$GITHUB_USER_TOKEN" ]];
80+
then
81+
echo "Could not create a GitHub Personal Access Token."
82+
exit 1
83+
fi
84+
85+
echo "GitHub Personal Access Token for ${USERNAME}:"
86+
echo
87+
echo " ${GITHUB_USER_TOKEN}"
88+
echo
7489

75-
# CircleCI: specify the credentials (the machine login and the new user-scope token)
76-
echo "CircleCI: Setting credentials (machine login and user-scoped token)"
77-
curl -sS --fail -X POST --header "Content-Type: application/json" \
78-
-d '{"name":"MACHINE_USER", "value":"'"${USERNAME}"'"}' \
79-
"https://circleci.com/api/v1.1/project/github/${EXCHANGE_ORG}/${REPO_NAME}/envvar?circle-token=${CIRCLECI_TOKEN}"
80-
curl -sS --fail -X POST --header "Content-Type: application/json" \
81-
-d '{"name":"MACHINE_PASSWORD", "value": "'"${GITHUB_USER_TOKEN}"'"}' \
82-
"https://circleci.com/api/v1.1/project/github/${EXCHANGE_ORG}/${REPO_NAME}/envvar?circle-token=${CIRCLECI_TOKEN}"
90+
# CircleCI: specify the credentials (the machine login and the new user-scope token)
91+
echo "CircleCI: Setting credentials (machine login and user-scoped token)"
92+
curl -sS --fail -X POST --header "Content-Type: application/json" \
93+
-d '{"name":"MACHINE_USER", "value":"'"${USERNAME}"'"}' \
94+
"https://circleci.com/api/v1.1/project/github/${EXCHANGE_ORG}/${REPO_NAME}/envvar?circle-token=${CIRCLECI_TOKEN}"
95+
curl -sS --fail -X POST --header "Content-Type: application/json" \
96+
-d '{"name":"MACHINE_PASSWORD", "value": "'"${GITHUB_USER_TOKEN}"'"}' \
97+
"https://circleci.com/api/v1.1/project/github/${EXCHANGE_ORG}/${REPO_NAME}/envvar?circle-token=${CIRCLECI_TOKEN}"
98+
done

0 commit comments

Comments
 (0)