Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(controller): use promotion name when generating branch names #2878

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/controller/promotions/promotions.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ func (r *reconciler) promote(
WorkDir: filepath.Join(os.TempDir(), "promotion-"+string(workingPromo.UID)),
Project: stageNamespace,
Stage: stageName,
Promotion: workingPromo.Name,
FreightRequests: stage.Spec.RequestedFreight,
Freight: *workingPromo.Status.FreightCollection.DeepCopy(),
StartFromStep: promo.Status.CurrentStep,
Expand Down
2 changes: 1 addition & 1 deletion internal/directives/git_pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (g *gitPushPusher) runPromotionStep(
}
// If we're supposed to generate a target branch name, do so
if cfg.GenerateTargetBranch {
pushOpts.TargetBranch = fmt.Sprintf("kargo/%s/%s/promotion", stepCtx.Project, stepCtx.Stage)
pushOpts.TargetBranch = fmt.Sprintf("kargo/promotion/%s", stepCtx.Promotion)
pushOpts.Force = true
}
targetBranch := pushOpts.TargetBranch
Expand Down
3 changes: 2 additions & 1 deletion internal/directives/git_pusher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func Test_gitPusher_runPromotionStep(t *testing.T) {
&PromotionStepContext{
Project: "fake-project",
Stage: "fake-stage",
Promotion: "fake-promotion",
WorkDir: workDir,
CredentialsDB: &credentials.FakeDB{},
},
Expand All @@ -201,7 +202,7 @@ func Test_gitPusher_runPromotionStep(t *testing.T) {
require.NoError(t, err)
branchName, ok := res.Output[branchKey]
require.True(t, ok)
require.Equal(t, "kargo/fake-project/fake-stage/promotion", branchName)
require.Equal(t, "kargo/promotion/fake-promotion", branchName)
expectedCommit, err := workTree.LastCommitID()
require.NoError(t, err)
actualCommit, ok := res.Output[commitKey]
Expand Down
4 changes: 4 additions & 0 deletions internal/directives/promotions.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type PromotionContext struct {
Project string
// Stage is the Stage that the Promotion is targeting.
Stage string
// Promotion is the name of the Promotion.
Promotion string
// FreightRequests is the list of Freight from various origins that is
// requested by the Stage targeted by the Promotion. This information is
// sometimes useful to PromotionSteps that reference a particular artifact
Expand Down Expand Up @@ -114,6 +116,8 @@ type PromotionStepContext struct {
Project string
// Stage is the Stage that the Promotion is targeting.
Stage string
// Promotion is the name of the Promotion.
Promotion string
// FreightRequests is the list of Freight from various origins that is
// requested by the Stage targeted by the Promotion. This information is
// sometimes useful to PromotionStep that reference a particular artifact and,
Expand Down
1 change: 1 addition & 0 deletions internal/directives/simple_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (e *SimpleEngine) Promote(
Config: step.Config.DeepCopy(),
Project: promoCtx.Project,
Stage: promoCtx.Stage,
Promotion: promoCtx.Promotion,
FreightRequests: promoCtx.FreightRequests,
Freight: promoCtx.Freight,
}
Expand Down