fix most of all the lint errors
This commit is contained in:
parent
4d94826874
commit
c9135ef778
23 changed files with 167 additions and 29 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AdminCreateOrg create an organization
|
||||||
func (c *Client) AdminCreateOrg(user string, opt CreateOrgOption) (*Organization, error) {
|
func (c *Client) AdminCreateOrg(user string, opt CreateOrgOption) (*Organization, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AdminCreateRepo create a repo
|
||||||
func (c *Client) AdminCreateRepo(user string, opt CreateRepoOption) (*Repository, error) {
|
func (c *Client) AdminCreateRepo(user string, opt CreateRepoOption) (*Repository, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// CreateUserOption create user options
|
||||||
type CreateUserOption struct {
|
type CreateUserOption struct {
|
||||||
SourceID int64 `json:"source_id"`
|
SourceID int64 `json:"source_id"`
|
||||||
LoginName string `json:"login_name"`
|
LoginName string `json:"login_name"`
|
||||||
|
@ -20,6 +21,7 @@ type CreateUserOption struct {
|
||||||
SendNotify bool `json:"send_notify"`
|
SendNotify bool `json:"send_notify"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AdminCreateUser create a user
|
||||||
func (c *Client) AdminCreateUser(opt CreateUserOption) (*User, error) {
|
func (c *Client) AdminCreateUser(opt CreateUserOption) (*User, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -29,6 +31,7 @@ func (c *Client) AdminCreateUser(opt CreateUserOption) (*User, error) {
|
||||||
return user, c.getParsedResponse("POST", "/admin/users", jsonHeader, bytes.NewReader(body), user)
|
return user, c.getParsedResponse("POST", "/admin/users", jsonHeader, bytes.NewReader(body), user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditUserOption edit user options
|
||||||
type EditUserOption struct {
|
type EditUserOption struct {
|
||||||
SourceID int64 `json:"source_id"`
|
SourceID int64 `json:"source_id"`
|
||||||
LoginName string `json:"login_name"`
|
LoginName string `json:"login_name"`
|
||||||
|
@ -44,6 +47,7 @@ type EditUserOption struct {
|
||||||
MaxRepoCreation *int `json:"max_repo_creation"`
|
MaxRepoCreation *int `json:"max_repo_creation"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AdminEditUser modify user informations
|
||||||
func (c *Client) AdminEditUser(user string, opt EditUserOption) error {
|
func (c *Client) AdminEditUser(user string, opt EditUserOption) error {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -53,11 +57,13 @@ func (c *Client) AdminEditUser(user string, opt EditUserOption) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AdminDeleteUser delete one user according name
|
||||||
func (c *Client) AdminDeleteUser(user string) error {
|
func (c *Client) AdminDeleteUser(user string) error {
|
||||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s", user), nil, nil)
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s", user), nil, nil)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AdminCreateUserPublicKey create one user with options
|
||||||
func (c *Client) AdminCreateUserPublicKey(user string, opt CreateKeyOption) (*PublicKey, error) {
|
func (c *Client) AdminCreateUserPublicKey(user string, opt CreateKeyOption) (*PublicKey, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Version return the library version
|
||||||
func Version() string {
|
func Version() string {
|
||||||
return "0.12.3"
|
return "0.12.3"
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,49 +11,58 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StateType string
|
// PRStateType issue state type
|
||||||
|
type PRStateType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
STATE_OPEN StateType = "open"
|
// PRStateOpen pr is opend
|
||||||
STATE_CLOSED StateType = "closed"
|
PRStateOpen PRStateType = "open"
|
||||||
|
// PRStateClosed pr is closed
|
||||||
|
PRStateClosed PRStateType = "closed"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// PullRequestMeta PR info if an issue is a PR
|
||||||
type PullRequestMeta struct {
|
type PullRequestMeta struct {
|
||||||
HasMerged bool `json:"merged"`
|
HasMerged bool `json:"merged"`
|
||||||
Merged *time.Time `json:"merged_at"`
|
Merged *time.Time `json:"merged_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue an issue to a repository
|
||||||
type Issue struct {
|
type Issue struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Index int64 `json:"number"`
|
Index int64 `json:"number"`
|
||||||
Poster *User `json:"user"`
|
Poster *User `json:"user"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
Labels []*Label `json:"labels"`
|
Labels []*Label `json:"labels"`
|
||||||
Milestone *Milestone `json:"milestone"`
|
Milestone *Milestone `json:"milestone"`
|
||||||
Assignee *User `json:"assignee"`
|
Assignee *User `json:"assignee"`
|
||||||
State StateType `json:"state"`
|
State PRStateType `json:"state"`
|
||||||
Comments int `json:"comments"`
|
Comments int `json:"comments"`
|
||||||
Created time.Time `json:"created_at"`
|
Created time.Time `json:"created_at"`
|
||||||
Updated time.Time `json:"updated_at"`
|
Updated time.Time `json:"updated_at"`
|
||||||
|
|
||||||
PullRequest *PullRequestMeta `json:"pull_request"`
|
PullRequest *PullRequestMeta `json:"pull_request"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListIssueOption list issue options
|
||||||
type ListIssueOption struct {
|
type ListIssueOption struct {
|
||||||
Page int
|
Page int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListRepoIssues list one repos' issues
|
||||||
func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Issue, error) {
|
func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Issue, error) {
|
||||||
issues := make([]*Issue, 0, 10)
|
issues := make([]*Issue, 0, 10)
|
||||||
return issues, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues?page=%d", owner, repo, opt.Page), nil, nil, &issues)
|
return issues, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues?page=%d", owner, repo, opt.Page), nil, nil, &issues)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetIssue get some one issue of repository
|
||||||
func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, error) {
|
func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, error) {
|
||||||
issue := new(Issue)
|
issue := new(Issue)
|
||||||
return issue, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), nil, nil, issue)
|
return issue, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), nil, nil, issue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateIssueOption options to create one issue
|
||||||
type CreateIssueOption struct {
|
type CreateIssueOption struct {
|
||||||
Title string `json:"title" binding:"Required"`
|
Title string `json:"title" binding:"Required"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
|
@ -63,6 +72,7 @@ type CreateIssueOption struct {
|
||||||
Closed bool `json:"closed"`
|
Closed bool `json:"closed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateIssue create an issue with options
|
||||||
func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue, error) {
|
func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -73,6 +83,7 @@ func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue,
|
||||||
jsonHeader, bytes.NewReader(body), issue)
|
jsonHeader, bytes.NewReader(body), issue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditIssueOption edit issue options
|
||||||
type EditIssueOption struct {
|
type EditIssueOption struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Body *string `json:"body"`
|
Body *string `json:"body"`
|
||||||
|
@ -81,6 +92,7 @@ type EditIssueOption struct {
|
||||||
State *string `json:"state"`
|
State *string `json:"state"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditIssue modify an issue of repository
|
||||||
func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption) (*Issue, error) {
|
func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption) (*Issue, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -10,27 +10,33 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Label a label to an issue or a pr
|
||||||
type Label struct {
|
type Label struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Color string `json:"color"`
|
Color string `json:"color"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListRepoLabels list lables of one reppsitory
|
||||||
func (c *Client) ListRepoLabels(owner, repo string) ([]*Label, error) {
|
func (c *Client) ListRepoLabels(owner, repo string) ([]*Label, error) {
|
||||||
labels := make([]*Label, 0, 10)
|
labels := make([]*Label, 0, 10)
|
||||||
return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels", owner, repo), nil, nil, &labels)
|
return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels", owner, repo), nil, nil, &labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRepoLabel get one label of repository by repo it
|
||||||
|
// TODO: maybe we need get a label by name
|
||||||
func (c *Client) GetRepoLabel(owner, repo string, id int64) (*Label, error) {
|
func (c *Client) GetRepoLabel(owner, repo string, id int64) (*Label, error) {
|
||||||
label := new(Label)
|
label := new(Label)
|
||||||
return label, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil, label)
|
return label, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil, label)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateLabelOption create options when one label of repository
|
||||||
type CreateLabelOption struct {
|
type CreateLabelOption struct {
|
||||||
Name string `json:"name" binding:"Required"`
|
Name string `json:"name" binding:"Required"`
|
||||||
Color string `json:"color" binding:"Required;Size(7)"`
|
Color string `json:"color" binding:"Required;Size(7)"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateLabel create one label of repository
|
||||||
func (c *Client) CreateLabel(owner, repo string, opt CreateLabelOption) (*Label, error) {
|
func (c *Client) CreateLabel(owner, repo string, opt CreateLabelOption) (*Label, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -41,11 +47,13 @@ func (c *Client) CreateLabel(owner, repo string, opt CreateLabelOption) (*Label,
|
||||||
jsonHeader, bytes.NewReader(body), label)
|
jsonHeader, bytes.NewReader(body), label)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditLabelOption edit label options
|
||||||
type EditLabelOption struct {
|
type EditLabelOption struct {
|
||||||
Name *string `json:"name"`
|
Name *string `json:"name"`
|
||||||
Color *string `json:"color"`
|
Color *string `json:"color"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditLabel modify one label with options
|
||||||
func (c *Client) EditLabel(owner, repo string, id int64, opt EditLabelOption) (*Label, error) {
|
func (c *Client) EditLabel(owner, repo string, id int64, opt EditLabelOption) (*Label, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -55,43 +63,52 @@ func (c *Client) EditLabel(owner, repo string, id int64, opt EditLabelOption) (*
|
||||||
return label, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), label)
|
return label, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), label)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteLabel delete one label of repository by id
|
||||||
|
// TODO: maybe we need delete by name
|
||||||
func (c *Client) DeleteLabel(owner, repo string, id int64) error {
|
func (c *Client) DeleteLabel(owner, repo string, id int64) error {
|
||||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil)
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IssueLabelsOption list one issue's labels options
|
||||||
type IssueLabelsOption struct {
|
type IssueLabelsOption struct {
|
||||||
Labels []int64 `json:"labels"`
|
Labels []int64 `json:"labels"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetIssueLabels get labels of one issue via issue id
|
||||||
func (c *Client) GetIssueLabels(owner, repo string, index int64) ([]*Label, error) {
|
func (c *Client) GetIssueLabels(owner, repo string, index int64) ([]*Label, error) {
|
||||||
labels := make([]*Label, 0, 5)
|
labels := make([]*Label, 0, 5)
|
||||||
return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil, &labels)
|
return labels, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil, &labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddIssueLabels add one or more labels to one issue
|
||||||
func (c *Client) AddIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) {
|
func (c *Client) AddIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
labels := make([]*Label, 0)
|
var labels []*Label
|
||||||
return labels, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels)
|
return labels, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReplaceIssueLabels replace old labels of issue with new labels
|
||||||
func (c *Client) ReplaceIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) {
|
func (c *Client) ReplaceIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
labels := make([]*Label, 0)
|
var labels []*Label
|
||||||
return labels, c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels)
|
return labels, c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteIssueLabel delete one label of one issue by issue id and label id
|
||||||
|
// TODO: maybe we need delete by label name and issue id
|
||||||
func (c *Client) DeleteIssueLabel(owner, repo string, index, label int64) error {
|
func (c *Client) DeleteIssueLabel(owner, repo string, index, label int64) error {
|
||||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels/%d", owner, repo, index, label), nil, nil)
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels/%d", owner, repo, index, label), nil, nil)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClearIssueLabels delete all the labels of one issue.
|
||||||
func (c *Client) ClearIssueLabels(owner, repo string, index int64) error {
|
func (c *Client) ClearIssueLabels(owner, repo string, index int64) error {
|
||||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil)
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Milestone milestone is a collection of issues on one repository
|
||||||
type Milestone struct {
|
type Milestone struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
@ -22,22 +23,26 @@ type Milestone struct {
|
||||||
Deadline *time.Time `json:"due_on"`
|
Deadline *time.Time `json:"due_on"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListRepoMilestones list all the milestones of one repository
|
||||||
func (c *Client) ListRepoMilestones(owner, repo string) ([]*Milestone, error) {
|
func (c *Client) ListRepoMilestones(owner, repo string) ([]*Milestone, error) {
|
||||||
milestones := make([]*Milestone, 0, 10)
|
milestones := make([]*Milestone, 0, 10)
|
||||||
return milestones, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), nil, nil, &milestones)
|
return milestones, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), nil, nil, &milestones)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMilestone get one milestone by repo name and milestone id
|
||||||
func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, error) {
|
func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, error) {
|
||||||
milestone := new(Milestone)
|
milestone := new(Milestone)
|
||||||
return milestone, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil, milestone)
|
return milestone, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil, milestone)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateMilestoneOption options when creating milestone
|
||||||
type CreateMilestoneOption struct {
|
type CreateMilestoneOption struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Deadline *time.Time `json:"due_on"`
|
Deadline *time.Time `json:"due_on"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateMilestone create one milestone with options
|
||||||
func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption) (*Milestone, error) {
|
func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption) (*Milestone, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -47,6 +52,7 @@ func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption)
|
||||||
return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), jsonHeader, bytes.NewReader(body), milestone)
|
return milestone, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), jsonHeader, bytes.NewReader(body), milestone)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditMilestoneOption options when modify milestone
|
||||||
type EditMilestoneOption struct {
|
type EditMilestoneOption struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description *string `json:"description"`
|
Description *string `json:"description"`
|
||||||
|
@ -54,6 +60,7 @@ type EditMilestoneOption struct {
|
||||||
Deadline *time.Time `json:"due_on"`
|
Deadline *time.Time `json:"due_on"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditMilestone modify milestone with options
|
||||||
func (c *Client) EditMilestone(owner, repo string, id int64, opt EditMilestoneOption) (*Milestone, error) {
|
func (c *Client) EditMilestone(owner, repo string, id int64, opt EditMilestoneOption) (*Milestone, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -63,6 +70,7 @@ func (c *Client) EditMilestone(owner, repo string, id int64, opt EditMilestoneOp
|
||||||
return milestone, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), milestone)
|
return milestone, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), milestone)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteMilestone delete one milestone by milestone id
|
||||||
func (c *Client) DeleteMilestone(owner, repo string, id int64) error {
|
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)
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
package gitea
|
package gitea
|
||||||
|
|
||||||
|
// MarkdownOption markdown options
|
||||||
type MarkdownOption struct {
|
type MarkdownOption struct {
|
||||||
Text string
|
Text string
|
||||||
Mode string
|
Mode string
|
||||||
|
|
|
@ -10,31 +10,36 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Organization a group of some repositories, users and teams
|
||||||
type Organization struct {
|
type Organization struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
UserName string `json:"username"`
|
UserName string `json:"username"`
|
||||||
FullName string `json:"full_name"`
|
FullName string `json:"full_name"`
|
||||||
AvatarUrl string `json:"avatar_url"`
|
AvatarURL string `json:"avatar_url"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Website string `json:"website"`
|
Website string `json:"website"`
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListMyOrgs list all of current user's organizations
|
||||||
func (c *Client) ListMyOrgs() ([]*Organization, error) {
|
func (c *Client) ListMyOrgs() ([]*Organization, error) {
|
||||||
orgs := make([]*Organization, 0, 5)
|
orgs := make([]*Organization, 0, 5)
|
||||||
return orgs, c.getParsedResponse("GET", "/user/orgs", nil, nil, &orgs)
|
return orgs, c.getParsedResponse("GET", "/user/orgs", nil, nil, &orgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListUserOrgs list all of some user's organizations
|
||||||
func (c *Client) ListUserOrgs(user string) ([]*Organization, error) {
|
func (c *Client) ListUserOrgs(user string) ([]*Organization, error) {
|
||||||
orgs := make([]*Organization, 0, 5)
|
orgs := make([]*Organization, 0, 5)
|
||||||
return orgs, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/orgs", user), nil, nil, &orgs)
|
return orgs, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/orgs", user), nil, nil, &orgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetOrg get one organization by name
|
||||||
func (c *Client) GetOrg(orgname string) (*Organization, error) {
|
func (c *Client) GetOrg(orgname string) (*Organization, error) {
|
||||||
org := new(Organization)
|
org := new(Organization)
|
||||||
return org, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s", orgname), nil, nil, org)
|
return org, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s", orgname), nil, nil, org)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateOrgOption create one organization options
|
||||||
type CreateOrgOption struct {
|
type CreateOrgOption struct {
|
||||||
UserName string `json:"username" binding:"Required"`
|
UserName string `json:"username" binding:"Required"`
|
||||||
FullName string `json:"full_name"`
|
FullName string `json:"full_name"`
|
||||||
|
@ -43,6 +48,7 @@ type CreateOrgOption struct {
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditOrgOption edit one organization options
|
||||||
type EditOrgOption struct {
|
type EditOrgOption struct {
|
||||||
FullName string `json:"full_name"`
|
FullName string `json:"full_name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
|
@ -50,6 +56,7 @@ type EditOrgOption struct {
|
||||||
Location string `json:"location"`
|
Location string `json:"location"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditOrg modify one organization via options
|
||||||
func (c *Client) EditOrg(orgname string, opt EditOrgOption) error {
|
func (c *Client) EditOrg(orgname string, opt EditOrgOption) error {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -10,10 +10,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AddOrgMembershipOption add user to organization options
|
||||||
type AddOrgMembershipOption struct {
|
type AddOrgMembershipOption struct {
|
||||||
Role string `json:"role" binding:"Required"`
|
Role string `json:"role" binding:"Required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddOrgMembership add some one to an organization's member
|
||||||
func (c *Client) AddOrgMembership(org, user string, opt AddOrgMembershipOption) error {
|
func (c *Client) AddOrgMembership(org, user string, opt AddOrgMembershipOption) error {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
package gitea
|
package gitea
|
||||||
|
|
||||||
|
// Team is a sub virtual organization of one Organization
|
||||||
type Team struct {
|
type Team struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
@ -11,6 +12,7 @@ type Team struct {
|
||||||
Permission string `json:"permission"`
|
Permission string `json:"permission"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateTeamOption options when create team
|
||||||
type CreateTeamOption struct {
|
type CreateTeamOption struct {
|
||||||
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
|
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"`
|
||||||
Description string `json:"description" binding:"MaxSize(255)"`
|
Description string `json:"description" binding:"MaxSize(255)"`
|
||||||
|
|
|
@ -39,6 +39,7 @@ type PullRequest struct {
|
||||||
MergeBase string `json:"merge_base"`
|
MergeBase string `json:"merge_base"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PRBranchInfo base branch info when send a PR
|
||||||
type PRBranchInfo struct {
|
type PRBranchInfo struct {
|
||||||
Name string `json:"label"`
|
Name string `json:"label"`
|
||||||
Ref string `json:"ref"`
|
Ref string `json:"ref"`
|
||||||
|
@ -47,11 +48,13 @@ type PRBranchInfo struct {
|
||||||
Repository *Repository `json:"repo"`
|
Repository *Repository `json:"repo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListPullRequestsOptions options when list PRs
|
||||||
type ListPullRequestsOptions struct {
|
type ListPullRequestsOptions struct {
|
||||||
Page int `json:"page"`
|
Page int `json:"page"`
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListRepoPullRequests list PRs of one repository
|
||||||
func (c *Client) ListRepoPullRequests(owner, repo string, opt ListPullRequestsOptions) ([]*PullRequest, error) {
|
func (c *Client) ListRepoPullRequests(owner, repo string, opt ListPullRequestsOptions) ([]*PullRequest, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -61,11 +64,13 @@ func (c *Client) ListRepoPullRequests(owner, repo string, opt ListPullRequestsOp
|
||||||
return prs, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/pulls", owner, repo), jsonHeader, bytes.NewReader(body), &prs)
|
return prs, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/pulls", owner, repo), jsonHeader, bytes.NewReader(body), &prs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPullRequest get information of one PR
|
||||||
func (c *Client) GetPullRequest(owner, repo string, index int64) (*PullRequest, error) {
|
func (c *Client) GetPullRequest(owner, repo string, index int64) (*PullRequest, error) {
|
||||||
pr := new(PullRequest)
|
pr := new(PullRequest)
|
||||||
return pr, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d", owner, repo, index), nil, nil, pr)
|
return pr, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d", owner, repo, index), nil, nil, pr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreatePullRequestOption options when creating a pull request
|
||||||
type CreatePullRequestOption struct {
|
type CreatePullRequestOption struct {
|
||||||
Head string `json:"head" binding:"Required"`
|
Head string `json:"head" binding:"Required"`
|
||||||
Base string `json:"base" binding:"Required"`
|
Base string `json:"base" binding:"Required"`
|
||||||
|
@ -76,6 +81,7 @@ type CreatePullRequestOption struct {
|
||||||
Labels []int64 `json:"labels"`
|
Labels []int64 `json:"labels"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreatePullRequest create pull request with options
|
||||||
func (c *Client) CreatePullRequest(owner, repo string, opt CreatePullRequestOption) (*PullRequest, error) {
|
func (c *Client) CreatePullRequest(owner, repo string, opt CreatePullRequestOption) (*PullRequest, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -86,6 +92,7 @@ func (c *Client) CreatePullRequest(owner, repo string, opt CreatePullRequestOpti
|
||||||
jsonHeader, bytes.NewReader(body), pr)
|
jsonHeader, bytes.NewReader(body), pr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditPullRequestOption options when modify pull request
|
||||||
type EditPullRequestOption struct {
|
type EditPullRequestOption struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
|
@ -95,6 +102,7 @@ type EditPullRequestOption struct {
|
||||||
State *string `json:"state"`
|
State *string `json:"state"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditPullRequest modify pull request with PR id and options
|
||||||
func (c *Client) EditPullRequest(owner, repo string, index int64, opt EditPullRequestOption) (*PullRequest, error) {
|
func (c *Client) EditPullRequest(owner, repo string, index int64, opt EditPullRequestOption) (*PullRequest, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -105,11 +113,13 @@ func (c *Client) EditPullRequest(owner, repo string, index int64, opt EditPullRe
|
||||||
jsonHeader, bytes.NewReader(body), pr)
|
jsonHeader, bytes.NewReader(body), pr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MergePullRequest merge a PR to repository by PR id
|
||||||
func (c *Client) MergePullRequest(owner, repo string, index int64) error {
|
func (c *Client) MergePullRequest(owner, repo string, index int64) error {
|
||||||
_, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/pulls/%d/merge", owner, repo, index), nil, nil)
|
_, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/pulls/%d/merge", owner, repo, index), nil, nil)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsPullRequestMerged test if one PR is merged to one repository
|
||||||
func (c *Client) IsPullRequestMerged(owner, repo string, index int64) (bool, error) {
|
func (c *Client) IsPullRequestMerged(owner, repo string, index int64) (bool, error) {
|
||||||
statusCode, err := c.getStatusCode("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d/merge", owner, repo, index), nil, nil)
|
statusCode, err := c.getStatusCode("GET", fmt.Sprintf("/repos/%s/%s/pulls/%d/merge", owner, repo, index), nil, nil)
|
||||||
|
|
||||||
|
|
|
@ -47,16 +47,19 @@ func (c *Client) ListMyRepos() ([]*Repository, error) {
|
||||||
return repos, c.getParsedResponse("GET", "/user/repos", nil, nil, &repos)
|
return repos, c.getParsedResponse("GET", "/user/repos", nil, nil, &repos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListUserRepos list all repositories of one user by user's name
|
||||||
func (c *Client) ListUserRepos(user string) ([]*Repository, error) {
|
func (c *Client) ListUserRepos(user string) ([]*Repository, error) {
|
||||||
repos := make([]*Repository, 0, 10)
|
repos := make([]*Repository, 0, 10)
|
||||||
return repos, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/repos", user), nil, nil, &repos)
|
return repos, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/repos", user), nil, nil, &repos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListOrgRepos list all repositories of one organization by organization's name
|
||||||
func (c *Client) ListOrgRepos(org string) ([]*Repository, error) {
|
func (c *Client) ListOrgRepos(org string) ([]*Repository, error) {
|
||||||
repos := make([]*Repository, 0, 10)
|
repos := make([]*Repository, 0, 10)
|
||||||
return repos, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/repos", org), nil, nil, &repos)
|
return repos, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/repos", org), nil, nil, &repos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateRepoOption options when creating repository
|
||||||
type CreateRepoOption struct {
|
type CreateRepoOption struct {
|
||||||
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
|
Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"`
|
||||||
Description string `json:"description" binding:"MaxSize(255)"`
|
Description string `json:"description" binding:"MaxSize(255)"`
|
||||||
|
@ -99,6 +102,7 @@ func (c *Client) DeleteRepo(owner, repo string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MigrateRepoOption options when migrate repository from an external place
|
||||||
type MigrateRepoOption struct {
|
type MigrateRepoOption struct {
|
||||||
CloneAddr string `json:"clone_addr" binding:"Required"`
|
CloneAddr string `json:"clone_addr" binding:"Required"`
|
||||||
AuthUsername string `json:"auth_username"`
|
AuthUsername string `json:"auth_username"`
|
||||||
|
|
|
@ -14,11 +14,13 @@ type Branch struct {
|
||||||
Commit *PayloadCommit `json:"commit"`
|
Commit *PayloadCommit `json:"commit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListRepoBranches list all the branches of one repository
|
||||||
func (c *Client) ListRepoBranches(user, repo string) ([]*Branch, error) {
|
func (c *Client) ListRepoBranches(user, repo string) ([]*Branch, error) {
|
||||||
branches := make([]*Branch, 0, 10)
|
branches := make([]*Branch, 0, 10)
|
||||||
return branches, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches", user, repo), nil, nil, &branches)
|
return branches, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches", user, repo), nil, nil, &branches)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetRepoBranch get one branch's information of one repository
|
||||||
func (c *Client) GetRepoBranch(user, repo, branch string) (*Branch, error) {
|
func (c *Client) GetRepoBranch(user, repo, branch string) (*Branch, error) {
|
||||||
b := new(Branch)
|
b := new(Branch)
|
||||||
return b, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches/%s", user, repo, branch), nil, nil, &b)
|
return b, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches/%s", user, repo, branch), nil, nil, &b)
|
||||||
|
|
|
@ -10,10 +10,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AddCollaboratorOption options when add some user as a collaborator of a repository
|
||||||
type AddCollaboratorOption struct {
|
type AddCollaboratorOption struct {
|
||||||
Permission *string `json:"permission"`
|
Permission *string `json:"permission"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddCollaborator add some user as a collaborator of a repository
|
||||||
func (c *Client) AddCollaborator(user, repo, collaborator string, opt AddCollaboratorOption) error {
|
func (c *Client) AddCollaborator(user, repo, collaborator string, opt AddCollaboratorOption) error {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -14,9 +14,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// ErrInvalidReceiveHook FIXME
|
||||||
ErrInvalidReceiveHook = errors.New("Invalid JSON payload received over webhook")
|
ErrInvalidReceiveHook = errors.New("Invalid JSON payload received over webhook")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Hook a hook is a web hook when one repository changed
|
||||||
type Hook struct {
|
type Hook struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
@ -28,11 +30,13 @@ type Hook struct {
|
||||||
Created time.Time `json:"created_at"`
|
Created time.Time `json:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListRepoHooks list all the hooks of one repository
|
||||||
func (c *Client) ListRepoHooks(user, repo string) ([]*Hook, error) {
|
func (c *Client) ListRepoHooks(user, repo string) ([]*Hook, error) {
|
||||||
hooks := make([]*Hook, 0, 10)
|
hooks := make([]*Hook, 0, 10)
|
||||||
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), nil, nil, &hooks)
|
return hooks, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), nil, nil, &hooks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateHookOption options when create a hook
|
||||||
type CreateHookOption struct {
|
type CreateHookOption struct {
|
||||||
Type string `json:"type" binding:"Required"`
|
Type string `json:"type" binding:"Required"`
|
||||||
Config map[string]string `json:"config" binding:"Required"`
|
Config map[string]string `json:"config" binding:"Required"`
|
||||||
|
@ -40,6 +44,7 @@ type CreateHookOption struct {
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateRepoHook create one hook with options
|
||||||
func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, error) {
|
func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -49,12 +54,14 @@ func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook,
|
||||||
return h, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), jsonHeader, bytes.NewReader(body), h)
|
return h, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), jsonHeader, bytes.NewReader(body), h)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditHookOption options when modify one hook
|
||||||
type EditHookOption struct {
|
type EditHookOption struct {
|
||||||
Config map[string]string `json:"config"`
|
Config map[string]string `json:"config"`
|
||||||
Events []string `json:"events"`
|
Events []string `json:"events"`
|
||||||
Active *bool `json:"active"`
|
Active *bool `json:"active"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EditRepoHook modify one hook with hook id and options
|
||||||
func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) error {
|
func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) error {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -64,23 +71,26 @@ func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) e
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteRepoHook delete one hook with hook id
|
||||||
func (c *Client) DeleteRepoHook(user, repo string, id int64) error {
|
func (c *Client) DeleteRepoHook(user, repo string, id int64) error {
|
||||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), nil, nil)
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), nil, nil)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Payloader payload is some part of one hook
|
||||||
type Payloader interface {
|
type Payloader interface {
|
||||||
SetSecret(string)
|
SetSecret(string)
|
||||||
JSONPayload() ([]byte, error)
|
JSONPayload() ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PayloadUser FIXME
|
||||||
type PayloadUser struct {
|
type PayloadUser struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
UserName string `json:"username"`
|
UserName string `json:"username"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: consider use same format as API when commits API are added.
|
// PayloadCommit FIXME: consider use same format as API when commits API are added.
|
||||||
type PayloadCommit struct {
|
type PayloadCommit struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
|
@ -103,6 +113,7 @@ var (
|
||||||
// \______ /|__| \___ >____ /__| \___ >
|
// \______ /|__| \___ >____ /__| \___ >
|
||||||
// \/ \/ \/ \/
|
// \/ \/ \/ \/
|
||||||
|
|
||||||
|
// CreatePayload FIXME
|
||||||
type CreatePayload struct {
|
type CreatePayload struct {
|
||||||
Secret string `json:"secret"`
|
Secret string `json:"secret"`
|
||||||
Ref string `json:"ref"`
|
Ref string `json:"ref"`
|
||||||
|
@ -111,10 +122,12 @@ type CreatePayload struct {
|
||||||
Sender *User `json:"sender"`
|
Sender *User `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSecret FIXME
|
||||||
func (p *CreatePayload) SetSecret(secret string) {
|
func (p *CreatePayload) SetSecret(secret string) {
|
||||||
p.Secret = secret
|
p.Secret = secret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JSONPayload return payload information
|
||||||
func (p *CreatePayload) JSONPayload() ([]byte, error) {
|
func (p *CreatePayload) JSONPayload() ([]byte, error) {
|
||||||
return json.MarshalIndent(p, "", " ")
|
return json.MarshalIndent(p, "", " ")
|
||||||
}
|
}
|
||||||
|
@ -159,10 +172,12 @@ type PushPayload struct {
|
||||||
Sender *User `json:"sender"`
|
Sender *User `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSecret FIXME
|
||||||
func (p *PushPayload) SetSecret(secret string) {
|
func (p *PushPayload) SetSecret(secret string) {
|
||||||
p.Secret = secret
|
p.Secret = secret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JSONPayload FIXME
|
||||||
func (p *PushPayload) JSONPayload() ([]byte, error) {
|
func (p *PushPayload) JSONPayload() ([]byte, error) {
|
||||||
return json.MarshalIndent(p, "", " ")
|
return json.MarshalIndent(p, "", " ")
|
||||||
}
|
}
|
||||||
|
@ -195,24 +210,36 @@ func (p *PushPayload) Branch() string {
|
||||||
// |___/____ >____ >____/ \___ >
|
// |___/____ >____ >____/ \___ >
|
||||||
// \/ \/ \/
|
// \/ \/ \/
|
||||||
|
|
||||||
|
// HookIssueAction FIXME
|
||||||
type HookIssueAction string
|
type HookIssueAction string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
HOOK_ISSUE_OPENED HookIssueAction = "opened"
|
// HookIssueOpened opened
|
||||||
HOOK_ISSUE_CLOSED HookIssueAction = "closed"
|
HookIssueOpened HookIssueAction = "opened"
|
||||||
HOOK_ISSUE_REOPENED HookIssueAction = "reopened"
|
// HookIssueClosed closed
|
||||||
HOOK_ISSUE_EDITED HookIssueAction = "edited"
|
HookIssueClosed HookIssueAction = "closed"
|
||||||
HOOK_ISSUE_ASSIGNED HookIssueAction = "assigned"
|
// HookIssueReOpened reopened
|
||||||
HOOK_ISSUE_UNASSIGNED HookIssueAction = "unassigned"
|
HookIssueReOpened HookIssueAction = "reopened"
|
||||||
HOOK_ISSUE_LABEL_UPDATED HookIssueAction = "label_updated"
|
// HookIssueEdited edited
|
||||||
HOOK_ISSUE_LABEL_CLEARED HookIssueAction = "label_cleared"
|
HookIssueEdited HookIssueAction = "edited"
|
||||||
HOOK_ISSUE_SYNCHRONIZED HookIssueAction = "synchronized"
|
// HookIssueAssigned assigned
|
||||||
|
HookIssueAssigned HookIssueAction = "assigned"
|
||||||
|
// HookIssueUnassigned unassigned
|
||||||
|
HookIssueUnassigned HookIssueAction = "unassigned"
|
||||||
|
// HookIssueLabelUpdated label_updated
|
||||||
|
HookIssueLabelUpdated HookIssueAction = "label_updated"
|
||||||
|
// HookIssueLabelCleared label_cleared
|
||||||
|
HookIssueLabelCleared HookIssueAction = "label_cleared"
|
||||||
|
// HookIssueSynchronized synchronized
|
||||||
|
HookIssueSynchronized HookIssueAction = "synchronized"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ChangesFromPayload FIXME
|
||||||
type ChangesFromPayload struct {
|
type ChangesFromPayload struct {
|
||||||
From string `json:"from"`
|
From string `json:"from"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ChangesPayload FIXME
|
||||||
type ChangesPayload struct {
|
type ChangesPayload struct {
|
||||||
Title *ChangesFromPayload `json:"title,omitempty"`
|
Title *ChangesFromPayload `json:"title,omitempty"`
|
||||||
Body *ChangesFromPayload `json:"body,omitempty"`
|
Body *ChangesFromPayload `json:"body,omitempty"`
|
||||||
|
@ -236,10 +263,12 @@ type PullRequestPayload struct {
|
||||||
Sender *User `json:"sender"`
|
Sender *User `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSecret FIXME
|
||||||
func (p *PullRequestPayload) SetSecret(secret string) {
|
func (p *PullRequestPayload) SetSecret(secret string) {
|
||||||
p.Secret = secret
|
p.Secret = secret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JSONPayload FIXME
|
||||||
func (p *PullRequestPayload) JSONPayload() ([]byte, error) {
|
func (p *PullRequestPayload) JSONPayload() ([]byte, error) {
|
||||||
return json.MarshalIndent(p, "", " ")
|
return json.MarshalIndent(p, "", " ")
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DeployKey a deploy key
|
||||||
type DeployKey struct {
|
type DeployKey struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
|
@ -20,21 +21,25 @@ type DeployKey struct {
|
||||||
ReadOnly bool `json:"read_only"`
|
ReadOnly bool `json:"read_only"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListDeployKeys list all the deploy keys of one repository
|
||||||
func (c *Client) ListDeployKeys(user, repo string) ([]*DeployKey, error) {
|
func (c *Client) ListDeployKeys(user, repo string) ([]*DeployKey, error) {
|
||||||
keys := make([]*DeployKey, 0, 10)
|
keys := make([]*DeployKey, 0, 10)
|
||||||
return keys, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys", user, repo), nil, nil, &keys)
|
return keys, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys", user, repo), nil, nil, &keys)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDeployKey get one deploy key with key id
|
||||||
func (c *Client) GetDeployKey(user, repo string, keyID int64) (*DeployKey, error) {
|
func (c *Client) GetDeployKey(user, repo string, keyID int64) (*DeployKey, error) {
|
||||||
key := new(DeployKey)
|
key := new(DeployKey)
|
||||||
return key, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys/%d", user, repo, keyID), nil, nil, &key)
|
return key, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/keys/%d", user, repo, keyID), nil, nil, &key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateKeyOption options when create deploy key
|
||||||
type CreateKeyOption struct {
|
type CreateKeyOption struct {
|
||||||
Title string `json:"title" binding:"Required"`
|
Title string `json:"title" binding:"Required"`
|
||||||
Key string `json:"key" binding:"Required"`
|
Key string `json:"key" binding:"Required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateDeployKey options when create one deploy key
|
||||||
func (c *Client) CreateDeployKey(user, repo string, opt CreateKeyOption) (*DeployKey, error) {
|
func (c *Client) CreateDeployKey(user, repo string, opt CreateKeyOption) (*DeployKey, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -44,6 +49,7 @@ func (c *Client) CreateDeployKey(user, repo string, opt CreateKeyOption) (*Deplo
|
||||||
return key, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/keys", user, repo), jsonHeader, bytes.NewReader(body), key)
|
return key, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/keys", user, repo), jsonHeader, bytes.NewReader(body), key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteDeployKey delete deploy key with key id
|
||||||
func (c *Client) DeleteDeployKey(owner, repo string, keyID int64) error {
|
func (c *Client) DeleteDeployKey(owner, repo string, keyID int64) error {
|
||||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/keys/%d", owner, repo, keyID), nil, nil)
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/keys/%d", owner, repo, keyID), nil, nil)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -14,9 +14,10 @@ type User struct {
|
||||||
UserName string `json:"username"`
|
UserName string `json:"username"`
|
||||||
FullName string `json:"full_name"`
|
FullName string `json:"full_name"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
AvatarUrl string `json:"avatar_url"`
|
AvatarURL string `json:"avatar_url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUserInfo get user info by user's name
|
||||||
func (c *Client) GetUserInfo(user string) (*User, error) {
|
func (c *Client) GetUserInfo(user string) (*User, error) {
|
||||||
u := new(User)
|
u := new(User)
|
||||||
err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)
|
err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// BasicAuthEncode generate base64 of basic auth head
|
||||||
func BasicAuthEncode(user, pass string) string {
|
func BasicAuthEncode(user, pass string) string {
|
||||||
return base64.StdEncoding.EncodeToString([]byte(user + ":" + pass))
|
return base64.StdEncoding.EncodeToString([]byte(user + ":" + pass))
|
||||||
}
|
}
|
||||||
|
@ -22,16 +23,19 @@ type AccessToken struct {
|
||||||
Sha1 string `json:"sha1"`
|
Sha1 string `json:"sha1"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListAccessTokens lista all the access tokens of user
|
||||||
func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) {
|
func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) {
|
||||||
tokens := make([]*AccessToken, 0, 10)
|
tokens := make([]*AccessToken, 0, 10)
|
||||||
return tokens, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/tokens", user),
|
return tokens, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/tokens", user),
|
||||||
http.Header{"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, nil, &tokens)
|
http.Header{"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, nil, &tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateAccessTokenOption options when create access token
|
||||||
type CreateAccessTokenOption struct {
|
type CreateAccessTokenOption struct {
|
||||||
Name string `json:"name" binding:"Required"`
|
Name string `json:"name" binding:"Required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateAccessToken create one access token with options
|
||||||
func (c *Client) CreateAccessToken(user, pass string, opt CreateAccessTokenOption) (*AccessToken, error) {
|
func (c *Client) CreateAccessToken(user, pass string, opt CreateAccessTokenOption) (*AccessToken, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -9,21 +9,25 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Email en email information of user
|
||||||
type Email struct {
|
type Email struct {
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Verified bool `json:"verified"`
|
Verified bool `json:"verified"`
|
||||||
Primary bool `json:"primary"`
|
Primary bool `json:"primary"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListEmails all the email addresses of user
|
||||||
func (c *Client) ListEmails() ([]*Email, error) {
|
func (c *Client) ListEmails() ([]*Email, error) {
|
||||||
emails := make([]*Email, 0, 3)
|
emails := make([]*Email, 0, 3)
|
||||||
return emails, c.getParsedResponse("GET", "/user/emails", nil, nil, &emails)
|
return emails, c.getParsedResponse("GET", "/user/emails", nil, nil, &emails)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateEmailOption options when create an email
|
||||||
type CreateEmailOption struct {
|
type CreateEmailOption struct {
|
||||||
Emails []string `json:"emails"`
|
Emails []string `json:"emails"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddEmail add one email to current user with options
|
||||||
func (c *Client) AddEmail(opt CreateEmailOption) ([]*Email, error) {
|
func (c *Client) AddEmail(opt CreateEmailOption) ([]*Email, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -33,6 +37,7 @@ func (c *Client) AddEmail(opt CreateEmailOption) ([]*Email, error) {
|
||||||
return emails, c.getParsedResponse("POST", "/user/emails", jsonHeader, bytes.NewReader(body), emails)
|
return emails, c.getParsedResponse("POST", "/user/emails", jsonHeader, bytes.NewReader(body), emails)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteEmail delete one email of current users'
|
||||||
func (c *Client) DeleteEmail(opt CreateEmailOption) error {
|
func (c *Client) DeleteEmail(opt CreateEmailOption) error {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -6,41 +6,49 @@ package gitea
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
|
// ListMyFollowers list all the followers of current user
|
||||||
func (c *Client) ListMyFollowers(page int) ([]*User, error) {
|
func (c *Client) ListMyFollowers(page int) ([]*User, error) {
|
||||||
users := make([]*User, 0, 10)
|
users := make([]*User, 0, 10)
|
||||||
return users, c.getParsedResponse("GET", fmt.Sprintf("/user/followers?page=%d", page), nil, nil, &users)
|
return users, c.getParsedResponse("GET", fmt.Sprintf("/user/followers?page=%d", page), nil, nil, &users)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListFollowers list all the followers of one user
|
||||||
func (c *Client) ListFollowers(user string, page int) ([]*User, error) {
|
func (c *Client) ListFollowers(user string, page int) ([]*User, error) {
|
||||||
users := make([]*User, 0, 10)
|
users := make([]*User, 0, 10)
|
||||||
return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/followers?page=%d", user, page), nil, nil, &users)
|
return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/followers?page=%d", user, page), nil, nil, &users)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListMyFollowing list all the users current user followed
|
||||||
func (c *Client) ListMyFollowing(page int) ([]*User, error) {
|
func (c *Client) ListMyFollowing(page int) ([]*User, error) {
|
||||||
users := make([]*User, 0, 10)
|
users := make([]*User, 0, 10)
|
||||||
return users, c.getParsedResponse("GET", fmt.Sprintf("/user/following?page=%d", page), nil, nil, &users)
|
return users, c.getParsedResponse("GET", fmt.Sprintf("/user/following?page=%d", page), nil, nil, &users)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListFollowing list all the users the user followed
|
||||||
func (c *Client) ListFollowing(user string, page int) ([]*User, error) {
|
func (c *Client) ListFollowing(user string, page int) ([]*User, error) {
|
||||||
users := make([]*User, 0, 10)
|
users := make([]*User, 0, 10)
|
||||||
return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/following?page=%d", user, page), nil, nil, &users)
|
return users, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/following?page=%d", user, page), nil, nil, &users)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsFollowing if current user followed the target
|
||||||
func (c *Client) IsFollowing(target string) bool {
|
func (c *Client) IsFollowing(target string) bool {
|
||||||
_, err := c.getResponse("GET", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
_, err := c.getResponse("GET", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsUserFollowing if the user followed the target
|
||||||
func (c *Client) IsUserFollowing(user, target string) bool {
|
func (c *Client) IsUserFollowing(user, target string) bool {
|
||||||
_, err := c.getResponse("GET", fmt.Sprintf("/users/%s/following/%s", user, target), nil, nil)
|
_, err := c.getResponse("GET", fmt.Sprintf("/users/%s/following/%s", user, target), nil, nil)
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Follow set current user follow the target
|
||||||
func (c *Client) Follow(target string) error {
|
func (c *Client) Follow(target string) error {
|
||||||
_, err := c.getResponse("PUT", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
_, err := c.getResponse("PUT", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unfollow set current user unfollow the target
|
||||||
func (c *Client) Unfollow(target string) error {
|
func (c *Client) Unfollow(target string) error {
|
||||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/user/following/%s", target), nil, nil)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// PublicKey publickey is a user key to push code to repository
|
||||||
type PublicKey struct {
|
type PublicKey struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
|
@ -19,21 +20,25 @@ type PublicKey struct {
|
||||||
Created time.Time `json:"created_at,omitempty"`
|
Created time.Time `json:"created_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListPublicKeys list all the public keys of the user
|
||||||
func (c *Client) ListPublicKeys(user string) ([]*PublicKey, error) {
|
func (c *Client) ListPublicKeys(user string) ([]*PublicKey, error) {
|
||||||
keys := make([]*PublicKey, 0, 10)
|
keys := make([]*PublicKey, 0, 10)
|
||||||
return keys, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/keys", user), nil, nil, &keys)
|
return keys, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/keys", user), nil, nil, &keys)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListMyPublicKeys list all the public keys of current user
|
||||||
func (c *Client) ListMyPublicKeys() ([]*PublicKey, error) {
|
func (c *Client) ListMyPublicKeys() ([]*PublicKey, error) {
|
||||||
keys := make([]*PublicKey, 0, 10)
|
keys := make([]*PublicKey, 0, 10)
|
||||||
return keys, c.getParsedResponse("GET", "/user/keys", nil, nil, &keys)
|
return keys, c.getParsedResponse("GET", "/user/keys", nil, nil, &keys)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPublicKey get current user's public key by key id
|
||||||
func (c *Client) GetPublicKey(keyID int64) (*PublicKey, error) {
|
func (c *Client) GetPublicKey(keyID int64) (*PublicKey, error) {
|
||||||
key := new(PublicKey)
|
key := new(PublicKey)
|
||||||
return key, c.getParsedResponse("GET", fmt.Sprintf("/user/keys/%d", keyID), nil, nil, &key)
|
return key, c.getParsedResponse("GET", fmt.Sprintf("/user/keys/%d", keyID), nil, nil, &key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreatePublicKey create public key with options
|
||||||
func (c *Client) CreatePublicKey(opt CreateKeyOption) (*PublicKey, error) {
|
func (c *Client) CreatePublicKey(opt CreateKeyOption) (*PublicKey, error) {
|
||||||
body, err := json.Marshal(&opt)
|
body, err := json.Marshal(&opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -43,6 +48,7 @@ func (c *Client) CreatePublicKey(opt CreateKeyOption) (*PublicKey, error) {
|
||||||
return key, c.getParsedResponse("POST", "/user/keys", jsonHeader, bytes.NewReader(body), key)
|
return key, c.getParsedResponse("POST", "/user/keys", jsonHeader, bytes.NewReader(body), key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeletePublicKey delete public key with key id
|
||||||
func (c *Client) DeletePublicKey(keyID int64) error {
|
func (c *Client) DeletePublicKey(keyID int64) error {
|
||||||
_, err := c.getResponse("DELETE", fmt.Sprintf("/user/keys/%d", keyID), nil, nil)
|
_, err := c.getResponse("DELETE", fmt.Sprintf("/user/keys/%d", keyID), nil, nil)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -10,14 +10,17 @@ import (
|
||||||
|
|
||||||
var jsonHeader = http.Header{"content-type": []string{"application/json"}}
|
var jsonHeader = http.Header{"content-type": []string{"application/json"}}
|
||||||
|
|
||||||
|
// Bool return address of bool value
|
||||||
func Bool(v bool) *bool {
|
func Bool(v bool) *bool {
|
||||||
return &v
|
return &v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String return address of string value
|
||||||
func String(v string) *string {
|
func String(v string) *string {
|
||||||
return &v
|
return &v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Int64 return address of int64 value
|
||||||
func Int64(v int64) *int64 {
|
func Int64(v int64) *int64 {
|
||||||
return &v
|
return &v
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue