Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Added ForkID property to the repo API #58

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func Version() string {
return "0.12.3"
return "0.12.12"
}

// Client represents a Gogs API client.
Expand Down
13 changes: 12 additions & 1 deletion issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,18 @@ type Issue struct {
}

type ListIssueOption struct {
Page int
Page int
State string
}

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

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

func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Issue, error) {
Expand Down
17 changes: 15 additions & 2 deletions issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
// Comment represents a comment in commit and issue page.
type Comment struct {
ID int64 `json:"id"`
HTMLURL string `json:"html_url"`
Poster *User `json:"user"`
Body string `json:"body"`
Created time.Time `json:"created_at"`
Expand All @@ -26,6 +27,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)
}

// 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.
type CreateIssueCommentOption struct {
Body string `json:"body" binding:"Required"`
Expand All @@ -38,7 +45,7 @@ func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateI
return nil, err
}
comment := new(Comment)
return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/:%s/:%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment)
return comment, c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment)
}

// EditIssueCommentOption is option when editing an issue comment.
Expand All @@ -53,5 +60,11 @@ func (c *Client) EditIssueComment(owner, repo string, index, commentID int64, op
return nil, err
}
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
}
1 change: 1 addition & 0 deletions issue_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Label struct {
ID int64 `json:"id"`
Name string `json:"name"`
Color string `json:"color"`
URL string `json:"url"`
}

func (c *Client) ListRepoLabels(owner, repo string) ([]*Label, error) {
Expand Down
22 changes: 22 additions & 0 deletions release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2017 The Gogs 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 gogs

import (
"time"
)

// Release represents a release API object.
type Release struct {
ID int64 `json:"id"`
TagName string `json:"tag_name"`
TargetCommitish string `json:"target_commitish"`
Name string `json:"name"`
Body string `json:"body"`
Draft bool `json:"draft"`
Prerelease bool `json:"prerelease"`
Author *User `json:"author"`
Created time.Time `json:"created_at"`
}
4 changes: 4 additions & 0 deletions repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ type Repository struct {
Description string `json:"description"`
Private bool `json:"private"`
Fork bool `json:"fork"`
ForkID int64 `json:"parent_id"`
Empty bool `json:"empty"`
Size int `json:"size"`
Mirror bool `json:"mirror"`
HTMLURL string `json:"html_url"`
SSHURL string `json:"ssh_url"`
CloneURL string `json:"clone_url"`
Expand Down
20 changes: 20 additions & 0 deletions repo_collaborator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ import (
"fmt"
)

type Collaborator struct {
*User
Permissions Permission `json:"permissions"`
}

type AddCollaboratorOption struct {
Permission *string `json:"permission"`
}

func (c *Client) ListCollaborator(user, repo string) ([]*Collaborator, error) {
collabs := make([]*Collaborator, 0, 10)
return collabs, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/collaborators", user, repo), nil, nil, &collabs)
}

func (c *Client) AddCollaborator(user, repo, collaborator string, opt AddCollaboratorOption) error {
body, err := json.Marshal(&opt)
if err != nil {
Expand All @@ -22,3 +32,13 @@ func (c *Client) AddCollaborator(user, repo, collaborator string, opt AddCollabo
_, err = c.getResponse("PUT", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, bytes.NewReader(body))
return err
}

func (c *Client) DeleteCollaborator(user, repo, collaborator string) error {
_, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, nil)
return err
}

func (c *Client) IsCollaborator(user, repo, collaborator string) error {
_, err := c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator), nil, nil)
return err
}
141 changes: 120 additions & 21 deletions repo_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func (c *Client) DeleteRepoHook(user, repo string, id int64) error {
}

type Payloader interface {
SetSecret(string)
JSONPayload() ([]byte, error)
}

Expand All @@ -87,12 +86,21 @@ type PayloadCommit struct {
URL string `json:"url"`
Author *PayloadUser `json:"author"`
Committer *PayloadUser `json:"committer"`
Timestamp time.Time `json:"timestamp"`

Added []string `json:"added"`
Removed []string `json:"removed"`
Modified []string `json:"modified"`

Timestamp time.Time `json:"timestamp"`
}

var (
_ Payloader = &CreatePayload{}
_ Payloader = &DeletePayload{}
_ Payloader = &ForkPayload{}
_ Payloader = &PushPayload{}
_ Payloader = &IssuesPayload{}
_ Payloader = &IssueCommentPayload{}
_ Payloader = &PullRequestPayload{}
)

Expand All @@ -104,15 +112,11 @@ var (
// \/ \/ \/ \/

type CreatePayload struct {
Secret string `json:"secret"`
Ref string `json:"ref"`
RefType string `json:"ref_type"`
Repo *Repository `json:"repository"`
Sender *User `json:"sender"`
}

func (p *CreatePayload) SetSecret(secret string) {
p.Secret = secret
Ref string `json:"ref"`
RefType string `json:"ref_type"`
DefaultBranch string `json:"default_branch"`
Repo *Repository `json:"repository"`
Sender *User `json:"sender"`
}

func (p *CreatePayload) JSONPayload() ([]byte, error) {
Expand All @@ -139,6 +143,48 @@ func ParseCreateHook(raw []byte) (*CreatePayload, error) {
return hook, nil
}

// ________ .__ __
// \______ \ ____ | | _____/ |_ ____
// | | \_/ __ \| | _/ __ \ __\/ __ \
// | ` \ ___/| |_\ ___/| | \ ___/
// /_______ /\___ >____/\___ >__| \___ >
// \/ \/ \/ \/

type PusherType string

const (
PUSHER_TYPE_USER PusherType = "user"
)

type DeletePayload struct {
Ref string `json:"ref"`
RefType string `json:"ref_type"`
PusherType PusherType `json:"pusher_type"`
Repo *Repository `json:"repository"`
Sender *User `json:"sender"`
}

func (p *DeletePayload) JSONPayload() ([]byte, error) {
return json.MarshalIndent(p, "", " ")
}

// ___________ __
// \_ _____/__________| | __
// | __)/ _ \_ __ \ |/ /
// | \( <_> ) | \/ <
// \___ / \____/|__| |__|_ \
// \/ \/

type ForkPayload struct {
Forkee *Repository `json:"forkee"`
Repo *Repository `json:"repository"`
Sender *User `json:"sender"`
}

func (p *ForkPayload) JSONPayload() ([]byte, error) {
return json.MarshalIndent(p, "", " ")
}

// __________ .__
// \______ \__ __ _____| |__
// | ___/ | \/ ___/ | \
Expand All @@ -148,7 +194,6 @@ func ParseCreateHook(raw []byte) (*CreatePayload, error) {

// PushPayload represents a payload information of push event.
type PushPayload struct {
Secret string `json:"secret"`
Ref string `json:"ref"`
Before string `json:"before"`
After string `json:"after"`
Expand All @@ -159,10 +204,6 @@ type PushPayload struct {
Sender *User `json:"sender"`
}

func (p *PushPayload) SetSecret(secret string) {
p.Secret = secret
}

func (p *PushPayload) JSONPayload() ([]byte, error) {
return json.MarshalIndent(p, "", " ")
}
Expand Down Expand Up @@ -206,6 +247,8 @@ const (
HOOK_ISSUE_UNASSIGNED HookIssueAction = "unassigned"
HOOK_ISSUE_LABEL_UPDATED HookIssueAction = "label_updated"
HOOK_ISSUE_LABEL_CLEARED HookIssueAction = "label_cleared"
HOOK_ISSUE_MILESTONED HookIssueAction = "milestoned"
HOOK_ISSUE_DEMILESTONED HookIssueAction = "demilestoned"
HOOK_ISSUE_SYNCHRONIZED HookIssueAction = "synchronized"
)

Expand All @@ -218,6 +261,42 @@ type ChangesPayload struct {
Body *ChangesFromPayload `json:"body,omitempty"`
}

// IssuesPayload represents a payload information of issues event.
type IssuesPayload struct {
Action HookIssueAction `json:"action"`
Index int64 `json:"number"`
Issue *Issue `json:"issue"`
Changes *ChangesPayload `json:"changes,omitempty"`
Repository *Repository `json:"repository"`
Sender *User `json:"sender"`
}

func (p *IssuesPayload) JSONPayload() ([]byte, error) {
return json.MarshalIndent(p, "", " ")
}

type HookIssueCommentAction string

const (
HOOK_ISSUE_COMMENT_CREATED HookIssueCommentAction = "created"
HOOK_ISSUE_COMMENT_EDITED HookIssueCommentAction = "edited"
HOOK_ISSUE_COMMENT_DELETED HookIssueCommentAction = "deleted"
)

// IssueCommentPayload represents a payload information of issue comment event.
type IssueCommentPayload struct {
Action HookIssueCommentAction `json:"action"`
Issue *Issue `json:"issue"`
Comment *Comment `json:"comment"`
Changes *ChangesPayload `json:"changes,omitempty"`
Repository *Repository `json:"repository"`
Sender *User `json:"sender"`
}

func (p *IssueCommentPayload) JSONPayload() ([]byte, error) {
return json.MarshalIndent(p, "", " ")
}

// __________ .__ .__ __________ __
// \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
// | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
Expand All @@ -227,19 +306,39 @@ type ChangesPayload struct {

// PullRequestPayload represents a payload information of pull request event.
type PullRequestPayload struct {
Secret string `json:"secret"`
Action HookIssueAction `json:"action"`
Index int64 `json:"number"`
Changes *ChangesPayload `json:"changes,omitempty"`
PullRequest *PullRequest `json:"pull_request"`
Changes *ChangesPayload `json:"changes,omitempty"`
Repository *Repository `json:"repository"`
Sender *User `json:"sender"`
}

func (p *PullRequestPayload) SetSecret(secret string) {
p.Secret = secret
func (p *PullRequestPayload) JSONPayload() ([]byte, error) {
return json.MarshalIndent(p, "", " ")
}

func (p *PullRequestPayload) JSONPayload() ([]byte, error) {
// __________ .__
// \______ \ ____ | | ____ _____ ______ ____
// | _// __ \| | _/ __ \\__ \ / ___// __ \
// | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
// |____|_ /\___ >____/\___ >____ /____ >\___ >
// \/ \/ \/ \/ \/ \/

type HookReleaseAction string

const (
HOOK_RELEASE_PUBLISHED HookReleaseAction = "published"
)

// ReleasePayload represents a payload information of release event.
type ReleasePayload struct {
Action HookReleaseAction `json:"action"`
Release *Release `json:"release"`
Repository *Repository `json:"repository"`
Sender *User `json:"sender"`
}

func (p *ReleasePayload) JSONPayload() ([]byte, error) {
return json.MarshalIndent(p, "", " ")
}
14 changes: 13 additions & 1 deletion user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,30 @@
package gogs

import (
"encoding/json"
"fmt"
)

// User represents a API user.
type User struct {
ID int64 `json:"id"`
UserName string `json:"username"`
UserName string `json:"login"`
FullName string `json:"full_name"`
Email string `json:"email"`
AvatarUrl string `json:"avatar_url"`
}

// MarshalJSON implements the json.Marshaler interface for User
func (u User) MarshalJSON() ([]byte, error) {
// Re-declaring User to avoid recursion
type shadow User
return json.Marshal(struct {
shadow
// LEGACY [Gogs 1.0]: remove field(s) for backward compatibility
CompatUserName string `json:"username"`
}{shadow(u), u.UserName})
}

func (c *Client) GetUserInfo(user string) (*User, error) {
u := new(User)
err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)
Expand Down