Skip to content

Commit aec3562

Browse files
Feature/improve automation (#4)
* DEVOPS-261 improving create repo automation * DEVOPS-261 added status badge for runs
1 parent b02a01c commit aec3562

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

.github/workflows/create_repository.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ on:
4141
gitignore_template:
4242
type: choice
4343
options:
44+
- None
4445
- AL
4546
- Actionscript
4647
- Ada
@@ -176,6 +177,7 @@ on:
176177
description: 'Choose license template'
177178
type: choice
178179
options:
180+
- None
179181
- AFL-3.0
180182
- Apache-2.0
181183
- Artistic-2.0

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# create-github-repository
22
create-github-repository using automation
33

4+
[![create-github-repository-using-github-workflow](https://github.com/devwithkrishna/create-github-repository/actions/workflows/create_repository.yaml/badge.svg)](https://github.com/devwithkrishna/create-github-repository/actions/workflows/create_repository.yaml)
5+
46
* This is using a github workflow to create a repositiry in a organization
57

68
* The credential used is ``` PERSONAL ACCESS TOKEN ```

create_repository_in_github.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,36 @@ HAS_WIKI=$8
1212
GITIGNORE_TEMPLATE=$9
1313
LICENSE_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

Comments
 (0)