diff --git a/gitea/admin_org.go b/gitea/admin_org.go index 520fa12..4071b6f 100644 --- a/gitea/admin_org.go +++ b/gitea/admin_org.go @@ -10,6 +10,7 @@ import ( "fmt" ) +// AdminCreateOrg create an organization func (c *Client) AdminCreateOrg(user string, opt CreateOrgOption) (*Organization, error) { body, err := json.Marshal(&opt) if err != nil { diff --git a/gitea/admin_repo.go b/gitea/admin_repo.go index 06daa94..cf565ff 100644 --- a/gitea/admin_repo.go +++ b/gitea/admin_repo.go @@ -10,6 +10,7 @@ import ( "fmt" ) +// AdminCreateRepo create a repo func (c *Client) AdminCreateRepo(user string, opt CreateRepoOption) (*Repository, error) { body, err := json.Marshal(&opt) if err != nil { diff --git a/gitea/admin_user.go b/gitea/admin_user.go index 186008b..6ccad7e 100644 --- a/gitea/admin_user.go +++ b/gitea/admin_user.go @@ -10,6 +10,7 @@ import ( "fmt" ) +// CreateUserOption create user options type CreateUserOption struct { SourceID int64 `json:"source_id"` LoginName string `json:"login_name"` @@ -20,6 +21,7 @@ type CreateUserOption struct { SendNotify bool `json:"send_notify"` } +// AdminCreateUser create a user func (c *Client) AdminCreateUser(opt CreateUserOption) (*User, error) { body, err := json.Marshal(&opt) 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) } +// EditUserOption edit user options type EditUserOption struct { SourceID int64 `json:"source_id"` LoginName string `json:"login_name"` @@ -44,6 +47,7 @@ type EditUserOption struct { MaxRepoCreation *int `json:"max_repo_creation"` } +// AdminEditUser modify user informations func (c *Client) AdminEditUser(user string, opt EditUserOption) error { body, err := json.Marshal(&opt) if err != nil { @@ -53,11 +57,13 @@ func (c *Client) AdminEditUser(user string, opt EditUserOption) error { return err } +// AdminDeleteUser delete one user according name func (c *Client) AdminDeleteUser(user string) error { _, err := c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s", user), nil, nil) return err } +// AdminCreateUserPublicKey create one user with options func (c *Client) AdminCreateUserPublicKey(user string, opt CreateKeyOption) (*PublicKey, error) { body, err := json.Marshal(&opt) if err != nil { diff --git a/gitea/gitea.go b/gitea/gitea.go index 4963452..20cb44f 100644 --- a/gitea/gitea.go +++ b/gitea/gitea.go @@ -13,6 +13,7 @@ import ( "strings" ) +// Version return the library version func Version() string { return "0.12.3" } diff --git a/gitea/issue.go b/gitea/issue.go index 4392e00..dfa4fb8 100644 --- a/gitea/issue.go +++ b/gitea/issue.go @@ -11,49 +11,58 @@ import ( "time" ) -type StateType string +// PRStateType issue state type +type PRStateType string const ( - STATE_OPEN StateType = "open" - STATE_CLOSED StateType = "closed" + // PRStateOpen pr is opend + PRStateOpen PRStateType = "open" + // PRStateClosed pr is closed + PRStateClosed PRStateType = "closed" ) +// PullRequestMeta PR info if an issue is a PR type PullRequestMeta struct { HasMerged bool `json:"merged"` Merged *time.Time `json:"merged_at"` } +// Issue an issue to a repository type Issue struct { - ID int64 `json:"id"` - Index int64 `json:"number"` - Poster *User `json:"user"` - Title string `json:"title"` - Body string `json:"body"` - Labels []*Label `json:"labels"` - Milestone *Milestone `json:"milestone"` - Assignee *User `json:"assignee"` - State StateType `json:"state"` - Comments int `json:"comments"` - Created time.Time `json:"created_at"` - Updated time.Time `json:"updated_at"` + ID int64 `json:"id"` + Index int64 `json:"number"` + Poster *User `json:"user"` + Title string `json:"title"` + Body string `json:"body"` + Labels []*Label `json:"labels"` + Milestone *Milestone `json:"milestone"` + Assignee *User `json:"assignee"` + State PRStateType `json:"state"` + Comments int `json:"comments"` + Created time.Time `json:"created_at"` + Updated time.Time `json:"updated_at"` PullRequest *PullRequestMeta `json:"pull_request"` } +// ListIssueOption list issue options type ListIssueOption struct { Page int } +// ListRepoIssues list one repos' issues func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Issue, error) { 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) } +// GetIssue get some one issue of repository func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, error) { issue := new(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 { Title string `json:"title" binding:"Required"` Body string `json:"body"` @@ -63,6 +72,7 @@ type CreateIssueOption struct { Closed bool `json:"closed"` } +// CreateIssue create an issue with options func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue, error) { body, err := json.Marshal(&opt) if err != nil { @@ -73,6 +83,7 @@ func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue, jsonHeader, bytes.NewReader(body), issue) } +// EditIssueOption edit issue options type EditIssueOption struct { Title string `json:"title"` Body *string `json:"body"` @@ -81,6 +92,7 @@ type EditIssueOption struct { State *string `json:"state"` } +// EditIssue modify an issue of repository func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption) (*Issue, error) { body, err := json.Marshal(&opt) if err != nil { diff --git a/gitea/issue_label.go b/gitea/issue_label.go index 681e504..ec353ed 100644 --- a/gitea/issue_label.go +++ b/gitea/issue_label.go @@ -10,27 +10,33 @@ import ( "fmt" ) +// Label a label to an issue or a pr type Label struct { ID int64 `json:"id"` Name string `json:"name"` Color string `json:"color"` } +// ListRepoLabels list lables of one reppsitory func (c *Client) ListRepoLabels(owner, repo string) ([]*Label, error) { labels := make([]*Label, 0, 10) 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) { label := new(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 { Name string `json:"name" binding:"Required"` 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) { body, err := json.Marshal(&opt) if err != nil { @@ -41,11 +47,13 @@ func (c *Client) CreateLabel(owner, repo string, opt CreateLabelOption) (*Label, jsonHeader, bytes.NewReader(body), label) } +// EditLabelOption edit label options type EditLabelOption struct { Name *string `json:"name"` Color *string `json:"color"` } +// EditLabel modify one label with options func (c *Client) EditLabel(owner, repo string, id int64, opt EditLabelOption) (*Label, error) { body, err := json.Marshal(&opt) 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) } +// 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 { _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil) return err } +// IssueLabelsOption list one issue's labels options type IssueLabelsOption struct { Labels []int64 `json:"labels"` } +// GetIssueLabels get labels of one issue via issue id func (c *Client) GetIssueLabels(owner, repo string, index int64) ([]*Label, error) { labels := make([]*Label, 0, 5) 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) { body, err := json.Marshal(&opt) if err != nil { 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) } +// ReplaceIssueLabels replace old labels of issue with new labels func (c *Client) ReplaceIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, error) { body, err := json.Marshal(&opt) if err != nil { 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) } +// 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 { _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels/%d", owner, repo, index, label), nil, nil) return err } +// ClearIssueLabels delete all the labels of one issue. 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) return err diff --git a/gitea/issue_milestone.go b/gitea/issue_milestone.go index 58f1789..e35325e 100644 --- a/gitea/issue_milestone.go +++ b/gitea/issue_milestone.go @@ -11,6 +11,7 @@ import ( "time" ) +// Milestone milestone is a collection of issues on one repository type Milestone struct { ID int64 `json:"id"` Title string `json:"title"` @@ -22,22 +23,26 @@ type Milestone struct { Deadline *time.Time `json:"due_on"` } +// ListRepoMilestones list all the milestones of one repository func (c *Client) ListRepoMilestones(owner, repo string) ([]*Milestone, error) { milestones := make([]*Milestone, 0, 10) return milestones, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), nil, nil, &milestones) } +// GetMilestone get one milestone by repo name and milestone id func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, error) { milestone := new(Milestone) return milestone, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil, milestone) } +// CreateMilestoneOption options when creating milestone type CreateMilestoneOption struct { Title string `json:"title"` Description string `json:"description"` Deadline *time.Time `json:"due_on"` } +// CreateMilestone create one milestone with options func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption) (*Milestone, error) { body, err := json.Marshal(&opt) 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) } +// EditMilestoneOption options when modify milestone type EditMilestoneOption struct { Title string `json:"title"` Description *string `json:"description"` @@ -54,6 +60,7 @@ type EditMilestoneOption struct { Deadline *time.Time `json:"due_on"` } +// EditMilestone modify milestone with options func (c *Client) EditMilestone(owner, repo string, id int64, opt EditMilestoneOption) (*Milestone, error) { body, err := json.Marshal(&opt) 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) } +// DeleteMilestone delete one milestone by milestone id func (c *Client) DeleteMilestone(owner, repo string, id int64) error { _, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil) return err diff --git a/gitea/miscellaneous.go b/gitea/miscellaneous.go index d97940e..ae12d6e 100644 --- a/gitea/miscellaneous.go +++ b/gitea/miscellaneous.go @@ -4,6 +4,7 @@ package gitea +// MarkdownOption markdown options type MarkdownOption struct { Text string Mode string diff --git a/gitea/org.go b/gitea/org.go index 70d872c..103674a 100644 --- a/gitea/org.go +++ b/gitea/org.go @@ -10,31 +10,36 @@ import ( "fmt" ) +// Organization a group of some repositories, users and teams type Organization struct { ID int64 `json:"id"` UserName string `json:"username"` FullName string `json:"full_name"` - AvatarUrl string `json:"avatar_url"` + AvatarURL string `json:"avatar_url"` Description string `json:"description"` Website string `json:"website"` Location string `json:"location"` } +// ListMyOrgs list all of current user's organizations func (c *Client) ListMyOrgs() ([]*Organization, error) { orgs := make([]*Organization, 0, 5) 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) { orgs := make([]*Organization, 0, 5) 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) { org := new(Organization) return org, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s", orgname), nil, nil, org) } +// CreateOrgOption create one organization options type CreateOrgOption struct { UserName string `json:"username" binding:"Required"` FullName string `json:"full_name"` @@ -43,6 +48,7 @@ type CreateOrgOption struct { Location string `json:"location"` } +// EditOrgOption edit one organization options type EditOrgOption struct { FullName string `json:"full_name"` Description string `json:"description"` @@ -50,6 +56,7 @@ type EditOrgOption struct { Location string `json:"location"` } +// EditOrg modify one organization via options func (c *Client) EditOrg(orgname string, opt EditOrgOption) error { body, err := json.Marshal(&opt) if err != nil { diff --git a/gitea/org_member.go b/gitea/org_member.go index 46e8398..9bb95af 100644 --- a/gitea/org_member.go +++ b/gitea/org_member.go @@ -10,10 +10,12 @@ import ( "fmt" ) +// AddOrgMembershipOption add user to organization options type AddOrgMembershipOption struct { 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 { body, err := json.Marshal(&opt) if err != nil { diff --git a/gitea/org_team.go b/gitea/org_team.go index 38da20d..a94a43f 100644 --- a/gitea/org_team.go +++ b/gitea/org_team.go @@ -4,6 +4,7 @@ package gitea +// Team is a sub virtual organization of one Organization type Team struct { ID int64 `json:"id"` Name string `json:"name"` @@ -11,6 +12,7 @@ type Team struct { Permission string `json:"permission"` } +// CreateTeamOption options when create team type CreateTeamOption struct { Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(30)"` Description string `json:"description" binding:"MaxSize(255)"` diff --git a/gitea/pull.go b/gitea/pull.go index b58df95..f55ecc0 100644 --- a/gitea/pull.go +++ b/gitea/pull.go @@ -39,6 +39,7 @@ type PullRequest struct { MergeBase string `json:"merge_base"` } +// PRBranchInfo base branch info when send a PR type PRBranchInfo struct { Name string `json:"label"` Ref string `json:"ref"` @@ -47,11 +48,13 @@ type PRBranchInfo struct { 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 { @@ -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) } +// 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"` @@ -76,6 +81,7 @@ type CreatePullRequestOption struct { 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 { @@ -86,6 +92,7 @@ func (c *Client) CreatePullRequest(owner, repo string, opt CreatePullRequestOpti jsonHeader, bytes.NewReader(body), pr) } +// EditPullRequestOption options when modify pull request type EditPullRequestOption struct { Title string `json:"title"` Body string `json:"body"` @@ -95,6 +102,7 @@ type EditPullRequestOption struct { 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 { @@ -105,11 +113,13 @@ func (c *Client) EditPullRequest(owner, repo string, index int64, opt EditPullRe 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) diff --git a/gitea/repo.go b/gitea/repo.go index 266c01c..75d6395 100644 --- a/gitea/repo.go +++ b/gitea/repo.go @@ -47,16 +47,19 @@ func (c *Client) ListMyRepos() ([]*Repository, error) { 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) { repos := make([]*Repository, 0, 10) 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) { repos := make([]*Repository, 0, 10) return repos, c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/repos", org), nil, nil, &repos) } +// CreateRepoOption options when creating repository type CreateRepoOption struct { Name string `json:"name" binding:"Required;AlphaDashDot;MaxSize(100)"` Description string `json:"description" binding:"MaxSize(255)"` @@ -99,6 +102,7 @@ func (c *Client) DeleteRepo(owner, repo string) error { return err } +// MigrateRepoOption options when migrate repository from an external place type MigrateRepoOption struct { CloneAddr string `json:"clone_addr" binding:"Required"` AuthUsername string `json:"auth_username"` diff --git a/gitea/repo_branch.go b/gitea/repo_branch.go index c57df07..fadc9e3 100644 --- a/gitea/repo_branch.go +++ b/gitea/repo_branch.go @@ -14,11 +14,13 @@ type Branch struct { Commit *PayloadCommit `json:"commit"` } +// ListRepoBranches list all the branches of one repository func (c *Client) ListRepoBranches(user, repo string) ([]*Branch, error) { branches := make([]*Branch, 0, 10) 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) { b := new(Branch) return b, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/branches/%s", user, repo, branch), nil, nil, &b) diff --git a/gitea/repo_collaborator.go b/gitea/repo_collaborator.go index 1937de4..82f6f8f 100644 --- a/gitea/repo_collaborator.go +++ b/gitea/repo_collaborator.go @@ -10,10 +10,12 @@ import ( "fmt" ) +// AddCollaboratorOption options when add some user as a collaborator of a repository type AddCollaboratorOption struct { 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 { body, err := json.Marshal(&opt) if err != nil { diff --git a/gitea/repo_hook.go b/gitea/repo_hook.go index 7f71bea..80df75c 100644 --- a/gitea/repo_hook.go +++ b/gitea/repo_hook.go @@ -14,9 +14,11 @@ import ( ) var ( + // ErrInvalidReceiveHook FIXME ErrInvalidReceiveHook = errors.New("Invalid JSON payload received over webhook") ) +// Hook a hook is a web hook when one repository changed type Hook struct { ID int64 `json:"id"` Type string `json:"type"` @@ -28,11 +30,13 @@ type Hook struct { Created time.Time `json:"created_at"` } +// ListRepoHooks list all the hooks of one repository func (c *Client) ListRepoHooks(user, repo string) ([]*Hook, error) { hooks := make([]*Hook, 0, 10) 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 string `json:"type" binding:"Required"` Config map[string]string `json:"config" binding:"Required"` @@ -40,6 +44,7 @@ type CreateHookOption struct { Active bool `json:"active"` } +// CreateRepoHook create one hook with options func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, error) { body, err := json.Marshal(&opt) 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) } +// EditHookOption options when modify one hook type EditHookOption struct { Config map[string]string `json:"config"` Events []string `json:"events"` 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 { body, err := json.Marshal(&opt) if err != nil { @@ -64,23 +71,26 @@ func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) e return err } +// DeleteRepoHook delete one hook with hook id 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) return err } +// Payloader payload is some part of one hook type Payloader interface { SetSecret(string) JSONPayload() ([]byte, error) } +// PayloadUser FIXME type PayloadUser struct { Name string `json:"name"` Email string `json:"email"` 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 { ID string `json:"id"` Message string `json:"message"` @@ -103,6 +113,7 @@ var ( // \______ /|__| \___ >____ /__| \___ > // \/ \/ \/ \/ +// CreatePayload FIXME type CreatePayload struct { Secret string `json:"secret"` Ref string `json:"ref"` @@ -111,10 +122,12 @@ type CreatePayload struct { Sender *User `json:"sender"` } +// SetSecret FIXME func (p *CreatePayload) SetSecret(secret string) { p.Secret = secret } +// JSONPayload return payload information func (p *CreatePayload) JSONPayload() ([]byte, error) { return json.MarshalIndent(p, "", " ") } @@ -159,10 +172,12 @@ type PushPayload struct { Sender *User `json:"sender"` } +// SetSecret FIXME func (p *PushPayload) SetSecret(secret string) { p.Secret = secret } +// JSONPayload FIXME func (p *PushPayload) JSONPayload() ([]byte, error) { return json.MarshalIndent(p, "", " ") } @@ -195,24 +210,36 @@ func (p *PushPayload) Branch() string { // |___/____ >____ >____/ \___ > // \/ \/ \/ +// HookIssueAction FIXME type HookIssueAction string const ( - HOOK_ISSUE_OPENED HookIssueAction = "opened" - HOOK_ISSUE_CLOSED HookIssueAction = "closed" - HOOK_ISSUE_REOPENED HookIssueAction = "reopened" - HOOK_ISSUE_EDITED HookIssueAction = "edited" - HOOK_ISSUE_ASSIGNED HookIssueAction = "assigned" - HOOK_ISSUE_UNASSIGNED HookIssueAction = "unassigned" - HOOK_ISSUE_LABEL_UPDATED HookIssueAction = "label_updated" - HOOK_ISSUE_LABEL_CLEARED HookIssueAction = "label_cleared" - HOOK_ISSUE_SYNCHRONIZED HookIssueAction = "synchronized" + // HookIssueOpened opened + HookIssueOpened HookIssueAction = "opened" + // HookIssueClosed closed + HookIssueClosed HookIssueAction = "closed" + // HookIssueReOpened reopened + HookIssueReOpened HookIssueAction = "reopened" + // HookIssueEdited edited + HookIssueEdited HookIssueAction = "edited" + // 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 { From string `json:"from"` } +// ChangesPayload FIXME type ChangesPayload struct { Title *ChangesFromPayload `json:"title,omitempty"` Body *ChangesFromPayload `json:"body,omitempty"` @@ -236,10 +263,12 @@ type PullRequestPayload struct { Sender *User `json:"sender"` } +// SetSecret FIXME func (p *PullRequestPayload) SetSecret(secret string) { p.Secret = secret } +// JSONPayload FIXME func (p *PullRequestPayload) JSONPayload() ([]byte, error) { return json.MarshalIndent(p, "", " ") } diff --git a/gitea/repo_key.go b/gitea/repo_key.go index acae30a..a0dbf0a 100644 --- a/gitea/repo_key.go +++ b/gitea/repo_key.go @@ -11,6 +11,7 @@ import ( "time" ) +// DeployKey a deploy key type DeployKey struct { ID int64 `json:"id"` Key string `json:"key"` @@ -20,21 +21,25 @@ type DeployKey struct { ReadOnly bool `json:"read_only"` } +// ListDeployKeys list all the deploy keys of one repository func (c *Client) ListDeployKeys(user, repo string) ([]*DeployKey, error) { keys := make([]*DeployKey, 0, 10) 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) { key := new(DeployKey) 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 { Title string `json:"title" 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) { body, err := json.Marshal(&opt) 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) } +// DeleteDeployKey delete deploy key with key id 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) return err diff --git a/gitea/user.go b/gitea/user.go index 8b78bea..4e38a6b 100644 --- a/gitea/user.go +++ b/gitea/user.go @@ -14,9 +14,10 @@ type User struct { UserName string `json:"username"` FullName string `json:"full_name"` 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) { u := new(User) err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u) diff --git a/gitea/user_app.go b/gitea/user_app.go index 187053b..7fbb35d 100644 --- a/gitea/user_app.go +++ b/gitea/user_app.go @@ -12,6 +12,7 @@ import ( "net/http" ) +// BasicAuthEncode generate base64 of basic auth head func BasicAuthEncode(user, pass string) string { return base64.StdEncoding.EncodeToString([]byte(user + ":" + pass)) } @@ -22,16 +23,19 @@ type AccessToken struct { Sha1 string `json:"sha1"` } +// ListAccessTokens lista all the access tokens of user func (c *Client) ListAccessTokens(user, pass string) ([]*AccessToken, error) { tokens := make([]*AccessToken, 0, 10) return tokens, c.getParsedResponse("GET", fmt.Sprintf("/users/%s/tokens", user), http.Header{"Authorization": []string{"Basic " + BasicAuthEncode(user, pass)}}, nil, &tokens) } +// CreateAccessTokenOption options when create access token type CreateAccessTokenOption struct { Name string `json:"name" binding:"Required"` } +// CreateAccessToken create one access token with options func (c *Client) CreateAccessToken(user, pass string, opt CreateAccessTokenOption) (*AccessToken, error) { body, err := json.Marshal(&opt) if err != nil { diff --git a/gitea/user_email.go b/gitea/user_email.go index e9805ec..e167b5d 100644 --- a/gitea/user_email.go +++ b/gitea/user_email.go @@ -9,21 +9,25 @@ import ( "encoding/json" ) +// Email en email information of user type Email struct { Email string `json:"email"` Verified bool `json:"verified"` Primary bool `json:"primary"` } +// ListEmails all the email addresses of user func (c *Client) ListEmails() ([]*Email, error) { emails := make([]*Email, 0, 3) return emails, c.getParsedResponse("GET", "/user/emails", nil, nil, &emails) } +// CreateEmailOption options when create an email type CreateEmailOption struct { Emails []string `json:"emails"` } +// AddEmail add one email to current user with options func (c *Client) AddEmail(opt CreateEmailOption) ([]*Email, error) { body, err := json.Marshal(&opt) 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) } +// DeleteEmail delete one email of current users' func (c *Client) DeleteEmail(opt CreateEmailOption) error { body, err := json.Marshal(&opt) if err != nil { diff --git a/gitea/user_follow.go b/gitea/user_follow.go index cbb2c7b..a197a7f 100644 --- a/gitea/user_follow.go +++ b/gitea/user_follow.go @@ -6,41 +6,49 @@ package gitea import "fmt" +// ListMyFollowers list all the followers of current user func (c *Client) ListMyFollowers(page int) ([]*User, error) { users := make([]*User, 0, 10) 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) { users := make([]*User, 0, 10) 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) { users := make([]*User, 0, 10) 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) { users := make([]*User, 0, 10) 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 { _, err := c.getResponse("GET", fmt.Sprintf("/user/following/%s", target), nil, nil) return err == nil } +// IsUserFollowing if the user followed the target func (c *Client) IsUserFollowing(user, target string) bool { _, err := c.getResponse("GET", fmt.Sprintf("/users/%s/following/%s", user, target), nil, nil) return err == nil } +// Follow set current user follow the target func (c *Client) Follow(target string) error { _, err := c.getResponse("PUT", fmt.Sprintf("/user/following/%s", target), nil, nil) return err } +// Unfollow set current user unfollow the target func (c *Client) Unfollow(target string) error { _, err := c.getResponse("DELETE", fmt.Sprintf("/user/following/%s", target), nil, nil) return err diff --git a/gitea/user_key.go b/gitea/user_key.go index 8af5ed7..3135b33 100644 --- a/gitea/user_key.go +++ b/gitea/user_key.go @@ -11,6 +11,7 @@ import ( "time" ) +// PublicKey publickey is a user key to push code to repository type PublicKey struct { ID int64 `json:"id"` Key string `json:"key"` @@ -19,21 +20,25 @@ type PublicKey struct { Created time.Time `json:"created_at,omitempty"` } +// ListPublicKeys list all the public keys of the user func (c *Client) ListPublicKeys(user string) ([]*PublicKey, error) { keys := make([]*PublicKey, 0, 10) 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) { keys := make([]*PublicKey, 0, 10) 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) { key := new(PublicKey) 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) { body, err := json.Marshal(&opt) 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) } +// DeletePublicKey delete public key with key id func (c *Client) DeletePublicKey(keyID int64) error { _, err := c.getResponse("DELETE", fmt.Sprintf("/user/keys/%d", keyID), nil, nil) return err diff --git a/gitea/utils.go b/gitea/utils.go index 8d962ba..80892a1 100644 --- a/gitea/utils.go +++ b/gitea/utils.go @@ -10,14 +10,17 @@ import ( var jsonHeader = http.Header{"content-type": []string{"application/json"}} +// Bool return address of bool value func Bool(v bool) *bool { return &v } +// String return address of string value func String(v string) *string { return &v } +// Int64 return address of int64 value func Int64(v int64) *int64 { return &v }