Skip to content

Commit

Permalink
Merge pull request #62 from github/source-url-flag
Browse files Browse the repository at this point in the history
Add a hidden flag to fetch from an alternative Git source.
  • Loading branch information
chrisgavin authored Mar 23, 2022
2 parents 1890f26 + 1e04ff2 commit 06cf2d3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 4 additions & 1 deletion cmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ var pullCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
version.LogVersion()
cacheDirectory := cachedirectory.NewCacheDirectory(rootFlags.cacheDir)
return pull.Pull(cmd.Context(), cacheDirectory, pullFlags.sourceToken)
return pull.Pull(cmd.Context(), cacheDirectory, pullFlags.sourceToken, pullFlags.sourceURL)
},
}

type pullFlagFields struct {
sourceToken string
sourceURL string
}

var pullFlags = pullFlagFields{}

func (f *pullFlagFields) Init(cmd *cobra.Command) {
cmd.Flags().StringVar(&f.sourceToken, "source-token", "", "A token to access the API of GitHub.com. This is normally not required, but can be provided if you have issues with API rate limiting.")
cmd.Flags().StringVar(&f.sourceURL, "source-url", "", "Use a custom Git URL for fetching the Action repository contents from. The CodeQL bundles will still be fetched from GitHub.com.")
cmd.Flags().MarkHidden("source-url")
}
2 changes: 1 addition & 1 deletion cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var syncCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
version.LogVersion()
cacheDirectory := cachedirectory.NewCacheDirectory(rootFlags.cacheDir)
err := pull.Pull(cmd.Context(), cacheDirectory, pullFlags.sourceToken)
err := pull.Pull(cmd.Context(), cacheDirectory, pullFlags.sourceToken, pullFlags.sourceURL)
if err != nil {
return err
}
Expand Down
8 changes: 6 additions & 2 deletions internal/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

const sourceOwner = "github"
const sourceRepository = "codeql-action"
const sourceURL = "https://github.com/" + sourceOwner + "/" + sourceRepository + ".git"
const defaultSourceURL = "https://github.com/" + sourceOwner + "/" + sourceRepository + ".git"

var relevantReferences = regexp.MustCompile("^refs/(heads|tags)/(main|v\\d+)$")

Expand Down Expand Up @@ -254,7 +254,7 @@ func (pullService *pullService) pullReleases() error {
return nil
}

func Pull(ctx context.Context, cacheDirectory cachedirectory.CacheDirectory, sourceToken string) error {
func Pull(ctx context.Context, cacheDirectory cachedirectory.CacheDirectory, sourceToken string, sourceURL string) error {
err := cacheDirectory.CheckOrCreateVersionFile(true, version.Version())
if err != nil {
return err
Expand All @@ -272,6 +272,10 @@ func Pull(ctx context.Context, cacheDirectory cachedirectory.CacheDirectory, sou
tokenClient = oauth2.NewClient(ctx, tokenSource)
}

if sourceURL == "" {
sourceURL = defaultSourceURL
}

pullService := pullService{
ctx: ctx,
cacheDirectory: cacheDirectory,
Expand Down

0 comments on commit 06cf2d3

Please sign in to comment.