Skip to content

Commit

Permalink
DEVOPS-261 improving create repo automation
Browse files Browse the repository at this point in the history
  • Loading branch information
githubofkrishnadhas committed Jul 15, 2024
1 parent b02a01c commit bf5e37c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/create_repository.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ on:
gitignore_template:
type: choice
options:
- None
- AL
- Actionscript
- Ada
Expand Down Expand Up @@ -176,6 +177,7 @@ on:
description: 'Choose license template'
type: choice
options:
- None
- AFL-3.0
- Apache-2.0
- Artistic-2.0
Expand Down
30 changes: 28 additions & 2 deletions create_repository_in_github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,36 @@ HAS_WIKI=$8
GITIGNORE_TEMPLATE=$9
LICENSE_TEMPLATE=${10}

curl -L \
# Construct the JSON payload
JSON_PAYLOAD="{\"name\":\"$REPOSITORY_NAME\",\"description\":\"$REPOSITORY_DESCRIPTION\",\"homepage\":\"https://github.com/$ORGANIZATION/$REPOSITORY_NAME\",\"auto_init\":true,\"private\":$PRIVATE,\"has_issues\":$HAS_ISSUES,\"visibility\":\"$VISIBILITY\",\"has_projects\":$HAS_PROJECTS,\"has_wiki\":$HAS_WIKI"

# Add gitignore_template if it is not "None"
if [ "$GITIGNORE_TEMPLATE" != "None" ]; then
JSON_PAYLOAD="$JSON_PAYLOAD,\"gitignore_template\":\"$GITIGNORE_TEMPLATE\""
fi

# Add license_template if it is not "None"
if [ "$LICENSE_TEMPLATE" != "None" ]; then
JSON_PAYLOAD="$JSON_PAYLOAD,\"license_template\":\"$LICENSE_TEMPLATE\""
fi

# Close the JSON payload
JSON_PAYLOAD="$JSON_PAYLOAD}"

# Execute the curl command
response=$(curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/$ORGANIZATION/repos \
-d "{\"name\":\"$REPOSITORY_NAME\",\"description\":\"$REPOSITORY_DESCRIPTION\",\"homepage\":\"https://github.com/$ORGANIZATION/$REPOSITORY_NAME\",\"auto_init\":true,\"private\":$PRIVATE,\"has_issues\":$HAS_ISSUES,\"visibility\":\"$VISIBILITY\",\"has_projects\":$HAS_PROJECTS,\"has_wiki\":$HAS_WIKI,\"gitignore_template\":\"$GITIGNORE_TEMPLATE\",\"license_template\":\"$LICENSE_TEMPLATE\"}"
-d "$JSON_PAYLOAD" -w "%{http_code}")

# Extract the HTTP status code from the response
http_code=$(echo "$response" | tail -n1)

if [ "$http_code" -eq 201 ]; then
echo "Repository - $2 created "
else
echo "Failed with status code: $http_code"
fi

0 comments on commit bf5e37c

Please sign in to comment.