Skip to content

Commit

Permalink
feat: PR labels (#3002)
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Münch <[email protected]>
  • Loading branch information
muenchdo committed Dec 10, 2024
1 parent aecc74f commit 22bd83c
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 0 deletions.
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 @@ -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

Expand Down
1 change: 1 addition & 0 deletions internal/directives/git_pr_opener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
9 changes: 9 additions & 0 deletions internal/directives/schemas/git-open-pr-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
2 changes: 2 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.

11 changes: 11 additions & 0 deletions internal/gitprovider/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Check warning on line 124 in internal/gitprovider/github/github.go

View check run for this annotation

Codecov / codecov/patch

internal/gitprovider/github/github.go#L114-L124

Added lines #L114 - L124 were not covered by tests
return &pr, nil
}

Expand Down
1 change: 1 addition & 0 deletions internal/gitprovider/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions internal/gitprovider/gitprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions ui/src/gen/directives/git-open-pr-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}

0 comments on commit 22bd83c

Please sign in to comment.