Skip to content

Commit

Permalink
Add support for merge group in image-builder
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperMalachowski committed Nov 19, 2024
1 parent 83bff6a commit 904b2e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
17 changes: 16 additions & 1 deletion cmd/image-builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,21 @@ func loadGithubActionsGitState() (GitStateConfig, error) {
BaseCommitRef: gitRef,
}, nil

case "merge_group":
var payload github.MergeGroupEvent
err = json.Unmarshal(data, &payload)
if err != nil {
return GitStateConfig{}, fmt.Errorf("failed to parse event payload: %s", err)
}
return GitStateConfig{
RepositoryName: *payload.Repo.Name,
RepositoryOwner: *payload.Repo.Owner.Login,
JobType: "merge_group",
BaseCommitSHA: commitSHA,
BaseCommitRef: gitRef,
PullHeadCommitSHA: *payload.MergeGroup.HeadSHA,
}, nil

default:
return GitStateConfig{}, fmt.Errorf("GITHUB_EVENT_NAME environment variable is set to unsupported value \"%s\", please set it to supported value", eventName)
}
Expand Down Expand Up @@ -343,4 +358,4 @@ func determineUsedCISystem(envGetter func(key string) string, envLookup func(key
}

return "", fmt.Errorf("cannot determine ci system: unknown system")
}
}
2 changes: 2 additions & 0 deletions cmd/image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ func prepareADOTemplateParameters(options options) (adopipelines.OCIImageBuilder
templateParameters.SetWorkflowDispatchJobType()
case "schedule":
templateParameters.SetScheduleJobType()
case "merge_group":
templateParameters.SetMergeGroupJobType()
default:
return nil, fmt.Errorf("unknown JobType received, ensure image-builder runs on supported event")
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/azuredevops/pipelines/templatesParams.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strconv"
)

var validJobTypes = []string{"presubmit", "postsubmit", "workflow_dispatch", "schedule"}
var validJobTypes = []string{"presubmit", "postsubmit", "workflow_dispatch", "schedule", "merge_group"}

func GetValidJobTypes() []string {
return validJobTypes
Expand Down Expand Up @@ -59,6 +59,11 @@ func (p OCIImageBuilderTemplateParams) SetScheduleJobType() {
p["JobType"] = "schedule"
}

// SetMergeGroup sets required parameter JobType to merge_group.
func (p OCIImageBuilderTemplateParams) SetMergeGroupJobType() {
p["JobType"] = "schedule"
}

// SetPullNumber sets optional parameter PullNumber.
func (p OCIImageBuilderTemplateParams) SetPullNumber(number string) {
p["PullNumber"] = number
Expand Down

0 comments on commit 904b2e1

Please sign in to comment.