diff --git a/docs/docs/35-references/10-promotion-steps.md b/docs/docs/35-references/10-promotion-steps.md index f168c38cc..67c7ff984 100644 --- a/docs/docs/35-references/10-promotion-steps.md +++ b/docs/docs/35-references/10-promotion-steps.md @@ -1003,6 +1003,7 @@ requests. | `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. | +| `labels` | `[]string` | N | Labels to add to the pull request. | #### `git-open-pr` Example diff --git a/internal/directives/git_pr_opener.go b/internal/directives/git_pr_opener.go index 24259edfc..151b38925 100644 --- a/internal/directives/git_pr_opener.go +++ b/internal/directives/git_pr_opener.go @@ -217,6 +217,7 @@ func (g *gitPROpener) runPromotionStep( Base: cfg.TargetBranch, Title: title, Description: description, + Labels: cfg.Labels, }, ); err != nil { return PromotionStepResult{Status: kargoapi.PromotionPhaseErrored}, diff --git a/internal/directives/schemas/git-open-pr-config.json b/internal/directives/schemas/git-open-pr-config.json index 6f0a97d07..c660c5b1d 100644 --- a/internal/directives/schemas/git-open-pr-config.json +++ b/internal/directives/schemas/git-open-pr-config.json @@ -43,6 +43,15 @@ "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 + }, + "labels": { + "type": "array", + "description": "Labels to add to the pull request.", + "items": { + "type": "string", + "description": "A pull request label", + "minLength": 1 + } } }, "oneOf": [ diff --git a/internal/directives/zz_config_types.go b/internal/directives/zz_config_types.go index e09b38c60..2b0a14ebf 100644 --- a/internal/directives/zz_config_types.go +++ b/internal/directives/zz_config_types.go @@ -187,6 +187,8 @@ type GitOpenPRConfig struct { CreateTargetBranch bool `json:"createTargetBranch,omitempty"` // Indicates whether to skip TLS verification when cloning the repository. Default is false. InsecureSkipTLSVerify bool `json:"insecureSkipTLSVerify,omitempty"` + // Labels to add to the pull request. + Labels []string `json:"labels,omitempty"` // The name of the Git provider to use. Currently only 'github' and 'gitlab' are supported. // Kargo will try to infer the provider if it is not explicitly specified. Provider *Provider `json:"provider,omitempty"` diff --git a/internal/gitprovider/github/github.go b/internal/gitprovider/github/github.go index 7964027e4..d97a05bae 100644 --- a/internal/gitprovider/github/github.go +++ b/internal/gitprovider/github/github.go @@ -111,6 +111,17 @@ func (p *provider) CreatePullRequest( return nil, fmt.Errorf("unexpected nil pull request") } pr := convertGithubPR(*ghPR) + if len(opts.Labels) > 0 { + _, _, err = p.client.Issues.AddLabelsToIssue(ctx, + p.owner, + p.repo, + int(pr.Number), + opts.Labels, + ) + } + if err != nil { + return nil, err + } return &pr, nil } diff --git a/internal/gitprovider/gitlab/gitlab.go b/internal/gitprovider/gitlab/gitlab.go index ee52e2919..a87a226de 100644 --- a/internal/gitprovider/gitlab/gitlab.go +++ b/internal/gitprovider/gitlab/gitlab.go @@ -119,6 +119,7 @@ func (p *provider) CreatePullRequest( glMR, _, err := p.client.CreateMergeRequest(p.projectName, &gitlab.CreateMergeRequestOptions{ Title: &opts.Title, Description: &opts.Description, + Labels: (*gitlab.LabelOptions)(&opts.Labels), SourceBranch: &opts.Head, TargetBranch: &opts.Base, RemoveSourceBranch: gitlab.Ptr(true), diff --git a/internal/gitprovider/gitprovider.go b/internal/gitprovider/gitprovider.go index c83dd8091..da5e8f466 100644 --- a/internal/gitprovider/gitprovider.go +++ b/internal/gitprovider/gitprovider.go @@ -64,6 +64,8 @@ type CreatePullRequestOpts struct { Head string // Base is the name of the target branch. Base string + // Labels is an array of strings that should be added as labels to the pull request. + Labels []string } // ListPullRequestOptions encapsulates the options used when listing pull diff --git a/ui/src/gen/directives/git-open-pr-config.json b/ui/src/gen/directives/git-open-pr-config.json index 8f554bf2d..1d817a9ef 100644 --- a/ui/src/gen/directives/git-open-pr-config.json +++ b/ui/src/gen/directives/git-open-pr-config.json @@ -45,6 +45,15 @@ "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 + }, + "labels": { + "type": "array", + "description": "Labels to add to the pull request.", + "items": { + "type": "string", + "description": "A pull request label", + "minLength": 1 + } } } } \ No newline at end of file