Skip to content

Commit

Permalink
feat: custom PR title (#3063) (#3107)
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Münch <[email protected]>
  • Loading branch information
muenchdo authored Dec 9, 2024
1 parent 3a1ee47 commit ad9e16f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/docs/35-references/10-promotion-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.<br/><br/>__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

Expand Down
7 changes: 6 additions & 1 deletion internal/directives/git_pr_opener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions internal/directives/git_pr_opener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions internal/directives/schemas/git-open-pr-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
3 changes: 3 additions & 0 deletions internal/directives/zz_config_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions ui/src/gen/directives/git-open-pr-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit ad9e16f

Please sign in to comment.