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

feat: custom PR title (#3063) #3107

Merged
merged 1 commit into from
Dec 9, 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 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 @@
)
}

title := strings.Split(commitMsg, "\n")[0]
var title string
if cfg.Title != "" {
title = cfg.Title
} else {
title = strings.Split(commitMsg, "\n")[0]
}

Check warning on line 201 in internal/directives/git_pr_opener.go

View check run for this annotation

Codecov / codecov/patch

internal/directives/git_pr_opener.go#L200-L201

Added lines #L200 - L201 were not covered by tests
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
}
}
}
Loading