Skip to content

Commit 591fe22

Browse files
committed
Displayed the output variable in the logs
1 parent 2ca62d8 commit 591fe22

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

management_instance/runbooks/shared_scripts/fork_repo_github.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,28 @@ def init_argparse():
8686
usage='%(prog)s [OPTION] [FILE]...',
8787
description='Fork a GitHub repo'
8888
)
89-
parser.add_argument('--new-project-name', action='store',
89+
parser.add_argument('--new-repo-name', action='store',
9090
default=get_octopusvariable_quiet(
91-
'ForkGithubRepo.Exported.Project.Name') or get_octopusvariable_quiet(
91+
'ForkGithubRepo.Git.Url.NewRepoName') or get_octopusvariable_quiet(
9292
'Exported.Project.Name'))
93+
parser.add_argument('--new-repo-name-prefix', action='store',
94+
default=get_octopusvariable_quiet(
95+
'ForkGithubRepo.Git.Url.NewRepoNamePrefix') or get_octopusvariable_quiet(
96+
'Git.Url.NewRepoNamePrefix'))
97+
parser.add_argument('--template-repo-name', action='store',
98+
default=get_octopusvariable_quiet(
99+
'ForkGithubRepo.Original.Project.Name') or
100+
re.sub('[^a-zA-Z0-9-]', '_', get_octopusvariable_quiet('Octopus.Project.Name')))
101+
parser.add_argument('--tenant-name', action='store',
102+
default=get_octopusvariable_quiet('Octopus.Deployment.Tenant.Name'))
103+
parser.add_argument('--git-organization', action='store',
104+
default=get_octopusvariable_quiet(
105+
'ForkGithubRepo.Git.Url.Organization') or get_octopusvariable_quiet('Git.Url.Organization'))
106+
parser.add_argument('--mainline-branch',
107+
action='store',
108+
default=get_octopusvariable_quiet(
109+
'ForkGiteaRepo.Git.Branch.MainLine') or get_octopusvariable_quiet('Git.Branch.MainLine'),
110+
help='The branch name to use for the fork. Defaults to "main".')
93111
parser.add_argument('--github-app-id', action='store',
94112
default=get_octopusvariable_quiet(
95113
'ForkGithubRepo.GitHub.App.Id') or get_octopusvariable_quiet('GitHub.App.Id'))
@@ -106,24 +124,7 @@ def init_argparse():
106124
'ForkGithubRepo.GitHub.Credentials.AccessToken') or get_octopusvariable_quiet(
107125
'GitHub.Credentials.AccessToken'),
108126
help='The GitHub access token. This takes precedence over the --github-app-id, --github-app-installation-id, and --github-app-private-key')
109-
parser.add_argument('--git-organization', action='store',
110-
default=get_octopusvariable_quiet(
111-
'ForkGithubRepo.Git.Url.Organization') or get_octopusvariable_quiet('Git.Url.Organization'))
112-
parser.add_argument('--tenant-name', action='store',
113-
default=get_octopusvariable_quiet('Octopus.Deployment.Tenant.Name'))
114-
parser.add_argument('--new-repo-name-prefix', action='store',
115-
default=get_octopusvariable_quiet(
116-
'ForkGithubRepo.Git.Url.NewRepoNamePrefix') or get_octopusvariable_quiet(
117-
'Git.Url.NewRepoNamePrefix'))
118-
parser.add_argument('--template-repo-name', action='store',
119-
default=get_octopusvariable_quiet(
120-
'ForkGithubRepo.Original.Project.Name') or
121-
re.sub('[^a-zA-Z0-9-]', '_', get_octopusvariable_quiet('Octopus.Project.Name')))
122-
parser.add_argument('--mainline-branch',
123-
action='store',
124-
default=get_octopusvariable_quiet(
125-
'ForkGiteaRepo.Git.Branch.MainLine') or get_octopusvariable_quiet('Git.Branch.MainLine'),
126-
help='The branch name to use for the fork. Defaults to "main".')
127+
127128
return parser.parse_known_args()
128129

129130

@@ -310,14 +311,14 @@ def ensure_git_exists():
310311
template_repo = parser.template_repo_name.strip()
311312
new_repo_custom_prefix = re.sub('[^a-zA-Z0-9-]', '_', parser.new_repo_name_prefix.strip())
312313
tenant_name_sanitized = re.sub('[^a-zA-Z0-9-]', '_', parser.tenant_name.strip())
313-
project_name_sanitized = re.sub('[^a-zA-Z0-9-]', '_',
314-
parser.new_project_name.strip() if parser.new_project_name.strip() else template_repo)
314+
project_repo_sanitized = re.sub('[^a-zA-Z0-9-]', '_',
315+
parser.new_repo_name.strip() if parser.new_repo_name.strip() else template_repo)
315316

316317
# The new repo is prefixed either with the custom prefix or the tenant name if no custom prefix is defined
317318
new_repo_prefix = new_repo_custom_prefix if len(new_repo_custom_prefix) != 0 else tenant_name_sanitized
318319

319320
# The new repo name is the prefix + the name of thew new project
320-
new_repo = new_repo_prefix + '_' + project_name_sanitized if len(new_repo_prefix) != 0 else project_name_sanitized
321+
new_repo = new_repo_prefix + '_' + project_repo_sanitized if len(new_repo_prefix) != 0 else project_repo_sanitized
321322

322323
# Assume the main branch if nothing else was specified
323324
branch = parser.mainline_branch or 'main'
@@ -335,3 +336,6 @@ def ensure_git_exists():
335336
+ 'https://github.com/' + cac_org + '/' + new_repo)
336337
else:
337338
print('Repo at https://github.com/' + cac_org + '/' + new_repo + ' already exists and has not been modified')
339+
340+
print('New repo URL is defined in the output variable "NewRepo": #{Octopus.Action[' +
341+
get_octopusvariable_quiet('Octopus.Step.Name') + '].Output.NewRepo}')

0 commit comments

Comments
 (0)