Update gitea/sdk vendor

release/v1.15
Kim "BKC" Carlbäcker 2016-11-29 09:09:17 +01:00
parent f364522468
commit 57dc9efaae
26 changed files with 301 additions and 33 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

5
vendor/code.gitea.io/sdk/gitea/doc.go generated vendored Normal file
View File

@ -0,0 +1,5 @@
// Copyright 2016 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package gitea // import "code.gitea.io/sdk/gitea"

View File

@ -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"
} }
@ -88,3 +89,13 @@ func (c *Client) getParsedResponse(method, path string, header http.Header, body
} }
return json.Unmarshal(data, obj) return json.Unmarshal(data, obj)
} }
func (c *Client) getStatusCode(method, path string, header http.Header, body io.Reader) (int, error) {
resp, err := c.doRequest(method, path, header, body)
if err != nil {
return -1, err
}
defer resp.Body.Close()
return resp.StatusCode, nil
}

View File

@ -11,18 +11,23 @@ import (
"time" "time"
) )
// StateType issue state type
type StateType string type StateType string
const ( const (
STATE_OPEN StateType = "open" // StateOpen pr is opend
STATE_CLOSED StateType = "closed" StateOpen StateType = "open"
// StateClosed pr is closed
StateClosed StateType = "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"`
@ -40,20 +45,37 @@ type Issue struct {
PullRequest *PullRequestMeta `json:"pull_request"` PullRequest *PullRequestMeta `json:"pull_request"`
} }
// ListIssueOption list issue options
type ListIssueOption struct { type ListIssueOption struct {
Page int Page int
State string
} }
// ListIssues returns all issues assigned the authenticated user
func (c *Client) ListIssues(opt ListIssueOption) ([]*Issue, error) {
issues := make([]*Issue, 0, 10)
return issues, c.getParsedResponse("GET", fmt.Sprintf("/issues?page=%d", opt.Page), nil, nil, &issues)
}
// ListUserIssues returns all issues assigned to the authenticated user
func (c *Client) ListUserIssues(opt ListIssueOption) ([]*Issue, error) {
issues := make([]*Issue, 0, 10)
return issues, c.getParsedResponse("GET", fmt.Sprintf("/user/issues?page=%d", opt.Page), nil, nil, &issues)
}
// ListRepoIssues returns all issues for a given repository
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 returns a single issue for a given 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 +85,7 @@ type CreateIssueOption struct {
Closed bool `json:"closed"` Closed bool `json:"closed"`
} }
// CreateIssue create a new issue for a given repository
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 +96,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 +105,7 @@ type EditIssueOption struct {
State *string `json:"state"` State *string `json:"state"`
} }
// EditIssue modify an existing issue for a given 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 {

View File

@ -14,6 +14,9 @@ import (
// Comment represents a comment in commit and issue page. // Comment represents a comment in commit and issue page.
type Comment struct { type Comment struct {
ID int64 `json:"id"` ID int64 `json:"id"`
HTMLURL string `json:"html_url"`
PRURL string `json:"pull_request_url"`
IssueURL string `json:"issue_url"`
Poster *User `json:"user"` Poster *User `json:"user"`
Body string `json:"body"` Body string `json:"body"`
Created time.Time `json:"created_at"` Created time.Time `json:"created_at"`
@ -26,6 +29,12 @@ func (c *Client) ListIssueComments(owner, repo string, index int64) ([]*Comment,
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), nil, nil, &comments) return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), nil, nil, &comments)
} }
// ListRepoIssueComments list comments for a given repo.
func (c *Client) ListRepoIssueComments(owner, repo string) ([]*Comment, error) {
comments := make([]*Comment, 0, 10)
return comments, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments", owner, repo), nil, nil, &comments)
}
// CreateIssueCommentOption is option when creating an issue comment. // CreateIssueCommentOption is option when creating an issue comment.
type CreateIssueCommentOption struct { type CreateIssueCommentOption struct {
Body string `json:"body" binding:"Required"` Body string `json:"body" binding:"Required"`
@ -55,3 +64,9 @@ func (c *Client) EditIssueComment(owner, repo string, index, commentID int64, op
comment := new(Comment) comment := new(Comment)
return comment, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/:%s/:%s/issues/%d/comments/%d", owner, repo, index, commentID), jsonHeader, bytes.NewReader(body), comment) return comment, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/:%s/:%s/issues/%d/comments/%d", owner, repo, index, commentID), jsonHeader, bytes.NewReader(body), comment)
} }
// DeleteIssueComment deletes an issue comment.
func (c *Client) DeleteIssueComment(owner, repo string, index, commentID int64) error {
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/comments/%d", owner, repo, index, commentID), nil, nil)
return err
}

View File

@ -10,27 +10,34 @@ 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"`
URL string `json:"url"`
} }
// 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 +48,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 +64,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

View File

@ -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

View File

@ -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

View File

@ -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 {

View File

@ -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 {

View File

@ -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)"`

View File

@ -5,12 +5,14 @@
package gitea package gitea
import ( import (
"bytes"
"encoding/json"
"fmt"
"time" "time"
) )
// PullRequest represents a pull reqesut API object. // PullRequest represents a pull request API object.
type PullRequest struct { type PullRequest struct {
// Copied from issue.go
ID int64 `json:"id"` ID int64 `json:"id"`
Index int64 `json:"number"` Index int64 `json:"number"`
Poster *User `json:"user"` Poster *User `json:"user"`
@ -22,16 +24,109 @@ type PullRequest struct {
State StateType `json:"state"` State StateType `json:"state"`
Comments int `json:"comments"` Comments int `json:"comments"`
HeadBranch string `json:"head_branch"`
HeadRepo *Repository `json:"head_repo"`
BaseBranch string `json:"base_branch"`
BaseRepo *Repository `json:"base_repo"`
HTMLURL string `json:"html_url"` HTMLURL string `json:"html_url"`
DiffURL string `json:"diff_url"`
PatchURL string `json:"patch_url"`
Mergeable *bool `json:"mergeable"` Mergeable bool `json:"mergeable"`
HasMerged bool `json:"merged"` HasMerged bool `json:"merged"`
Merged *time.Time `json:"merged_at"` Merged *time.Time `json:"merged_at"`
MergedCommitID *string `json:"merge_commit_sha"` MergedCommitID *string `json:"merge_commit_sha"`
MergedBy *User `json:"merged_by"` MergedBy *User `json:"merged_by"`
Base *PRBranchInfo `json:"base"`
Head *PRBranchInfo `json:"head"`
MergeBase string `json:"merge_base"`
}
// PRBranchInfo base branch info when send a PR
type PRBranchInfo struct {
Name string `json:"label"`
Ref string `json:"ref"`
Sha string `json:"sha"`
RepoID int64 `json:"repo_id"`
Repository *Repository `json:"repo"`
}
// ListPullRequestsOptions options when list PRs
type ListPullRequestsOptions struct {
Page int `json:"page"`
State string `json:"state"`
}
// ListRepoPullRequests list PRs of one repository
func (c *Client) ListRepoPullRequests(owner, repo string, opt ListPullRequestsOptions) ([]*PullRequest, error) {
body, err := json.Marshal(&opt)
if err != nil {
return nil, err
}
prs := make([]*PullRequest, 0, 10)
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) {
pr := new(PullRequest)
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 {
Head string `json:"head" binding:"Required"`
Base string `json:"base" binding:"Required"`
Title string `json:"title" binding:"Required"`
Body string `json:"body"`
Assignee string `json:"assignee"`
Milestone int64 `json:"milestone"`
Labels []int64 `json:"labels"`
}
// CreatePullRequest create pull request with options
func (c *Client) CreatePullRequest(owner, repo string, opt CreatePullRequestOption) (*PullRequest, error) {
body, err := json.Marshal(&opt)
if err != nil {
return nil, err
}
pr := new(PullRequest)
return pr, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/pulls", owner, repo),
jsonHeader, bytes.NewReader(body), pr)
}
// EditPullRequestOption options when modify pull request
type EditPullRequestOption struct {
Title string `json:"title"`
Body string `json:"body"`
Assignee string `json:"assignee"`
Milestone int64 `json:"milestone"`
Labels []int64 `json:"labels"`
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) {
body, err := json.Marshal(&opt)
if err != nil {
return nil, err
}
pr := new(PullRequest)
return pr, c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index),
jsonHeader, bytes.NewReader(body), pr)
}
// MergePullRequest merge a PR to repository by PR id
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)
return err
}
// IsPullRequestMerged test if one PR is merged to one repository
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)
if err != nil {
return false, err
}
return statusCode == 204, nil
} }

View File

@ -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"`

View File

@ -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)

View File

@ -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 {

View File

@ -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,18 +113,22 @@ var (
// \______ /|__| \___ >____ /__| \___ > // \______ /|__| \___ >____ /__| \___ >
// \/ \/ \/ \/ // \/ \/ \/ \/
// CreatePayload FIXME
type CreatePayload struct { type CreatePayload struct {
Secret string `json:"secret"` Secret string `json:"secret"`
Sha string `json:"sha"`
Ref string `json:"ref"` Ref string `json:"ref"`
RefType string `json:"ref_type"` RefType string `json:"ref_type"`
Repo *Repository `json:"repository"` Repo *Repository `json:"repository"`
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 +173,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 +211,36 @@ func (p *PushPayload) Branch() string {
// |___/____ >____ >____/ \___ > // |___/____ >____ >____/ \___ >
// \/ \/ \/ // \/ \/ \/
// HookIssueAction FIXME
type HookIssueAction string type HookIssueAction string
const ( const (
// HookIssueOpened opened
HookIssueOpened HookIssueAction = "opened" HookIssueOpened HookIssueAction = "opened"
// HookIssueClosed closed
HookIssueClosed HookIssueAction = "closed" HookIssueClosed HookIssueAction = "closed"
HookIssueReopened HookIssueAction = "reopened" // HookIssueReOpened reopened
HookIssueReOpened HookIssueAction = "reopened"
// HookIssueEdited edited
HookIssueEdited HookIssueAction = "edited" HookIssueEdited HookIssueAction = "edited"
// HookIssueAssigned assigned
HookIssueAssigned HookIssueAction = "assigned" HookIssueAssigned HookIssueAction = "assigned"
// HookIssueUnassigned unassigned
HookIssueUnassigned HookIssueAction = "unassigned" HookIssueUnassigned HookIssueAction = "unassigned"
// HookIssueLabelUpdated label_updated
HookIssueLabelUpdated HookIssueAction = "label_updated" HookIssueLabelUpdated HookIssueAction = "label_updated"
// HookIssueLabelCleared label_cleared
HookIssueLabelCleared HookIssueAction = "label_cleared" HookIssueLabelCleared HookIssueAction = "label_cleared"
// HookIssueSynchronized synchronized
HookIssueSynchronized HookIssueAction = "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 +264,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, "", " ")
} }

View File

@ -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

View File

@ -11,12 +11,13 @@ import (
// User represents a API user. // User represents a API user.
type User struct { type User struct {
ID int64 `json:"id"` ID int64 `json:"id"`
UserName string `json:"username"` UserName string `json:"login"`
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)

View File

@ -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 {

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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
} }

6
vendor/vendor.json vendored
View File

@ -9,10 +9,10 @@
"revisionTime": "2016-11-13T14:20:52Z" "revisionTime": "2016-11-13T14:20:52Z"
}, },
{ {
"checksumSHA1": "/uhZZppDeb3Rbp3h8C0ALR3hdrA=", "checksumSHA1": "x5jr5+UwaMg861XyFWIoNzYmmMM=",
"path": "code.gitea.io/sdk/gitea", "path": "code.gitea.io/sdk/gitea",
"revision": "0a0a04ccf7a5e6b93d9a5507701635330cf4579c", "revision": "140df7f34c05d0d7e5b03c2b4a7d38690b3a5152",
"revisionTime": "2016-11-07T15:06:50Z" "revisionTime": "2016-11-29T07:37:12Z"
}, },
{ {
"checksumSHA1": "IyfS7Rbl6OgR83QR7TOfKdDCq+M=", "checksumSHA1": "IyfS7Rbl6OgR83QR7TOfKdDCq+M=",