Skip to content

Add a hidden push option for specifying the destination Git URL #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var pushCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
version.LogVersion()
cacheDirectory := cachedirectory.NewCacheDirectory(rootFlags.cacheDir)
return push.Push(cmd.Context(), cacheDirectory, pushFlags.destinationURL, pushFlags.destinationToken, pushFlags.destinationRepository, pushFlags.actionsAdminUser, pushFlags.force, pushFlags.pushSSH)
return push.Push(cmd.Context(), cacheDirectory, pushFlags.destinationURL, pushFlags.destinationToken, pushFlags.destinationRepository, pushFlags.actionsAdminUser, pushFlags.force, pushFlags.pushSSH, pushFlags.gitURL)
},
}

Expand All @@ -27,6 +27,7 @@ type pushFlagFields struct {
actionsAdminUser string
force bool
pushSSH bool
gitURL string
}

var pushFlags = pushFlagFields{}
Expand All @@ -45,4 +46,6 @@ func (f *pushFlagFields) Init(cmd *cobra.Command) {
cmd.Flags().StringVar(&f.actionsAdminUser, "actions-admin-user", "actions-admin", "The name of the Actions admin user.")
cmd.Flags().BoolVar(&f.force, "force", false, "Replace the existing repository even if it was not created by the sync tool.")
cmd.Flags().BoolVar(&f.pushSSH, "push-ssh", false, "Push Git contents over SSH rather than HTTPS. To use this option you must have SSH access to your GitHub Enterprise instance configured.")
cmd.Flags().StringVar(&f.gitURL, "git-url", "", "Use a custom Git URL for pushing the Action repository contents to.")
cmd.Flags().MarkHidden("git-url")
}
2 changes: 1 addition & 1 deletion cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var syncCmd = &cobra.Command{
if err != nil {
return err
}
err = push.Push(cmd.Context(), cacheDirectory, pushFlags.destinationURL, pushFlags.destinationToken, pushFlags.destinationRepository, pushFlags.actionsAdminUser, pushFlags.force, pushFlags.pushSSH)
err = push.Push(cmd.Context(), cacheDirectory, pushFlags.destinationURL, pushFlags.destinationToken, pushFlags.destinationRepository, pushFlags.actionsAdminUser, pushFlags.force, pushFlags.pushSSH, pushFlags.gitURL)
if err != nil {
return err
}
Expand Down
13 changes: 9 additions & 4 deletions internal/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type pushService struct {
aegis bool
force bool
pushSSH bool
gitURL string
}

func (pushService *pushService) createRepository() (*github.Repository, error) {
Expand Down Expand Up @@ -163,9 +164,12 @@ func (pushService *pushService) createRepository() (*github.Repository, error) {
}

func (pushService *pushService) pushGit(repository *github.Repository, initialPush bool) error {
remoteURL := repository.GetCloneURL()
if pushService.pushSSH {
remoteURL = repository.GetSSHURL()
remoteURL := pushService.gitURL
if remoteURL == "" {
remoteURL = repository.GetCloneURL()
if pushService.pushSSH {
remoteURL = repository.GetSSHURL()
}
}
if initialPush {
log.Debugf("Pushing Git releases to %s...", remoteURL)
Expand Down Expand Up @@ -366,7 +370,7 @@ func (pushService *pushService) pushReleases() error {
return nil
}

func Push(ctx context.Context, cacheDirectory cachedirectory.CacheDirectory, destinationURL string, destinationToken string, destinationRepository string, actionsAdminUser string, force bool, pushSSH bool) error {
func Push(ctx context.Context, cacheDirectory cachedirectory.CacheDirectory, destinationURL string, destinationToken string, destinationRepository string, actionsAdminUser string, force bool, pushSSH bool, gitURL string) error {
err := cacheDirectory.CheckOrCreateVersionFile(false, version.Version())
if err != nil {
return err
Expand Down Expand Up @@ -424,6 +428,7 @@ func Push(ctx context.Context, cacheDirectory cachedirectory.CacheDirectory, des
aegis: aegis,
force: force,
pushSSH: pushSSH,
gitURL: gitURL,
}

repository, err := pushService.createRepository()
Expand Down