1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-07-05 00:59:04 +02:00

feat: support closing milestones (#1657)

* feat: support closing milestones

Reference: https://github.com/goreleaser/goreleaser/issues/1415

* refactor: Adjust milestone handling for code simplification, add ErrNoMilestoneFound, and fix milestone documentation close default

Reference: https://github.com/goreleaser/goreleaser/pull/1657#pullrequestreview-445025743

* refactor: Use single repo config in milestones instead of each VCS

* fix: Ensure milestone Pipe is included in Defaulters

* feat: Add fail_on_error configuration to milestone configuration

Co-authored-by: Radek Simko <radek.simko@gmail.com>
This commit is contained in:
Brian Flad
2020-07-09 16:40:37 -04:00
committed by GitHub
parent 608e4008b6
commit 01fd3e8c7b
19 changed files with 581 additions and 21 deletions

View File

@ -56,6 +56,32 @@ func NewGitHub(ctx *context.Context, token string) (Client, error) {
return &githubClient{client: client}, nil
}
// CloseMilestone closes a given milestone.
func (c *githubClient) CloseMilestone(ctx *context.Context, repo Repo, title string) error {
milestone, err := c.getMilestoneByTitle(ctx, repo, title)
if err != nil {
return err
}
if milestone == nil {
return ErrNoMilestoneFound{Title: title}
}
closedState := "closed"
milestone.State = &closedState
_, _, err = c.client.Issues.EditMilestone(
ctx,
repo.Owner,
repo.Name,
*milestone.Number,
milestone,
)
return err
}
func (c *githubClient) CreateFile(
ctx *context.Context,
commitAuthor config.CommitAuthor,
@ -187,3 +213,38 @@ func (c *githubClient) Upload(
}
return RetriableError{err}
}
// getMilestoneByTitle returns a milestone by title.
func (c *githubClient) getMilestoneByTitle(ctx *context.Context, repo Repo, title string) (*github.Milestone, error) {
// The GitHub API/SDK does not provide lookup by title functionality currently.
opts := &github.MilestoneListOptions{
ListOptions: github.ListOptions{PerPage: 100},
}
for {
milestones, resp, err := c.client.Issues.ListMilestones(
ctx,
repo.Owner,
repo.Name,
opts,
)
if err != nil {
return nil, err
}
for _, m := range milestones {
if m != nil && m.Title != nil && *m.Title == title {
return m, nil
}
}
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
}
return nil, nil
}