@@ -12,10 +12,36 @@ HAS_WIKI=$8
1212GITIGNORE_TEMPLATE=$9
1313LICENSE_TEMPLATE=${10}
1414
15- curl -L \
15+ # Construct the JSON payload
16+ 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 "
17+
18+ # Add gitignore_template if it is not "None"
19+ if [ " $GITIGNORE_TEMPLATE " != " None" ]; then
20+ JSON_PAYLOAD=" $JSON_PAYLOAD ,\" gitignore_template\" :\" $GITIGNORE_TEMPLATE \" "
21+ fi
22+
23+ # Add license_template if it is not "None"
24+ if [ " $LICENSE_TEMPLATE " != " None" ]; then
25+ JSON_PAYLOAD=" $JSON_PAYLOAD ,\" license_template\" :\" $LICENSE_TEMPLATE \" "
26+ fi
27+
28+ # Close the JSON payload
29+ JSON_PAYLOAD=" $JSON_PAYLOAD }"
30+
31+ # Execute the curl command
32+ response=$( curl -L \
1633 -X POST \
1734 -H " Accept: application/vnd.github+json" \
1835 -H " Authorization: Bearer $GH_TOKEN " \
1936 -H " X-GitHub-Api-Version: 2022-11-28" \
2037 https://api.github.com/orgs/$ORGANIZATION /repos \
21- -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 \" }"
38+ -d " $JSON_PAYLOAD " -w " %{http_code}" )
39+
40+ # Extract the HTTP status code from the response
41+ http_code=$( echo " $response " | tail -n1)
42+
43+ if [ " $http_code " -eq 201 ]; then
44+ echo " Repository - $2 created "
45+ else
46+ echo " Failed with status code: $http_code "
47+ fi
0 commit comments