Skip to content

Commit

Permalink
feat: add ui stage link to promo prs (#2753)
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
  • Loading branch information
krancour authored Oct 15, 2024
1 parent 97ac7d7 commit b6b0328
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
7 changes: 7 additions & 0 deletions charts/kargo/templates/controller/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ metadata:
{{- include "kargo.labels" . | nindent 4 }}
{{- include "kargo.controller.labels" . | nindent 4 }}
data:
{{- if .Values.api.enabled }}
{{- if or .Values.api.tls.enabled (and .Values.api.ingress.enabled .Values.api.ingress.tls.enabled) }}
API_SERVER_BASE_URL: https://{{ .Values.api.host }}
{{- else }}
API_SERVER_BASE_URL: http://{{ .Values.api.host }}
{{- end }}
{{- end }}
LOG_LEVEL: {{ quote .Values.controller.logLevel }}
{{- if .Values.controller.shardName }}
SHARD_NAME: {{ .Values.controller.shardName }}
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/promotions/promotions.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import (

// ReconcilerConfig represents configuration for the promotion reconciler.
type ReconcilerConfig struct {
ShardName string `envconfig:"SHARD_NAME"`
ShardName string `envconfig:"SHARD_NAME"`
APIServerBaseURL string `envconfig:"API_SERVER_BASE_URL"`
}

func (c ReconcilerConfig) Name() string {
Expand Down Expand Up @@ -523,6 +524,7 @@ func (r *reconciler) promote(
}

promoCtx := directives.PromotionContext{
UIBaseURL: r.cfg.APIServerBaseURL,
WorkDir: filepath.Join(os.TempDir(), "promotion-"+string(workingPromo.UID)),
Project: stageNamespace,
Stage: stageName,
Expand Down
22 changes: 18 additions & 4 deletions internal/directives/git_pr_opener.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package directives
import (
"context"
"fmt"
"strings"

"github.com/xeipuuv/gojsonschema"

Expand Down Expand Up @@ -142,7 +143,7 @@ func (g *gitPROpener) runPromotionStep(
// Get the title from the commit message of the head of the source branch
// BEFORE we move on to ensuring the existence of the target branch because
// that may involve creating a new branch and committing to it.
title, err := repo.CommitMessage(sourceBranch)
commitMsg, err := repo.CommitMessage(sourceBranch)
if err != nil {
return PromotionStepResult{Status: kargoapi.PromotionPhaseErrored}, fmt.Errorf(
"error getting commit message from head of branch %s: %w",
Expand All @@ -161,12 +162,25 @@ func (g *gitPROpener) runPromotionStep(
)
}

title := strings.Split(commitMsg, "\n")[0]
description := commitMsg
if stepCtx.UIBaseURL != "" {
description = fmt.Sprintf(
"%s\n\n[View in Kargo UI](%s/project/%s/stage/%s)",
description,
stepCtx.UIBaseURL,
stepCtx.Project,
stepCtx.Stage,
)
}

pr, err := gitProviderSvc.CreatePullRequest(
ctx,
gitprovider.CreatePullRequestOpts{
Head: sourceBranch,
Base: cfg.TargetBranch,
Title: title,
Head: sourceBranch,
Base: cfg.TargetBranch,
Title: title,
Description: description,
},
)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions internal/directives/promotions.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type PromotionStepRunner interface {
// PromotionContext is the context of a user-defined promotion process that is
// executed by the Engine.
type PromotionContext struct {
// UIBaseURL may be used to construct deeper URLs for interacting with the
// Kargo UI.
UIBaseURL string
// WorkDir is the working directory to use for the Promotion.
WorkDir string
// Project is the Project that the Promotion is associated with.
Expand Down Expand Up @@ -95,6 +98,9 @@ type PromotionResult struct {
// PromotionStepContext is a type that represents the context in which a
// SinglePromotion step is executed by a PromotionStepRunner.
type PromotionStepContext struct {
// UIBaseURL may be used to construct deeper URLs for interacting with the
// Kargo UI.
UIBaseURL string
// WorkDir is the root directory for the execution of a step.
WorkDir string
// SharedState is the state shared between steps.
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 @@ -88,6 +88,7 @@ func (e *SimpleEngine) Promote(
stateCopy := state.DeepCopy()

stepCtx := &PromotionStepContext{
UIBaseURL: promoCtx.UIBaseURL,
WorkDir: workDir,
SharedState: stateCopy,
Alias: step.Alias,
Expand Down
2 changes: 1 addition & 1 deletion internal/gitprovider/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (g *GitHubProvider) CreatePullRequest(
Title: &opts.Title,
Head: &opts.Head,
Base: &opts.Base,
Body: &opts.Title,
Body: &opts.Description,
MaintainerCanModify: github.Bool(false),
},
)
Expand Down

0 comments on commit b6b0328

Please sign in to comment.