Skip to content

Commit 5526f72

Browse files
feat(BUILD-4994): add link to repo
1 parent 27f8663 commit 5526f72

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

action.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ inputs:
5151
description: 'Whether to create a Port entity for the repository'
5252
required: false
5353
default: "true"
54+
addLinkToPort:
55+
description: 'Whether to add a link to the repository in Port'
56+
required: false
57+
default: "true"
58+
outputs:
59+
repoURL:
60+
description: 'The URL of the created repository'
5461
runs:
5562
using: docker
5663
image: Dockerfile

entrypoint.sh

+19-12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ scaffold_directory="$INPUT_SCAFFOLDDIRECTORY"
1818
create_port_entity="$INPUT_CREATEPORTENTITY"
1919
branch_name="port_$port_run_id"
2020
git_url="$INPUT_GITHUBURL"
21+
repo_url="https://github.com/$org_name/$repository_name"
22+
add_link_to_port="$INPUT_ADDLINKTOPORT"
2123

2224
get_access_token() {
2325
curl --silent --show-error --location --request POST 'https://api.getport.io/v1/auth/access_token' --header 'Content-Type: application/json' --data-raw "{
@@ -27,7 +29,7 @@ get_access_token() {
2729
}
2830

2931
send_log() {
30-
message=$1
32+
local message=$1
3133
if [[ -n $port_run_id ]]; then
3234
curl --silent --show-error --location "https://api.getport.io/v1/actions/runs/$port_run_id/logs" \
3335
--header "Authorization: Bearer $access_token" \
@@ -41,12 +43,16 @@ send_log() {
4143
}
4244

4345
add_link() {
44-
url=$1
46+
if [[ "$add_link_to_port" != "true" ]]; then
47+
echo "Skipping adding link to Port"
48+
return
49+
fi
50+
local link_url=$1
4551
curl --silent --show-error --request PATCH --location "https://api.getport.io/v1/actions/runs/$port_run_id" \
4652
--header "Authorization: Bearer $access_token" \
4753
--header "Content-Type: application/json" \
4854
--data "{
49-
\"link\": \"$url\"
55+
\"link\": \"$link_url\"
5056
}"
5157
}
5258

@@ -113,22 +119,23 @@ apply_cookiecutter_template() {
113119
}
114120

115121
push_to_repository() {
122+
local default_branch="master"
116123
if [ -n "$monorepo_url" ] && [ -n "$scaffold_directory" ]; then
117124
git config user.name "GitHub Actions Bot"
118125
git config user.email "github-actions[bot]@users.noreply.github.com"
119126
git add .
120127
git commit -m "Scaffolded project in $scaffold_directory"
121128
git push -u origin "$branch_name"
122129

123-
send_log "Creating pull request to merge $branch_name into master 🚢"
130+
send_log "Creating pull request to merge $branch_name into $default_branch 🚢"
124131

125132
owner=$(echo "$monorepo_url" | awk -F'/' '{print $4}')
126133
repo=$(echo "$monorepo_url" | awk -F'/' '{print $5}')
127134

128135
echo "Owner: $owner"
129136
echo "Repo: $repo"
130137

131-
PR_PAYLOAD=$(jq -n --arg title "Scaffolded project in $repo" --arg head "$branch_name" --arg base "master" '{
138+
PR_PAYLOAD=$(jq -n --arg title "Scaffolded project in $repo" --arg head "$branch_name" --arg base "$default_branch" '{
132139
"title": $title,
133140
"head": $head,
134141
"base": $base
@@ -152,9 +159,10 @@ push_to_repository() {
152159
git config user.email "github-actions[bot]@users.noreply.github.com"
153160
git add .
154161
git commit -m "Initial commit after scaffolding"
155-
git branch -M master
162+
git branch -M $default_branch
156163
git remote add origin "https://oauth2:$github_token@github.com/$org_name/$repository_name.git"
157-
git push -u origin master
164+
git push -u origin $default_branch
165+
add_link "$repo_url"
158166
fi
159167
}
160168

@@ -175,7 +183,7 @@ main() {
175183
if [ -z "$monorepo_url" ] || [ -z "$scaffold_directory" ]; then
176184
send_log "Creating a new repository: $repository_name 🏃"
177185
create_repository
178-
send_log "Created a new repository at https://github.com/$org_name/$repository_name 🚀"
186+
send_log "New repository created: $repo_url 🚀"
179187
else
180188
send_log "Using monorepo scaffolding 🏃"
181189
clone_monorepo
@@ -185,11 +193,9 @@ main() {
185193

186194
send_log "Starting templating with cookiecutter 🍪"
187195
apply_cookiecutter_template
188-
send_log "Pushing the template into the repository ⬆️"
196+
send_log "Pushing the template into the repository."
189197
push_to_repository
190198

191-
url="https://github.com/$org_name/$repository_name"
192-
193199
if [[ "$create_port_entity" == "true" ]]; then
194200
send_log "Reporting to Port the new entity created 🚢"
195201
report_to_port
@@ -200,8 +206,9 @@ main() {
200206
if [ -n "$monorepo_url" ] && [ -n "$scaffold_directory" ]; then
201207
send_log "Finished! 🏁✅"
202208
else
203-
send_log "Finished! Visit $url 🏁✅"
209+
send_log "Finished! Visit $repo_url 🏁✅"
204210
fi
211+
echo "repoURL=$repo_url" >>"$GITHUB_OUTPUT"
205212
}
206213

207214
main

0 commit comments

Comments
 (0)