|
7 | 7 |
|
8 | 8 | set -e
|
9 | 9 |
|
10 |
| -SCRIPTNAME=$(basename "$0" .sh) |
| 10 | +SCRIPTNAME=$(basename "$0" .sh) # The name of this script. Don't alter this line. |
11 | 11 | REPO="github/docs-internal"
|
12 | 12 | DEVCONTAINER=".devcontainer/devcontainer.json"
|
13 | 13 | TIMEOUT="3h"
|
14 | 14 | MACHINE="xLargePremiumLinux" # To list available machine types for a repo use:
|
15 | 15 | # 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 |
16 | 19 | RETENTION="720h"
|
17 | 20 | OPEN_IN_BROWSER=false # Set to true to open the codespace in a browser, or false to open in VS Code.
|
18 | 21 | REQUEST_BRANCH=true # Set to true to request a branch name, or false to use the default branch.
|
|
59 | 62 |
|
60 | 63 | CREATE_COMMAND="gh cs create -R $REPO --devcontainer-path $DEVCONTAINER -d '$DISPLAYNAME' --idle-timeout $TIMEOUT -m $MACHINE --retention-period $RETENTION"
|
61 | 64 |
|
| 65 | +echo |
62 | 66 | if [[ "$BRANCH" =~ ( |\') ]]
|
63 | 67 | then
|
64 | 68 | echo "Branch names cannot contain spaces or single quotes."
|
65 | 69 | exit 1
|
66 | 70 | elif [ ! -z ${BRANCH+x} ] && [ -n "$BRANCH" ] # If BRANCH is set and not empty
|
67 | 71 | then
|
68 | 72 | CREATE_COMMAND="$CREATE_COMMAND -b $BRANCH"
|
69 |
| - echo "CREATE_COMMAND is $CREATE_COMMAND" |
70 | 73 | # Get the SHA for the default branch:
|
71 | 74 | SHA=$(eval "gh api repos/$REPO/git/ref/heads/main --jq .object.sha")
|
72 | 75 | # Create a remote branch
|
73 | 76 | 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 |
75 | 78 | eval $API_CALL > /dev/null
|
76 | 79 | fi
|
77 | 80 |
|
| 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: |
78 | 87 | echo $CREATE_COMMAND; echo
|
79 | 88 | OUTPUT=$(eval $CREATE_COMMAND)
|
80 | 89 |
|
|
0 commit comments