Skip to content

Additional API support for milestones #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 87 additions & 1 deletion issue_milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

package gogs

import "time"
import (
"bytes"
"encoding/json"
"fmt"
"time"
)

type Milestone struct {
ID int64 `json:"id"`
Expand All @@ -16,3 +21,84 @@ type Milestone struct {
Closed *time.Time `json:"closed_at"`
Deadline *time.Time `json:"due_on"`
}

type CreateMilestoneOption struct {
Title string `json:"title"`
Description string `json:"description"`
Deadline *time.Time `json:"due_on"`
}

type EditMilestoneOption struct {
Title string `json:"title"`
Description string `json:"description"`
Deadline *time.Time `json:"due_on"`
}

type SetIssueMilestoneOption struct {
ID int64 `json:"id"`
}

func (c *Client) ListRepoMilestones(owner, repo string) ([]*Milestone, error) {
milestones := make([]*Milestone, 0, 10)
return milestones, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), nil, nil, &milestones)
}

func (c *Client) GetRepoMilestone(owner, repo string, id int64) (*Milestone, error) {
milestone := new(Milestone)
return milestone, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil, milestone)
}

func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption) (*Milestone, error) {
body, err := json.Marshal(&opt)
if err != nil {
return nil, err
}
milestone := new(Milestone)
return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo),
jsonHeader, bytes.NewReader(body), milestone)
}

func (c *Client) EditMilestone(owner, repo string, id int64, opt EditMilestoneOption) (*Milestone, error) {
body, err := json.Marshal(&opt)
if err != nil {
return nil, err
}
milestone := new(Milestone)
return milestone, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), milestone)
}

func (c *Client) DeleteMilestone(owner, repo string, id int64) error {
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil)
return err
}

func (c *Client) ChangeMilestoneStatus(owner, repo string, id int64, open bool) (*Milestone, error) {
var action string
if open {
action = "open"
} else {
action = "close"
}

milestone := new(Milestone)
return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones/%d/%s", owner, repo, id, action), nil, nil, milestone)
}

func (c *Client) GetIssueMilestone(owner, repo string, index int64) (*Milestone, error) {
milestone := new(Milestone)
return milestone, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/milestone", owner, repo, index), nil, nil, &milestone)
}

func (c *Client) SetIssueMilestone(owner, repo string, index int64, opt SetIssueMilestoneOption) (*Milestone, error) {
body, err := json.Marshal(&opt)
if err != nil {
return nil, err
}
milestone := new(Milestone)
return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/milestone", owner, repo, index), jsonHeader, bytes.NewReader(body), &milestone)
}

func (c *Client) DeleteIssueMilestone(owner, repo string, index int64) error {
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/milestone", owner, repo, index), nil, nil)
return err
}