This commit is contained in:
Julian Tölle 2024-08-31 10:20:16 +02:00
parent 8b3bd3ca27
commit 901b5977e6
5 changed files with 32 additions and 24 deletions

View file

@ -26,7 +26,7 @@ type Forge interface {
// EnsureLabelsExist verifies that all desired labels are available on the repository. If labels are missing, they
// are created them.
EnsureLabelsExist(context.Context, []rp.Label) error
EnsureLabelsExist(context.Context, []Label) error
// PullRequestForBranch returns the open pull request between the branch and Options.BaseBranch. If no open PR
// exists, it returns nil.
@ -41,7 +41,7 @@ type Forge interface {
// SetPullRequestLabels updates the pull/merge request identified through the ID of
// the ReleasePullRequest to the current labels.
SetPullRequestLabels(ctx context.Context, pr *rp.ReleasePullRequest, remove, add []rp.Label) error
SetPullRequestLabels(ctx context.Context, pr *rp.ReleasePullRequest, remove, add []Label) error
// ClosePullRequest closes the pull/merge request identified through the ID of
// the ReleasePullRequest, as it is no longer required.
@ -49,7 +49,7 @@ type Forge interface {
// PendingReleases returns a list of ReleasePullRequest. The list should contain all pull/merge requests that are
// merged and have the matching label.
PendingReleases(context.Context, rp.Label) ([]*rp.ReleasePullRequest, error)
PendingReleases(context.Context, Label) ([]*rp.ReleasePullRequest, error)
// CreateRelease creates a release on the Forge, pointing at the commit with the passed in details.
CreateRelease(ctx context.Context, commit git.Commit, title, changelog string, prerelease, latest bool) error
@ -59,3 +59,6 @@ type Options struct {
Repository string
BaseBranch string
}
// Label is the string identifier of a pull/merge request label on the forge.
type Label string

View file

@ -266,7 +266,7 @@ func (g *GitHub) prForCommit(ctx context.Context, commit git.Commit) (*git.PullR
return gitHubPRToPullRequest(pullrequest), nil
}
func (g *GitHub) EnsureLabelsExist(ctx context.Context, labels []rp.Label) error {
func (g *GitHub) EnsureLabelsExist(ctx context.Context, labels []forge.Label) error {
existingLabels := make([]string, 0, len(labels))
page := 1
@ -362,7 +362,7 @@ func (g *GitHub) CreatePullRequest(ctx context.Context, pr *rp.ReleasePullReques
// TODO: String ID?
pr.ID = ghPR.GetNumber()
err = g.SetPullRequestLabels(ctx, pr, []rp.Label{}, pr.Labels)
err = g.SetPullRequestLabels(ctx, pr, []forge.Label{}, pr.Labels)
if err != nil {
return err
}
@ -385,7 +385,7 @@ func (g *GitHub) UpdatePullRequest(ctx context.Context, pr *rp.ReleasePullReques
return nil
}
func (g *GitHub) SetPullRequestLabels(ctx context.Context, pr *rp.ReleasePullRequest, remove, add []rp.Label) error {
func (g *GitHub) SetPullRequestLabels(ctx context.Context, pr *rp.ReleasePullRequest, remove, add []forge.Label) error {
for _, label := range remove {
_, err := g.client.Issues.RemoveLabelForIssue(
ctx, g.options.Owner, g.options.Repo,
@ -426,7 +426,7 @@ func (g *GitHub) ClosePullRequest(ctx context.Context, pr *rp.ReleasePullRequest
return nil
}
func (g *GitHub) PendingReleases(ctx context.Context, pendingLabel rp.Label) ([]*rp.ReleasePullRequest, error) {
func (g *GitHub) PendingReleases(ctx context.Context, pendingLabel forge.Label) ([]*rp.ReleasePullRequest, error) {
page := 1
var prs []*rp.ReleasePullRequest
@ -512,10 +512,10 @@ func gitHubPRToPullRequest(pr *github.PullRequest) *git.PullRequest {
}
func gitHubPRToReleasePullRequest(pr *github.PullRequest) *rp.ReleasePullRequest {
labels := make([]rp.Label, 0, len(pr.Labels))
labels := make([]forge.Label, 0, len(pr.Labels))
for _, label := range pr.Labels {
labelName := rp.Label(label.GetName())
if slices.Contains(rp.KnownLabels, rp.Label(label.GetName())) {
labelName := forge.Label(label.GetName())
if slices.Contains(rp.KnownLabels, forge.Label(label.GetName())) {
labels = append(labels, labelName)
}
}

7
pr.go Normal file
View file

@ -0,0 +1,7 @@
package rp
import "github.com/apricote/releaser-pleaser/internal/git"
type PullRequest git.PullRequest
func (pr *PullRequest) GetOverrides() {}

View file

@ -12,6 +12,7 @@ import (
"github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/text"
"github.com/apricote/releaser-pleaser/internal/forge"
"github.com/apricote/releaser-pleaser/internal/git"
"github.com/apricote/releaser-pleaser/internal/markdown"
east "github.com/apricote/releaser-pleaser/internal/markdown/extensions/ast"
@ -34,12 +35,12 @@ func init() {
// ReleasePullRequest
//
// TODO: Reuse [PullRequest]
// TODO: Reuse [git.PullRequest]
type ReleasePullRequest struct {
ID int
Title string
Description string
Labels []Label
Labels []forge.Label
Head string
ReleaseCommit *git.Commit
@ -48,7 +49,7 @@ type ReleasePullRequest struct {
func NewReleasePullRequest(head, branch, version, changelogEntry string) (*ReleasePullRequest, error) {
rp := &ReleasePullRequest{
Head: head,
Labels: []Label{LabelReleasePending},
Labels: []forge.Label{LabelReleasePending},
}
rp.SetTitle(branch, version)
@ -103,20 +104,17 @@ func (n NextVersionType) IsPrerelease() bool {
}
}
// Label is the string identifier of a pull/merge request label on the forge.
type Label string
const (
LabelNextVersionTypeNormal Label = "rp-next-version::normal"
LabelNextVersionTypeRC Label = "rp-next-version::rc"
LabelNextVersionTypeBeta Label = "rp-next-version::beta"
LabelNextVersionTypeAlpha Label = "rp-next-version::alpha"
LabelNextVersionTypeNormal forge.Label = "rp-next-version::normal"
LabelNextVersionTypeRC forge.Label = "rp-next-version::rc"
LabelNextVersionTypeBeta forge.Label = "rp-next-version::beta"
LabelNextVersionTypeAlpha forge.Label = "rp-next-version::alpha"
LabelReleasePending Label = "rp-release::pending"
LabelReleaseTagged Label = "rp-release::tagged"
LabelReleasePending forge.Label = "rp-release::pending"
LabelReleaseTagged forge.Label = "rp-release::tagged"
)
var KnownLabels = []Label{
var KnownLabels = []forge.Label{
LabelNextVersionTypeNormal,
LabelNextVersionTypeRC,
LabelNextVersionTypeBeta,

View file

@ -132,7 +132,7 @@ func (rp *ReleaserPleaser) createPendingRelease(ctx context.Context, pr *Release
logger.DebugContext(ctx, "created release", "release.title", version, "release.url", rp.forge.ReleaseURL(version))
logger.DebugContext(ctx, "updating pr labels")
err = rp.forge.SetPullRequestLabels(ctx, pr, []Label{LabelReleasePending}, []Label{LabelReleaseTagged})
err = rp.forge.SetPullRequestLabels(ctx, pr, []forge.Label{LabelReleasePending}, []forge.Label{LabelReleaseTagged})
if err != nil {
return err
}