From ad9e16f63ae050a04edc4e2bc3b54980586546e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20M=C3=BCnch?= Date: Tue, 10 Dec 2024 00:33:57 +0100 Subject: [PATCH] feat: custom PR title (#3063) (#3107) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Dominik Münch --- docs/docs/35-references/10-promotion-steps.md | 1 + internal/directives/git_pr_opener.go | 7 ++++++- internal/directives/git_pr_opener_test.go | 11 +++++++++++ internal/directives/schemas/git-open-pr-config.json | 5 +++++ internal/directives/zz_config_types.go | 3 +++ ui/src/gen/directives/git-open-pr-config.json | 5 +++++ 6 files changed, 31 insertions(+), 1 deletion(-) diff --git a/docs/docs/35-references/10-promotion-steps.md b/docs/docs/35-references/10-promotion-steps.md index b715ada5c..1113aa275 100644 --- a/docs/docs/35-references/10-promotion-steps.md +++ b/docs/docs/35-references/10-promotion-steps.md @@ -1002,6 +1002,7 @@ requests. | `sourceBranchFromStep` | `string` | N | Indicates the source branch should be determined by the `branch` key in the output of a previous promotion step with the specified alias. Mutually exclusive with `sourceBranch`.

__Deprecated: Use `sourceBranch` with an expression instead. Will be removed in v1.3.0.__ | | `targetBranch` | `string` | N | The branch to which the changes should be merged. | | `createTargetBranch` | `boolean` | N | Indicates whether a new, empty orphaned branch should be created and pushed to the remote if the target branch does not already exist there. Default is `false`. | +| `title` | `string` | N | The title for the pull request. Kargo generates a title based on the commit messages if it is not explicitly specified. | #### `git-open-pr` Example diff --git a/internal/directives/git_pr_opener.go b/internal/directives/git_pr_opener.go index 5810ac163..2192bee60 100644 --- a/internal/directives/git_pr_opener.go +++ b/internal/directives/git_pr_opener.go @@ -193,7 +193,12 @@ func (g *gitPROpener) runPromotionStep( ) } - title := strings.Split(commitMsg, "\n")[0] + var title string + if cfg.Title != "" { + title = cfg.Title + } else { + title = strings.Split(commitMsg, "\n")[0] + } description := commitMsg if stepCtx.UIBaseURL != "" { description = fmt.Sprintf( diff --git a/internal/directives/git_pr_opener_test.go b/internal/directives/git_pr_opener_test.go index bb4f9074f..444fcca52 100644 --- a/internal/directives/git_pr_opener_test.go +++ b/internal/directives/git_pr_opener_test.go @@ -107,6 +107,16 @@ func Test_gitPROpener_validate(t *testing.T) { "targetBranch": "fake-branch", }, }, + { + name: "valid with custom title", + config: Config{ + "provider": "github", + "repoURL": "https://github.com/example/repo.git", + "sourceBranch": "fake-branch", + "targetBranch": "another-fake-branch", + "title": "custom title", + }, + }, } r := newGitPROpener() @@ -213,6 +223,7 @@ func Test_gitPROpener_runPromotionStep(t *testing.T) { TargetBranch: testTargetBranch, CreateTargetBranch: true, Provider: ptr.To(Provider(fakeGitProviderName)), + Title: "kargo", }, ) require.NoError(t, err) diff --git a/internal/directives/schemas/git-open-pr-config.json b/internal/directives/schemas/git-open-pr-config.json index 20dd24f64..6f0a97d07 100644 --- a/internal/directives/schemas/git-open-pr-config.json +++ b/internal/directives/schemas/git-open-pr-config.json @@ -38,6 +38,11 @@ "type": "string", "description": "The branch to which the changes should be merged. This branch must already exist and be up to date on the remote.", "minLength": 1 + }, + "title": { + "type": "string", + "description": "The title for the pull request. Kargo generates a title based on the commit messages if it is not explicitly specified.", + "minLength": 1 } }, "oneOf": [ diff --git a/internal/directives/zz_config_types.go b/internal/directives/zz_config_types.go index 6a9f964de..2d8812f47 100644 --- a/internal/directives/zz_config_types.go +++ b/internal/directives/zz_config_types.go @@ -201,6 +201,9 @@ type GitOpenPRConfig struct { // The branch to which the changes should be merged. This branch must already exist and be // up to date on the remote. TargetBranch string `json:"targetBranch"` + // The title for the pull request. Kargo generates a title based on the commit messages if + // it is not explicitly specified. + Title string `json:"title,omitempty"` } type GitPushConfig struct { diff --git a/ui/src/gen/directives/git-open-pr-config.json b/ui/src/gen/directives/git-open-pr-config.json index 86d88a917..8f554bf2d 100644 --- a/ui/src/gen/directives/git-open-pr-config.json +++ b/ui/src/gen/directives/git-open-pr-config.json @@ -40,6 +40,11 @@ "type": "string", "description": "The branch to which the changes should be merged. This branch must already exist and be up to date on the remote.", "minLength": 1 + }, + "title": { + "type": "string", + "description": "The title for the pull request. Kargo generates a title based on the commit messages if it is not explicitly specified.", + "minLength": 1 } } } \ No newline at end of file