diff --git a/.github/workflows/create_repository.yaml b/.github/workflows/create_repository.yaml index e0f4784..370256b 100644 --- a/.github/workflows/create_repository.yaml +++ b/.github/workflows/create_repository.yaml @@ -41,6 +41,7 @@ on: gitignore_template: type: choice options: + - None - AL - Actionscript - Ada @@ -176,6 +177,7 @@ on: description: 'Choose license template' type: choice options: + - None - AFL-3.0 - Apache-2.0 - Artistic-2.0 diff --git a/create_repository_in_github.sh b/create_repository_in_github.sh index f0258e8..04e2d0e 100644 --- a/create_repository_in_github.sh +++ b/create_repository_in_github.sh @@ -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 \ No newline at end of file