-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmilestones.go
More file actions
73 lines (65 loc) · 2.13 KB
/
Copy pathmilestones.go
File metadata and controls
73 lines (65 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package gitcode
import (
"context"
"fmt"
"net/http"
)
type ListMilestonesOptions struct {
ListOptions
State string `json:"state,omitempty"`
Sort string `json:"sort,omitempty"`
Direction string `json:"direction,omitempty"`
}
func (c *Client) ListMilestonesWithOptions(ctx context.Context, owner, repo string, opts ListMilestonesOptions) ([]*Milestone, error) {
var milestones []*Milestone
query := opts.toQuery()
if opts.State != "" {
query += "&state=" + opts.State
}
if opts.Sort != "" {
query += "&sort=" + opts.Sort
}
if opts.Direction != "" {
query += "&direction=" + opts.Direction
}
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/repos/%s/%s/milestones?%s", owner, repo, query), nil, &milestones)
if err != nil {
return nil, err
}
return milestones, nil
}
func (c *Client) GetMilestone(ctx context.Context, owner, repo string, number int) (*Milestone, error) {
var milestone Milestone
err := c.doRequest(ctx, http.MethodGet, fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, number), nil, &milestone)
if err != nil {
return nil, err
}
return &milestone, nil
}
type UpdateMilestoneOptions struct {
Title string `json:"title"`
State string `json:"state,omitempty"`
Description string `json:"description,omitempty"`
DueOn string `json:"due_on"`
}
func (c *Client) UpdateMilestone(ctx context.Context, owner, repo string, number int, opts UpdateMilestoneOptions) (*Milestone, error) {
var milestone Milestone
err := c.doRequest(ctx, http.MethodPatch, fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, number), opts, &milestone)
if err != nil {
return nil, err
}
return &milestone, nil
}
type CreateMilestoneOptions struct {
Title string `json:"title"`
Description string `json:"description,omitempty"`
DueOn string `json:"due_on"`
}
func (c *Client) CreateMilestoneWithOptions(ctx context.Context, owner, repo string, opts CreateMilestoneOptions) (*Milestone, error) {
var milestone Milestone
err := c.doRequest(ctx, http.MethodPost, fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), opts, &milestone)
if err != nil {
return nil, err
}
return &milestone, nil
}