Skip to content

Commit 47311b7

Browse files
committed
Add location variable
1 parent 8a1b8e5 commit 47311b7

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

gh-doccs

+12-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77

88
set -e
99

10-
SCRIPTNAME=$(basename "$0" .sh)
10+
SCRIPTNAME=$(basename "$0" .sh) # The name of this script. Don't alter this line.
1111
REPO="github/docs-internal"
1212
DEVCONTAINER=".devcontainer/devcontainer.json"
1313
TIMEOUT="3h"
1414
MACHINE="xLargePremiumLinux" # To list available machine types for a repo use:
1515
# gh api --jq ".machines[].name" repos/OWNER/REPONAME/codespaces/machines
16+
LOCATION="" # e.g. EastUs|SouthEastAsia|WestEurope|WestUs2
17+
# Leave empty for automatic location selection.
18+
# To list current available locations see: gh cs create --help
1619
RETENTION="720h"
1720
OPEN_IN_BROWSER=false # Set to true to open the codespace in a browser, or false to open in VS Code.
1821
REQUEST_BRANCH=true # Set to true to request a branch name, or false to use the default branch.
@@ -59,22 +62,28 @@ fi
5962

6063
CREATE_COMMAND="gh cs create -R $REPO --devcontainer-path $DEVCONTAINER -d '$DISPLAYNAME' --idle-timeout $TIMEOUT -m $MACHINE --retention-period $RETENTION"
6164

65+
echo
6266
if [[ "$BRANCH" =~ ( |\') ]]
6367
then
6468
echo "Branch names cannot contain spaces or single quotes."
6569
exit 1
6670
elif [ ! -z ${BRANCH+x} ] && [ -n "$BRANCH" ] # If BRANCH is set and not empty
6771
then
6872
CREATE_COMMAND="$CREATE_COMMAND -b $BRANCH"
69-
echo "CREATE_COMMAND is $CREATE_COMMAND"
7073
# Get the SHA for the default branch:
7174
SHA=$(eval "gh api repos/$REPO/git/ref/heads/main --jq .object.sha")
7275
# Create a remote branch
7376
API_CALL="gh api --method POST -H \"Accept: application/vnd.github+json\" /repos/$REPO/git/refs -f ref=\"refs/heads/$BRANCH\" -f sha=\"$SHA\""
74-
echo; echo $API_CALL
77+
echo $API_CALL
7578
eval $API_CALL > /dev/null
7679
fi
7780

81+
if [ -n "$LOCATION" ] # If LOCATION is not an empty string
82+
then
83+
CREATE_COMMAND="$CREATE_COMMAND -l $LOCATION"
84+
fi
85+
86+
# Print the command we're about to run:
7887
echo $CREATE_COMMAND; echo
7988
OUTPUT=$(eval $CREATE_COMMAND)
8089

0 commit comments

Comments
 (0)