Skip to content

Commit

Permalink
scripts/bumper: allow fetching using https
Browse files Browse the repository at this point in the history
In a container, trying to fetch using git over ssh goes south super
quickly. In other contexts we always fetch using https to make our lives
easier.

Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
  • Loading branch information
stevekuznetsov committed Sep 9, 2023
1 parent 6799db7 commit d54b806
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions scripts/bumper/main.go
Expand Up @@ -32,6 +32,13 @@ const (
publish mode = "publish"
)

type fetchMode string

const (
https fetchMode = "https"
ssh fetchMode = "ssh"
)

const (
githubOrg = "openshift"
githubRepo = "operator-framework-olm"
Expand All @@ -49,6 +56,7 @@ type options struct {
mode string
logLevel string
centralRef string
fetchMode string

dryRun bool
githubLogin string
Expand All @@ -71,6 +79,7 @@ func (o *options) Bind(fs *flag.FlagSet) {
fs.StringVar(&o.commitFileInput, "commits-input", "", "File to read commits data from in order to drive sync process.")
fs.StringVar(&o.logLevel, "log-level", logrus.InfoLevel.String(), "Logging level.")
fs.StringVar(&o.centralRef, "central-ref", "origin/master", "Git ref for the central branch that will be updated, used as the base for determining what commits need to be cherry-picked.")
fs.StringVar(&o.fetchMode, "fetch-mode", string(ssh), "Method to use for fetching from git remotes.")

fs.BoolVar(&o.dryRun, "dry-run", true, "Whether to actually create the pull request with github client")
fs.StringVar(&o.githubLogin, "github-login", githubLogin, "The GitHub username to use.")
Expand All @@ -93,6 +102,12 @@ func (o *options) Validate() error {
return fmt.Errorf("--mode must be one of %v", []mode{summarize, synchronize})
}

switch fetchMode(o.fetchMode) {
case ssh, https:
default:
return fmt.Errorf("--mode must be one of %v", []fetchMode{https, ssh})
}

if _, err := logrus.ParseLevel(o.logLevel); err != nil {
return fmt.Errorf("--log-level invalid: %w", err)
}
Expand Down Expand Up @@ -150,7 +165,7 @@ func main() {
logrus.WithError(err).Fatal("could not unmarshal input commits")
}
} else {
commits, err = detectNewCommits(ctx, logger.WithField("phase", "detect"), opts.stagingDir, opts.centralRef)
commits, err = detectNewCommits(ctx, logger.WithField("phase", "detect"), opts.stagingDir, opts.centralRef, fetchMode(opts.fetchMode))
if err != nil {
logger.WithError(err).Fatal("failed to detect commits")
}
Expand Down Expand Up @@ -250,7 +265,7 @@ type commit struct {
var repoRegex = regexp.MustCompile(`Upstream-repository: ([^ ]+)\n`)
var commitRegex = regexp.MustCompile(`Upstream-commit: ([a-f0-9]+)\n`)

func detectNewCommits(ctx context.Context, logger *logrus.Entry, stagingDir, centralRef string) ([]commit, error) {
func detectNewCommits(ctx context.Context, logger *logrus.Entry, stagingDir, centralRef string, mode fetchMode) ([]commit, error) {
lastCommits := map[string]string{}
if err := fs.WalkDir(os.DirFS(stagingDir), ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
Expand Down Expand Up @@ -301,9 +316,16 @@ func detectNewCommits(ctx context.Context, logger *logrus.Entry, stagingDir, cen

var commits []commit
for repo, lastCommit := range lastCommits {
var remote string
switch mode {
case ssh:
remote = "git@github.com:operator-framework/" + repo
case https:
remote = "https://github.com/operator-framework/" + repo + ".git"
}
if _, err := runCommand(logger, exec.CommandContext(ctx,
"git", "fetch",
"git@github.com:operator-framework/"+repo,
remote,
"master",
)); err != nil {
return nil, err
Expand Down

0 comments on commit d54b806

Please sign in to comment.