Skip to content

Commit

Permalink
Merge pull request #64 from github/git-url
Browse files Browse the repository at this point in the history
Add a hidden push option for specifying the destination Git URL
  • Loading branch information
chrisgavin authored Apr 6, 2022
2 parents 55fba50 + cf7bdeb commit 6ac01ae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
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 @@ -375,7 +379,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 @@ -433,6 +437,7 @@ func Push(ctx context.Context, cacheDirectory cachedirectory.CacheDirectory, des
aegis: aegis,
force: force,
pushSSH: pushSSH,
gitURL: gitURL,
}

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

0 comments on commit 6ac01ae

Please sign in to comment.