From 3b300f8802ce647cc47616cea6bf06e66bfc30ee Mon Sep 17 00:00:00 2001 From: Kent Rancourt Date: Wed, 30 Oct 2024 12:32:36 -0400 Subject: [PATCH] use promotion name when generating branch names Signed-off-by: Kent Rancourt --- internal/controller/promotions/promotions.go | 1 + internal/directives/git_pusher.go | 2 +- internal/directives/git_pusher_test.go | 3 ++- internal/directives/promotions.go | 4 ++++ internal/directives/simple_engine.go | 1 + 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/controller/promotions/promotions.go b/internal/controller/promotions/promotions.go index 2d8ab027e..407bb0d5f 100644 --- a/internal/controller/promotions/promotions.go +++ b/internal/controller/promotions/promotions.go @@ -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, diff --git a/internal/directives/git_pusher.go b/internal/directives/git_pusher.go index a0f1c1061..ee6c6fea1 100644 --- a/internal/directives/git_pusher.go +++ b/internal/directives/git_pusher.go @@ -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 diff --git a/internal/directives/git_pusher_test.go b/internal/directives/git_pusher_test.go index d13039821..e900dcbba 100644 --- a/internal/directives/git_pusher_test.go +++ b/internal/directives/git_pusher_test.go @@ -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{}, }, @@ -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] diff --git a/internal/directives/promotions.go b/internal/directives/promotions.go index 52bd1ee1e..59fa37a65 100644 --- a/internal/directives/promotions.go +++ b/internal/directives/promotions.go @@ -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 @@ -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, diff --git a/internal/directives/simple_engine.go b/internal/directives/simple_engine.go index 4c3eaeb43..f3b0cfab4 100644 --- a/internal/directives/simple_engine.go +++ b/internal/directives/simple_engine.go @@ -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, }