You've already forked goreleaser
mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-07-05 00:59:04 +02:00
feat: support pull request templates (#4105)
check if there is a `.github/PULL_REQUEST_TEMPLATE.md` file, and use it as body of the pull request if there is. --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
2519581221
commit
bbcc45b677
@ -166,6 +166,22 @@ func headString(base, head Repo) string {
|
||||
}, ":")
|
||||
}
|
||||
|
||||
func (c *githubClient) getPRTemplate(ctx *context.Context, repo Repo) (string, error) {
|
||||
content, _, _, err := c.client.Repositories.GetContents(
|
||||
ctx, repo.Owner, repo.Name,
|
||||
".github/PULL_REQUEST_TEMPLATE.md",
|
||||
&github.RepositoryContentGetOptions{
|
||||
Ref: repo.Branch,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return content.GetContent()
|
||||
}
|
||||
|
||||
const prFooter = "###### Automated with [GoReleaser](https://goreleaser.com)"
|
||||
|
||||
func (c *githubClient) OpenPullRequest(
|
||||
ctx *context.Context,
|
||||
base, head Repo,
|
||||
@ -180,26 +196,38 @@ func (c *githubClient) OpenPullRequest(
|
||||
}
|
||||
base.Branch = def
|
||||
}
|
||||
tpl, err := c.getPRTemplate(ctx, base)
|
||||
if err != nil {
|
||||
log.WithError(err).Debug("no pull request template found...")
|
||||
}
|
||||
if len(tpl) > 0 {
|
||||
log.Info("got a pr template")
|
||||
}
|
||||
log := log.
|
||||
WithField("base", headString(base, Repo{})).
|
||||
WithField("head", headString(base, head)).
|
||||
WithField("draft", draft)
|
||||
log.Info("opening pull request")
|
||||
pr, res, err := c.client.PullRequests.Create(ctx, base.Owner, base.Name, &github.NewPullRequest{
|
||||
Title: github.String(title),
|
||||
Base: github.String(base.Branch),
|
||||
Head: github.String(headString(base, head)),
|
||||
Body: github.String("Automatically generated by [GoReleaser](https://goreleaser.com)"),
|
||||
Draft: github.Bool(draft),
|
||||
})
|
||||
pr, res, err := c.client.PullRequests.Create(
|
||||
ctx,
|
||||
firstNonEmpty(base.Owner, head.Owner),
|
||||
firstNonEmpty(base.Name, head.Name),
|
||||
&github.NewPullRequest{
|
||||
Title: github.String(title),
|
||||
Base: github.String(base.Branch),
|
||||
Head: github.String(headString(base, head)),
|
||||
Body: github.String(strings.Join([]string{tpl, prFooter}, "\n")),
|
||||
Draft: github.Bool(draft),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
if res.StatusCode == 422 {
|
||||
log.Warn("PR already exists, doing nothing...")
|
||||
log.WithError(err).Warn("pull request validation failed")
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("could not create pull request: %w", err)
|
||||
}
|
||||
log.WithField("url", pr.GetHTMLURL()).Info("opened")
|
||||
log.WithField("url", pr.GetHTMLURL()).Info("pull request created")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -240,6 +268,7 @@ func (c *githubClient) CreateFile(
|
||||
log.
|
||||
WithField("repository", repo.String()).
|
||||
WithField("branch", repo.Branch).
|
||||
WithField("file", path).
|
||||
Info("pushing")
|
||||
|
||||
if defBranch != branch && branch != "" {
|
||||
|
Reference in New Issue
Block a user