@@ -86,10 +86,28 @@ def init_argparse():
86
86
usage = '%(prog)s [OPTION] [FILE]...' ,
87
87
description = 'Fork a GitHub repo'
88
88
)
89
- parser .add_argument ('--new-project -name' , action = 'store' ,
89
+ parser .add_argument ('--new-repo -name' , action = 'store' ,
90
90
default = get_octopusvariable_quiet (
91
- 'ForkGithubRepo.Exported.Project.Name ' ) or get_octopusvariable_quiet (
91
+ 'ForkGithubRepo.Git.Url.NewRepoName ' ) or get_octopusvariable_quiet (
92
92
'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".' )
93
111
parser .add_argument ('--github-app-id' , action = 'store' ,
94
112
default = get_octopusvariable_quiet (
95
113
'ForkGithubRepo.GitHub.App.Id' ) or get_octopusvariable_quiet ('GitHub.App.Id' ))
@@ -106,24 +124,7 @@ def init_argparse():
106
124
'ForkGithubRepo.GitHub.Credentials.AccessToken' ) or get_octopusvariable_quiet (
107
125
'GitHub.Credentials.AccessToken' ),
108
126
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
+
127
128
return parser .parse_known_args ()
128
129
129
130
@@ -310,14 +311,14 @@ def ensure_git_exists():
310
311
template_repo = parser .template_repo_name .strip ()
311
312
new_repo_custom_prefix = re .sub ('[^a-zA-Z0-9-]' , '_' , parser .new_repo_name_prefix .strip ())
312
313
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 )
315
316
316
317
# The new repo is prefixed either with the custom prefix or the tenant name if no custom prefix is defined
317
318
new_repo_prefix = new_repo_custom_prefix if len (new_repo_custom_prefix ) != 0 else tenant_name_sanitized
318
319
319
320
# 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
321
322
322
323
# Assume the main branch if nothing else was specified
323
324
branch = parser .mainline_branch or 'main'
@@ -335,3 +336,6 @@ def ensure_git_exists():
335
336
+ 'https://github.com/' + cac_org + '/' + new_repo )
336
337
else :
337
338
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