Skip to content

Commit

Permalink
Setup exisitng bumpers to use new autobumper
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperMalachowski committed Oct 21, 2024
1 parent a040aba commit 5240a15
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/image-autobumper/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ LABEL io.kyma-project.source=github.com/kyma-project/test-infra/cmd/image-autobu
# Copy the built Go app from the builder stage
COPY --from=builder /app/cmd/image-autobumper/main /image-autobumper

RUN apk add --no-cache ca-certificates && \
RUN apk add --no-cache ca-certificates git && \
chmod +x /image-autobumper
ENTRYPOINT ["/image-autobumper"]
4 changes: 2 additions & 2 deletions cmd/image-autobumper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ func (c *client) Changes() []func(context.Context) (string, []string, error) {
}

// PRTitleBody returns the body of the PR, this function runs after each commit
func (c *client) PRTitleBody() (string, string, error) {
func (c *client) PRTitleBody() (string, string) {
body := generatePRBody(c.images, c.o.Prefixes)
if c.o.AdditionalPRBody != "" {
body += c.o.AdditionalPRBody + "\n"
}
return makeCommitSummary(c.o.Prefixes, c.versions), body, nil
return makeCommitSummary(c.o.Prefixes, c.versions), body
}

var rootCmd = &cobra.Command{
Expand Down
4 changes: 2 additions & 2 deletions cmd/image-detector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func (c *client) Changes() []func(context.Context) (string, []string, error) {
}

// PRTitleBody returns the body of the PR, this function runs after each commit
func (c *client) PRTitleBody() (string, string, error) {
return "Update sec-scanners-config.yaml", "", nil
func (c *client) PRTitleBody() (string, string) {
return "Update sec-scanners-config.yaml", ""
}

// options is the options for autobumper operations.
Expand Down
4 changes: 2 additions & 2 deletions cmd/markdown-index/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func (c *client) Changes() []func(context.Context) (string, []string, error) {
}

// PRTitleBody returns the body of the PR, this function runs after each commit
func (c *client) PRTitleBody() (string, string, error) {
return "Update index.md", "", nil
func (c *client) PRTitleBody() (string, string) {
return "Update index.md", ""
}

// options is the options for autobumper operations.
Expand Down
20 changes: 15 additions & 5 deletions pkg/github/bumper/bumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ type Options struct {
// manipulating the repo, and provides commit messages, PR title and body.
type PRHandler interface {
// Changes returns a slice of functions, each one does some stuff, and
// returns commit message for the changes
Changes() []func(context.Context) (string, error)
// returns commit message for the changes and list of files that should be added to commit
Changes() []func(context.Context) (string, []string, error)
// PRTitleBody returns the body of the PR, this function runs after all
// changes have been executed
PRTitleBody() (string, string)
Expand Down Expand Up @@ -212,7 +212,7 @@ func processGitHub(ctx context.Context, o *Options, prh PRHandler) error {
// Make change, commit and push
var anyChange bool
for i, changeFunc := range prh.Changes() {
msg, err := changeFunc(ctx)
msg, files, err := changeFunc(ctx)
if err != nil {
return fmt.Errorf("process function %d: %w", i, err)
}
Expand All @@ -227,6 +227,10 @@ func processGitHub(ctx context.Context, o *Options, prh PRHandler) error {
continue
}

if err := gitAdd(files, stdout, stderr); err != nil {
return fmt.Errorf("git add: %w", err)
}

anyChange = true
if err := gitCommit(o.GitName, o.GitEmail, msg, stdout, stderr, o.Signoff); err != nil {
return fmt.Errorf("git commit: %w", err)
Expand Down Expand Up @@ -357,10 +361,16 @@ func HasChanges(o *Options) (bool, error) {
return hasChanges, nil
}

func gitCommit(name, email, message string, stdout, stderr io.Writer, signoff bool) error {
if err := Call(stdout, stderr, gitCmd, []string{"add", "-A"}); err != nil {
func gitAdd(files []string, stdout, stderr io.Writer) error {
args := []string{"add"}
args = append(args, files...)
if err := Call(stdout, stderr, gitCmd, args); err != nil {
return fmt.Errorf("git add: %w", err)
}
return nil
}

func gitCommit(name, email, message string, stdout, stderr io.Writer, signoff bool) error {
commitArgs := []string{"commit", "-m", message}
if name != "" && email != "" {
commitArgs = append(commitArgs, "--author", fmt.Sprintf("%s <%s>", name, email))
Expand Down

0 comments on commit 5240a15

Please sign in to comment.