| 1 |
// Copyright 2014 The go-github AUTHORS. All rights reserved. |
| 2 |
// |
| 3 |
// Use of this source code is governed by a BSD-style |
| 4 |
// license that can be found in the LICENSE file. |
| 5 |
|
| 6 |
package github |
| 7 |
|
| 8 |
import ( |
| 9 |
"context" |
| 10 |
"fmt" |
| 11 |
) |
| 12 |
|
| 13 |
// Milestone represents a GitHub repository milestone. |
| 14 |
type Milestone struct { |
| 15 |
URL *string `json:"url,omitempty"` |
| 16 |
HTMLURL *string `json:"html_url,omitempty"` |
| 17 |
LabelsURL *string `json:"labels_url,omitempty"` |
| 18 |
ID *int64 `json:"id,omitempty"` |
| 19 |
Number *int `json:"number,omitempty"` |
| 20 |
State *string `json:"state,omitempty"` |
| 21 |
Title *string `json:"title,omitempty"` |
| 22 |
Description *string `json:"description,omitempty"` |
| 23 |
Creator *User `json:"creator,omitempty"` |
| 24 |
OpenIssues *int `json:"open_issues,omitempty"` |
| 25 |
ClosedIssues *int `json:"closed_issues,omitempty"` |
| 26 |
CreatedAt *Timestamp `json:"created_at,omitempty"` |
| 27 |
UpdatedAt *Timestamp `json:"updated_at,omitempty"` |
| 28 |
ClosedAt *Timestamp `json:"closed_at,omitempty"` |
| 29 |
DueOn *Timestamp `json:"due_on,omitempty"` |
| 30 |
NodeID *string `json:"node_id,omitempty"` |
| 31 |
} |
| 32 |
|
| 33 |
func (m Milestone) String() string { |
| 34 |
return Stringify(m) |
| 35 |
} |
| 36 |
|
| 37 |
// MilestoneListOptions specifies the optional parameters to the |
| 38 |
// IssuesService.ListMilestones method. |
| 39 |
type MilestoneListOptions struct { |
| 40 |
// State filters milestones based on their state. Possible values are: |
| 41 |
// open, closed, all. Default is "open". |
| 42 |
State string `url:"state,omitempty"` |
| 43 |
|
| 44 |
// Sort specifies how to sort milestones. Possible values are: due_on, completeness. |
| 45 |
// Default value is "due_on". |
| 46 |
Sort string `url:"sort,omitempty"` |
| 47 |
|
| 48 |
// Direction in which to sort milestones. Possible values are: asc, desc. |
| 49 |
// Default is "asc". |
| 50 |
Direction string `url:"direction,omitempty"` |
| 51 |
|
| 52 |
ListOptions |
| 53 |
} |
| 54 |
|
| 55 |
// ListMilestones lists all milestones for a repository. |
| 56 |
// |
| 57 |
// GitHub API docs: https://docs.github.com/rest/issues/milestones#list-milestones |
| 58 |
// |
| 59 |
//meta:operation GET /repos/{owner}/{repo}/milestones |
| 60 |
func (s *IssuesService) ListMilestones(ctx context.Context, owner string, repo string, opts *MilestoneListOptions) ([]*Milestone, *Response, error) { |
| 61 |
u := fmt.Sprintf("repos/%v/%v/milestones", owner, repo) |
| 62 |
u, err := addOptions(u, opts) |
| 63 |
if err != nil { |
| 64 |
return nil, nil, err |
| 65 |
} |
| 66 |
|
| 67 |
req, err := s.client.NewRequest("GET", u, nil) |
| 68 |
if err != nil { |
| 69 |
return nil, nil, err |
| 70 |
} |
| 71 |
|
| 72 |
var milestones []*Milestone |
| 73 |
resp, err := s.client.Do(ctx, req, &milestones) |
| 74 |
if err != nil { |
| 75 |
return nil, resp, err |
| 76 |
} |
| 77 |
|
| 78 |
return milestones, resp, nil |
| 79 |
} |
| 80 |
|
| 81 |
// GetMilestone gets a single milestone. |
| 82 |
// |
| 83 |
// GitHub API docs: https://docs.github.com/rest/issues/milestones#get-a-milestone |
| 84 |
// |
| 85 |
//meta:operation GET /repos/{owner}/{repo}/milestones/{milestone_number} |
| 86 |
func (s *IssuesService) GetMilestone(ctx context.Context, owner string, repo string, number int) (*Milestone, *Response, error) { |
| 87 |
u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number) |
| 88 |
req, err := s.client.NewRequest("GET", u, nil) |
| 89 |
if err != nil { |
| 90 |
return nil, nil, err |
| 91 |
} |
| 92 |
|
| 93 |
milestone := new(Milestone) |
| 94 |
resp, err := s.client.Do(ctx, req, milestone) |
| 95 |
if err != nil { |
| 96 |
return nil, resp, err |
| 97 |
} |
| 98 |
|
| 99 |
return milestone, resp, nil |
| 100 |
} |
| 101 |
|
| 102 |
// CreateMilestone creates a new milestone on the specified repository. |
| 103 |
// |
| 104 |
// GitHub API docs: https://docs.github.com/rest/issues/milestones#create-a-milestone |
| 105 |
// |
| 106 |
//meta:operation POST /repos/{owner}/{repo}/milestones |
| 107 |
func (s *IssuesService) CreateMilestone(ctx context.Context, owner string, repo string, milestone *Milestone) (*Milestone, *Response, error) { |
| 108 |
u := fmt.Sprintf("repos/%v/%v/milestones", owner, repo) |
| 109 |
req, err := s.client.NewRequest("POST", u, milestone) |
| 110 |
if err != nil { |
| 111 |
return nil, nil, err |
| 112 |
} |
| 113 |
|
| 114 |
m := new(Milestone) |
| 115 |
resp, err := s.client.Do(ctx, req, m) |
| 116 |
if err != nil { |
| 117 |
return nil, resp, err |
| 118 |
} |
| 119 |
|
| 120 |
return m, resp, nil |
| 121 |
} |
| 122 |
|
| 123 |
// EditMilestone edits a milestone. |
| 124 |
// |
| 125 |
// GitHub API docs: https://docs.github.com/rest/issues/milestones#update-a-milestone |
| 126 |
// |
| 127 |
//meta:operation PATCH /repos/{owner}/{repo}/milestones/{milestone_number} |
| 128 |
func (s *IssuesService) EditMilestone(ctx context.Context, owner string, repo string, number int, milestone *Milestone) (*Milestone, *Response, error) { |
| 129 |
u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number) |
| 130 |
req, err := s.client.NewRequest("PATCH", u, milestone) |
| 131 |
if err != nil { |
| 132 |
return nil, nil, err |
| 133 |
} |
| 134 |
|
| 135 |
m := new(Milestone) |
| 136 |
resp, err := s.client.Do(ctx, req, m) |
| 137 |
if err != nil { |
| 138 |
return nil, resp, err |
| 139 |
} |
| 140 |
|
| 141 |
return m, resp, nil |
| 142 |
} |
| 143 |
|
| 144 |
// DeleteMilestone deletes a milestone. |
| 145 |
// |
| 146 |
// GitHub API docs: https://docs.github.com/rest/issues/milestones#delete-a-milestone |
| 147 |
// |
| 148 |
//meta:operation DELETE /repos/{owner}/{repo}/milestones/{milestone_number} |
| 149 |
func (s *IssuesService) DeleteMilestone(ctx context.Context, owner string, repo string, number int) (*Response, error) { |
| 150 |
u := fmt.Sprintf("repos/%v/%v/milestones/%d", owner, repo, number) |
| 151 |
req, err := s.client.NewRequest("DELETE", u, nil) |
| 152 |
if err != nil { |
| 153 |
return nil, err |
| 154 |
} |
| 155 |
|
| 156 |
return s.client.Do(ctx, req, nil) |
| 157 |
} |