mirror of
https://github.com/apricote/releaser-pleaser.git
synced 2026-01-13 21:21:03 +00:00
feat: open pr
This commit is contained in:
parent
3c5c66d029
commit
e0b1e2221d
3 changed files with 40 additions and 2 deletions
|
|
@ -232,7 +232,21 @@ func reconcileReleasePR(ctx context.Context, forge rp.Forge, changesets []rp.Cha
|
|||
logger.InfoContext(ctx, "file content is already up-to-date in remote branch, skipping push")
|
||||
}
|
||||
|
||||
// TODO Open PR
|
||||
// Open/Update PR
|
||||
if pr == nil {
|
||||
pr = &rp.ReleasePullRequest{
|
||||
Title: releaseCommitMessage,
|
||||
Description: "TODO",
|
||||
Labels: nil,
|
||||
Head: rpBranch,
|
||||
}
|
||||
|
||||
pr, err = forge.CreatePullRequest(ctx, pr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logger.InfoContext(ctx, "opened pull request", "pr.title", pr.Title, "pr.id", pr.ID)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
24
forge.go
24
forge.go
|
|
@ -48,6 +48,8 @@ type Forge interface {
|
|||
// PullRequestForBranch returns the open pull request between the branch and ForgeOptions.BaseBranch. If no open PR
|
||||
// exists, it returns nil.
|
||||
PullRequestForBranch(context.Context, string) (*ReleasePullRequest, error)
|
||||
|
||||
CreatePullRequest(context.Context, *ReleasePullRequest) (*ReleasePullRequest, error)
|
||||
}
|
||||
|
||||
type ForgeOptions struct {
|
||||
|
|
@ -330,7 +332,7 @@ func (g *GitHub) PullRequestForBranch(ctx context.Context, branch string) (*Rele
|
|||
}
|
||||
|
||||
for _, pr := range prs {
|
||||
if pr.Base.GetLabel() == g.options.BaseBranch && pr.Head.GetLabel() == branch && pr.GetState() == GitHubPRStateOpen {
|
||||
if pr.GetBase().GetLabel() == g.options.BaseBranch && pr.GetHead().GetLabel() == branch && pr.GetState() == GitHubPRStateOpen {
|
||||
labels := make([]string, 0, len(pr.Labels))
|
||||
for _, label := range pr.Labels {
|
||||
labels = append(labels, label.GetName())
|
||||
|
|
@ -341,6 +343,7 @@ func (g *GitHub) PullRequestForBranch(ctx context.Context, branch string) (*Rele
|
|||
Title: pr.GetTitle(),
|
||||
Description: pr.GetBody(),
|
||||
Labels: labels,
|
||||
Head: pr.GetHead().GetLabel(),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
|
@ -354,6 +357,25 @@ func (g *GitHub) PullRequestForBranch(ctx context.Context, branch string) (*Rele
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func (g *GitHub) CreatePullRequest(ctx context.Context, pr *ReleasePullRequest) (*ReleasePullRequest, error) {
|
||||
ghPR, _, err := g.client.PullRequests.Create(
|
||||
ctx, g.options.Owner, g.options.Repo,
|
||||
&github.NewPullRequest{
|
||||
Title: &pr.Title,
|
||||
Head: &pr.Head,
|
||||
Base: &g.options.BaseBranch,
|
||||
Body: &pr.Description,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pr.ID = int(*ghPR.ID) // TODO: String ID?
|
||||
|
||||
return pr, nil
|
||||
}
|
||||
|
||||
func (g *GitHubOptions) autodiscover() {
|
||||
if apiToken := os.Getenv(GitHubEnvAPIToken); apiToken != "" {
|
||||
g.APIToken = apiToken
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ type ReleasePullRequest struct {
|
|||
Title string
|
||||
Description string
|
||||
Labels []string
|
||||
|
||||
Head string
|
||||
}
|
||||
|
||||
type ReleaseOverrides struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue