mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-02-10 19:57:03 +00:00
wip
This commit is contained in:
parent
8b3bd3ca27
commit
901b5977e6
5 changed files with 32 additions and 24 deletions
|
|
@ -26,7 +26,7 @@ type Forge interface {
|
||||||
|
|
||||||
// EnsureLabelsExist verifies that all desired labels are available on the repository. If labels are missing, they
|
// EnsureLabelsExist verifies that all desired labels are available on the repository. If labels are missing, they
|
||||||
// are created them.
|
// 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
|
// PullRequestForBranch returns the open pull request between the branch and Options.BaseBranch. If no open PR
|
||||||
// exists, it returns nil.
|
// exists, it returns nil.
|
||||||
|
|
@ -41,7 +41,7 @@ type Forge interface {
|
||||||
|
|
||||||
// SetPullRequestLabels updates the pull/merge request identified through the ID of
|
// SetPullRequestLabels updates the pull/merge request identified through the ID of
|
||||||
// the ReleasePullRequest to the current labels.
|
// 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
|
// ClosePullRequest closes the pull/merge request identified through the ID of
|
||||||
// the ReleasePullRequest, as it is no longer required.
|
// 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
|
// PendingReleases returns a list of ReleasePullRequest. The list should contain all pull/merge requests that are
|
||||||
// merged and have the matching label.
|
// 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 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
|
CreateRelease(ctx context.Context, commit git.Commit, title, changelog string, prerelease, latest bool) error
|
||||||
|
|
@ -59,3 +59,6 @@ type Options struct {
|
||||||
Repository string
|
Repository string
|
||||||
BaseBranch string
|
BaseBranch string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Label is the string identifier of a pull/merge request label on the forge.
|
||||||
|
type Label string
|
||||||
|
|
|
||||||
|
|
@ -266,7 +266,7 @@ func (g *GitHub) prForCommit(ctx context.Context, commit git.Commit) (*git.PullR
|
||||||
return gitHubPRToPullRequest(pullrequest), nil
|
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))
|
existingLabels := make([]string, 0, len(labels))
|
||||||
|
|
||||||
page := 1
|
page := 1
|
||||||
|
|
@ -362,7 +362,7 @@ func (g *GitHub) CreatePullRequest(ctx context.Context, pr *rp.ReleasePullReques
|
||||||
// TODO: String ID?
|
// TODO: String ID?
|
||||||
pr.ID = ghPR.GetNumber()
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -385,7 +385,7 @@ func (g *GitHub) UpdatePullRequest(ctx context.Context, pr *rp.ReleasePullReques
|
||||||
return nil
|
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 {
|
for _, label := range remove {
|
||||||
_, err := g.client.Issues.RemoveLabelForIssue(
|
_, err := g.client.Issues.RemoveLabelForIssue(
|
||||||
ctx, g.options.Owner, g.options.Repo,
|
ctx, g.options.Owner, g.options.Repo,
|
||||||
|
|
@ -426,7 +426,7 @@ func (g *GitHub) ClosePullRequest(ctx context.Context, pr *rp.ReleasePullRequest
|
||||||
return nil
|
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
|
page := 1
|
||||||
|
|
||||||
var prs []*rp.ReleasePullRequest
|
var prs []*rp.ReleasePullRequest
|
||||||
|
|
@ -512,10 +512,10 @@ func gitHubPRToPullRequest(pr *github.PullRequest) *git.PullRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
func gitHubPRToReleasePullRequest(pr *github.PullRequest) *rp.ReleasePullRequest {
|
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 {
|
for _, label := range pr.Labels {
|
||||||
labelName := rp.Label(label.GetName())
|
labelName := forge.Label(label.GetName())
|
||||||
if slices.Contains(rp.KnownLabels, rp.Label(label.GetName())) {
|
if slices.Contains(rp.KnownLabels, forge.Label(label.GetName())) {
|
||||||
labels = append(labels, labelName)
|
labels = append(labels, labelName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
7
pr.go
Normal file
7
pr.go
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
package rp
|
||||||
|
|
||||||
|
import "github.com/apricote/releaser-pleaser/internal/git"
|
||||||
|
|
||||||
|
type PullRequest git.PullRequest
|
||||||
|
|
||||||
|
func (pr *PullRequest) GetOverrides() {}
|
||||||
24
releasepr.go
24
releasepr.go
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/yuin/goldmark/ast"
|
"github.com/yuin/goldmark/ast"
|
||||||
"github.com/yuin/goldmark/text"
|
"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/git"
|
||||||
"github.com/apricote/releaser-pleaser/internal/markdown"
|
"github.com/apricote/releaser-pleaser/internal/markdown"
|
||||||
east "github.com/apricote/releaser-pleaser/internal/markdown/extensions/ast"
|
east "github.com/apricote/releaser-pleaser/internal/markdown/extensions/ast"
|
||||||
|
|
@ -34,12 +35,12 @@ func init() {
|
||||||
|
|
||||||
// ReleasePullRequest
|
// ReleasePullRequest
|
||||||
//
|
//
|
||||||
// TODO: Reuse [PullRequest]
|
// TODO: Reuse [git.PullRequest]
|
||||||
type ReleasePullRequest struct {
|
type ReleasePullRequest struct {
|
||||||
ID int
|
ID int
|
||||||
Title string
|
Title string
|
||||||
Description string
|
Description string
|
||||||
Labels []Label
|
Labels []forge.Label
|
||||||
|
|
||||||
Head string
|
Head string
|
||||||
ReleaseCommit *git.Commit
|
ReleaseCommit *git.Commit
|
||||||
|
|
@ -48,7 +49,7 @@ type ReleasePullRequest struct {
|
||||||
func NewReleasePullRequest(head, branch, version, changelogEntry string) (*ReleasePullRequest, error) {
|
func NewReleasePullRequest(head, branch, version, changelogEntry string) (*ReleasePullRequest, error) {
|
||||||
rp := &ReleasePullRequest{
|
rp := &ReleasePullRequest{
|
||||||
Head: head,
|
Head: head,
|
||||||
Labels: []Label{LabelReleasePending},
|
Labels: []forge.Label{LabelReleasePending},
|
||||||
}
|
}
|
||||||
|
|
||||||
rp.SetTitle(branch, version)
|
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 (
|
const (
|
||||||
LabelNextVersionTypeNormal Label = "rp-next-version::normal"
|
LabelNextVersionTypeNormal forge.Label = "rp-next-version::normal"
|
||||||
LabelNextVersionTypeRC Label = "rp-next-version::rc"
|
LabelNextVersionTypeRC forge.Label = "rp-next-version::rc"
|
||||||
LabelNextVersionTypeBeta Label = "rp-next-version::beta"
|
LabelNextVersionTypeBeta forge.Label = "rp-next-version::beta"
|
||||||
LabelNextVersionTypeAlpha Label = "rp-next-version::alpha"
|
LabelNextVersionTypeAlpha forge.Label = "rp-next-version::alpha"
|
||||||
|
|
||||||
LabelReleasePending Label = "rp-release::pending"
|
LabelReleasePending forge.Label = "rp-release::pending"
|
||||||
LabelReleaseTagged Label = "rp-release::tagged"
|
LabelReleaseTagged forge.Label = "rp-release::tagged"
|
||||||
)
|
)
|
||||||
|
|
||||||
var KnownLabels = []Label{
|
var KnownLabels = []forge.Label{
|
||||||
LabelNextVersionTypeNormal,
|
LabelNextVersionTypeNormal,
|
||||||
LabelNextVersionTypeRC,
|
LabelNextVersionTypeRC,
|
||||||
LabelNextVersionTypeBeta,
|
LabelNextVersionTypeBeta,
|
||||||
|
|
|
||||||
|
|
@ -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, "created release", "release.title", version, "release.url", rp.forge.ReleaseURL(version))
|
||||||
|
|
||||||
logger.DebugContext(ctx, "updating pr labels")
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue