api

package
v0.3.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package api provides GitCode API client

Index

Constants

View Source
const (
	// DefaultHost is the default GitCode host
	DefaultHost = "api.gitcode.com"
	// DefaultAPIVersion is the default API version
	DefaultAPIVersion = "v5"
)

Variables

View Source
var ErrInvalidReleaseID = fmtError("invalid release ID")

ErrInvalidReleaseID is returned when release ID is invalid

View Source
var ErrNoReleaseID = fmtError("release id was not returned by GitCode API")

ErrNoReleaseID is returned when the GitCode API omits release IDs.

Functions

func BuildURL

func BuildURL(base string, params map[string]string) string

BuildURL builds a URL with path parameters

func ClearIssueLabels

func ClearIssueLabels(client *Client, owner, repo string, number int) error

ClearIssueLabels removes all labels from an issue

func DefaultHTTPClient

func DefaultHTTPClient() *http.Client

DefaultHTTPClient returns the default HTTP client

func DeleteIssueComment

func DeleteIssueComment(client *Client, owner, repo string, commentID int64) error

DeleteIssueComment deletes a comment on an issue

func DeleteLabel

func DeleteLabel(client *Client, owner, repo, name string) error

DeleteLabel deletes a label

func DeleteMilestone

func DeleteMilestone(client *Client, owner, repo string, number int) error

DeleteMilestone deletes a milestone

func DeleteRelease

func DeleteRelease(client *Client, owner, repo string, id int64) error

DeleteRelease deletes a release by ID

func DeleteReleaseAsset

func DeleteReleaseAsset(client *Client, owner, repo string, assetID int64) error

DeleteReleaseAsset deletes a release asset

func DeleteReleaseByTag

func DeleteReleaseByTag(client *Client, owner, repo, tag string) error

DeleteReleaseByTag deletes a release by tag name

func DeleteRepo

func DeleteRepo(client *Client, owner, name string) error

DeleteRepo deletes a repository

func GetCommitDiff added in v0.3.0

func GetCommitDiff(client *Client, owner, repo, sha string) (string, error)

GetCommitDiff fetches the diff of a commit

func GetCommitPatch added in v0.3.0

func GetCommitPatch(client *Client, owner, repo, sha string) (string, error)

GetCommitPatch fetches the patch of a commit

func RemoveIssueLabel added in v0.2.4

func RemoveIssueLabel(client *Client, owner, repo string, number int, label string) error

RemoveIssueLabel removes a label from an issue by updating the issue

func RemoveLabelFromIssue

func RemoveLabelFromIssue(client *Client, owner, repo string, number int, label string) error

RemoveLabelFromIssue removes a label from an issue

func ResolvePRComment added in v0.2.5

func ResolvePRComment(client *Client, owner, repo string, number int, discussionID string, opts *ResolvePRCommentOptions) error

ResolvePRComment updates the resolution status of a PR comment

func ResolveUserIDs added in v0.3.7

func ResolveUserIDs(client *Client, usernames []string) ([]string, error)

ResolveUserIDs resolves usernames to GitCode user IDs.

func ReviewPR added in v0.2.5

func ReviewPR(client *Client, owner, repo string, number int, opts *ReviewPROptions) error

ReviewPR handles PR review (approve/force pass)

func TestPR added in v0.2.5

func TestPR(client *Client, owner, repo string, number int, opts *TestPROptions) error

TestPR handles PR test

func UploadReleaseAssetByTag

func UploadReleaseAssetByTag(client *Client, owner, repo, tag, filename string, content []byte, contentType string) error

UploadReleaseAssetByTag uploads a file to a release by tag name using two-step process

Types

type APIError

type APIError struct {
	StatusCode    int    `json:"-"`
	Message       string `json:"message"`
	ErrorMessage  string `json:"error_message"`
	ErrorName     string `json:"error"`
	ErrorCodeName string `json:"error_code_name"`
}

APIError represents an API error

func (*APIError) Error

func (e *APIError) Error() string

type AssetUploadURL

type AssetUploadURL struct {
	URL     string            `json:"url"`
	Headers map[string]string `json:"headers"`
}

AssetUploadURL represents the response from getting upload URL

func GetReleaseUploadURL

func GetReleaseUploadURL(client *Client, owner, repo, tag, filename string) (*AssetUploadURL, error)

GetReleaseUploadURL fetches the upload URL for a release asset

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a GitCode API client

func ClientFromToken

func ClientFromToken(token string) *Client

ClientFromToken creates a client with the given token

func ClientFromTokenAndHost

func ClientFromTokenAndHost(token, host string) *Client

ClientFromTokenAndHost creates a client with the given token and host

func NewClient

func NewClient(httpClient *http.Client, host, token string) *Client

NewClient creates a new API client

func NewClientFromHTTP

func NewClientFromHTTP(httpClient *http.Client) *Client

NewClientFromHTTP creates a client from an existing HTTP client

func (*Client) Delete

func (c *Client) Delete(path string) error

Delete performs a DELETE request

func (*Client) Get

func (c *Client) Get(path string, response interface{}) error

Get performs a GET request

func (*Client) GetText added in v0.3.7

func (c *Client) GetText(path string) (string, error)

GetText performs a GET request and returns the raw response body as text.

func (*Client) Host

func (c *Client) Host() string

Host returns the current host

func (*Client) Patch

func (c *Client) Patch(path string, body interface{}, response interface{}) error

Patch performs a PATCH request

func (*Client) PatchForm added in v0.2.4

func (c *Client) PatchForm(path string, formValues url.Values, response interface{}) error

PatchForm performs a PATCH request with form data

func (*Client) Post

func (c *Client) Post(path string, body interface{}, response interface{}) error

Post performs a POST request

func (*Client) PostForm added in v0.3.7

func (c *Client) PostForm(path string, formValues url.Values, response interface{}) error

PostForm performs a POST request with form data.

func (*Client) Put

func (c *Client) Put(path string, body interface{}, response interface{}) error

Put performs a PUT request

func (*Client) REST

func (c *Client) REST(method, path string, body interface{}, response interface{}) error

REST performs a REST API call

func (*Client) SetHost

func (c *Client) SetHost(host string)

SetHost sets the API host

func (*Client) SetToken

func (c *Client) SetToken(token, source string)

SetToken sets the authentication token

func (*Client) Token

func (c *Client) Token() string

Token returns the current token

func (*Client) UploadAsset

func (c *Client) UploadAsset(path, filename string, content []byte, contentType string) (*ReleaseAsset, error)

UploadAsset uploads a file to a release

func (*Client) UploadToURL

func (c *Client) UploadToURL(uploadURL, filename string, content []byte, contentType string, headers map[string]string) error

UploadToURL uploads a file to an external URL with custom headers

type Commit

type Commit struct {
	SHA       string `json:"sha"`
	Message   string `json:"message"`
	Author    *User  `json:"author"`
	Committer *User  `json:"committer"`
}

Commit represents a Git commit

func ListPRCommits

func ListPRCommits(client *Client, owner, repo string, number int) ([]Commit, error)

ListPRCommits lists commits in a PR

type CommitAuthor added in v0.3.0

type CommitAuthor struct {
	Name  string       `json:"name"`
	Email string       `json:"email"`
	Date  FlexibleTime `json:"date"`
}

CommitAuthor represents commit author info

type CommitComment added in v0.3.0

type CommitComment struct {
	ID        interface{} `json:"id"`
	Body      string      `json:"body"`
	CreatedAt string      `json:"created_at"`
	UpdatedAt string      `json:"updated_at"`
	User      *User       `json:"user"`
	Target    *Commit     `json:"target"`
}

CommitComment represents a commit comment

func CreateCommitComment added in v0.3.0

func CreateCommitComment(client *Client, owner, repo, sha, body string) (*CommitComment, error)

CreateCommitComment creates a comment on a commit

func GetCommitComment added in v0.3.0

func GetCommitComment(client *Client, owner, repo, id string) (*CommitComment, error)

GetCommitComment fetches a single commit comment

func ListCommentsForCommit added in v0.3.0

func ListCommentsForCommit(client *Client, owner, repo, sha string, opts *ListOptions) ([]CommitComment, error)

ListCommentsForCommit lists comments for a specific commit

func ListCommitComments added in v0.3.0

func ListCommitComments(client *Client, owner, repo string, opts *ListOptions) ([]CommitComment, error)

ListCommitComments lists all commit comments in a repository

func UpdateCommitComment added in v0.3.0

func UpdateCommitComment(client *Client, owner, repo, id string, body string) (*CommitComment, error)

UpdateCommitComment updates a commit comment

type CommitCommentsBySHAOptions added in v0.3.0

type CommitCommentsBySHAOptions struct {
	Page    int
	PerPage int
}

CommitCommentsBySHAOptions represents options for listing comments by SHA

type CommitFile added in v0.3.0

type CommitFile struct {
	Filename  string `json:"filename"`
	Status    string `json:"status"`
	Additions int    `json:"additions"`
	Deletions int    `json:"deletions"`
	Changes   int    `json:"changes"`
}

CommitFile represents a file in a commit

type CommitInfo added in v0.3.0

type CommitInfo struct {
	Author    *CommitAuthor `json:"author"`
	Committer *CommitAuthor `json:"committer"`
	Message   string        `json:"message"`
}

CommitInfo represents the commit details

type CommitStatItem added in v0.3.0

type CommitStatItem struct {
	Author  string `json:"author"`
	Commits int    `json:"commits"`
}

CommitStatItem represents a single commit stat item

type CommitStatistics added in v0.3.0

type CommitStatistics struct {
	Commits    []CommitStatItem `json:"commits"`
	Statistics []StatItem       `json:"statistics"`
	Total      int              `json:"total"`
}

CommitStatistics represents code contribution statistics

func GetCommitStatistics added in v0.3.0

func GetCommitStatistics(client *Client, owner, repo string, opts *CommitStatsOptions) (*CommitStatistics, error)

GetCommitStatistics gets code contribution statistics for a repository

type CommitStats added in v0.3.0

type CommitStats struct {
	Additions int `json:"additions"`
	Deletions int `json:"deletions"`
	Total     int `json:"total"`
}

CommitStats represents commit statistics

type CommitStatsOptions added in v0.3.0

type CommitStatsOptions struct {
	BranchName string `url:"branch_name,omitempty"`
	Author     string `url:"author,omitempty"`
	OnlySelf   bool   `url:"only_self,omitempty"`
	Since      string `url:"since,omitempty"`
	Until      string `url:"until,omitempty"`
}

CommitStatsOptions represents options for getting commit statistics

type CreateCommentOptions

type CreateCommentOptions struct {
	Body string `json:"body"`
}

CreateCommentOptions represents options for creating a comment

type CreateIssueOptions

type CreateIssueOptions struct {
	Title       string   `json:"title"`
	Body        string   `json:"body,omitempty"`
	AssigneeIDs []string `json:"assignee_ids,omitempty"`
	Labels      []string `json:"labels,omitempty"`
	Milestone   int      `json:"milestone,omitempty"`
}

CreateIssueOptions represents options for creating an issue

type CreateLabelOptions

type CreateLabelOptions struct {
	Name        string `json:"name"`
	Color       string `json:"color,omitempty"`
	Description string `json:"description,omitempty"`
}

CreateLabelOptions represents options for creating a label

type CreateMilestoneOptions

type CreateMilestoneOptions struct {
	Title       string `json:"title"`
	Description string `json:"description,omitempty"`
	State       string `json:"state,omitempty"`
	DueOn       string `json:"due_on,omitempty"`
}

CreateMilestoneOptions represents options for creating a milestone

type CreatePRCommentOptions

type CreatePRCommentOptions struct {
	Body     string `json:"body"`
	Path     string `json:"path,omitempty"`
	Position int    `json:"position,omitempty"`
}

CreatePRCommentOptions represents options for creating a PR comment

type CreatePROptions

type CreatePROptions struct {
	Title    string `json:"title"`
	Body     string `json:"body,omitempty"`
	Head     string `json:"head"`
	Base     string `json:"base"`
	Draft    bool   `json:"draft,omitempty"`
	ForkPath string `json:"fork_path,omitempty"` // 跨仓库 PR:fork 项目路径【owner/repo】
}

CreatePROptions represents options for creating a PR

type CreatePRReviewOptions

type CreatePRReviewOptions struct {
	Body     string            `json:"body,omitempty"`
	Event    string            `json:"event"`
	Comments []PRReviewComment `json:"comments,omitempty"`
}

CreatePRReviewOptions represents options for creating a PR review

type CreateReleaseOptions

type CreateReleaseOptions struct {
	TagName         string `json:"tag_name"`
	Name            string `json:"name,omitempty"`
	Body            string `json:"body,omitempty"`
	Draft           bool   `json:"draft,omitempty"`
	Prerelease      bool   `json:"prerelease,omitempty"`
	TargetCommitish string `json:"target_commitish,omitempty"`
}

CreateReleaseOptions represents options for creating a release

type CreateRepoOptions

type CreateRepoOptions struct {
	Name              string `json:"name"`
	Description       string `json:"description,omitempty"`
	Private           bool   `json:"private"`
	AutoInit          bool   `json:"auto_init,omitempty"`
	GitignoreTemplate string `json:"gitignore_template,omitempty"`
	LicenseTemplate   string `json:"license_template,omitempty"`
}

CreateRepoOptions represents options for creating a repository

type EditPRCommentOptions added in v0.2.5

type EditPRCommentOptions struct {
	Body string `json:"body"`
}

EditPRCommentOptions represents options for editing a PR comment

type FlexibleTime added in v0.3.3

type FlexibleTime struct {
	time.Time
}

FlexibleTime is a custom time type that can parse multiple time formats returned by GitCode API.

func (FlexibleTime) Format added in v0.3.3

func (ft FlexibleTime) Format(layout string) string

Format returns a formatted string representation of the time.

func (FlexibleTime) IsZero added in v0.3.3

func (ft FlexibleTime) IsZero() bool

IsZero returns true if the time is zero.

func (FlexibleTime) MarshalJSON added in v0.3.3

func (ft FlexibleTime) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (FlexibleTime) String added in v0.3.3

func (ft FlexibleTime) String() string

String returns a string representation of the time.

func (*FlexibleTime) UnmarshalJSON added in v0.3.3

func (ft *FlexibleTime) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface. It tries multiple time formats to parse the input.

type Issue

type Issue struct {
	ID        interface{}   `json:"id"`
	Number    string        `json:"number"`
	Title     string        `json:"title"`
	Body      string        `json:"body"`
	State     string        `json:"state"`
	HTMLURL   string        `json:"html_url"`
	User      *User         `json:"user"`
	Assignees []*User       `json:"assignees"`
	Labels    []*Label      `json:"labels"`
	Milestone *Milestone    `json:"milestone"`
	CreatedAt FlexibleTime  `json:"created_at"`
	UpdatedAt FlexibleTime  `json:"updated_at"`
	ClosedAt  *FlexibleTime `json:"closed_at"`
	Comments  int           `json:"comments"`
}

Issue represents a GitCode issue

func CloseIssue

func CloseIssue(client *Client, owner, repo string, number int) (*Issue, error)

CloseIssue closes an issue

func CreateIssue

func CreateIssue(client *Client, owner, repo string, opts *CreateIssueOptions) (*Issue, error)

CreateIssue creates a new issue

func GetIssue

func GetIssue(client *Client, owner, repo string, number int) (*Issue, error)

GetIssue fetches an issue by number

func ListRepoIssues

func ListRepoIssues(client *Client, owner, repo string, opts *IssueListOptions) ([]Issue, error)

ListRepoIssues lists issues for a repository

func ReopenIssue

func ReopenIssue(client *Client, owner, repo string, number int) (*Issue, error)

ReopenIssue reopens a closed issue

func UpdateIssue

func UpdateIssue(client *Client, owner, repo string, number int, opts *UpdateIssueOptions) (*Issue, error)

UpdateIssue updates an existing issue GitCode API: PATCH /repos/:owner/issues/:number with repo param in body

type IssueComment

type IssueComment struct {
	ID        interface{}  `json:"id"`
	Body      string       `json:"body"`
	User      *User        `json:"user"`
	CreatedAt FlexibleTime `json:"created_at"`
	UpdatedAt FlexibleTime `json:"updated_at"`
}

IssueComment represents a comment on an issue

func CreateIssueComment

func CreateIssueComment(client *Client, owner, repo string, number int, opts *CreateCommentOptions) (*IssueComment, error)

CreateIssueComment creates a comment on an issue

func ListIssueComments

func ListIssueComments(client *Client, owner, repo string, number int, opts *IssueCommentListOptions) ([]IssueComment, error)

ListIssueComments lists comments on an issue

func UpdateIssueComment added in v0.3.7

func UpdateIssueComment(client *Client, owner, repo string, commentID string, opts *UpdateCommentOptions) (*IssueComment, error)

UpdateIssueComment updates a comment on an issue.

type IssueCommentListOptions added in v0.3.7

type IssueCommentListOptions struct {
	Page    int
	PerPage int
	Order   string
	Since   string
}

IssueCommentListOptions represents options for listing issue comments.

type IssueListOptions

type IssueListOptions struct {
	State         string `url:"state,omitempty"`
	Labels        string `url:"labels,omitempty"`
	Sort          string `url:"sort,omitempty"`
	Direction     string `url:"direction,omitempty"`
	Since         string `url:"since,omitempty"`
	PerPage       int    `url:"per_page,omitempty"`
	Page          int    `url:"page,omitempty"`
	Milestone     string `url:"milestone,omitempty"`
	Assignee      string `url:"assignee,omitempty"`
	Creator       string `url:"creator,omitempty"`
	CreatedAfter  string `url:"created_after,omitempty"`
	CreatedBefore string `url:"created_before,omitempty"`
	UpdatedAfter  string `url:"updated_after,omitempty"`
	UpdatedBefore string `url:"updated_before,omitempty"`
	Search        string `url:"search,omitempty"`
}

IssueListOptions represents options for listing issues

type IssuePR added in v0.2.11

type IssuePR struct {
	ID            interface{}   `json:"id"`
	HTMLURL       string        `json:"html_url"`
	DiffURL       string        `json:"diff_url"`
	Number        int           `json:"number"`
	State         string        `json:"state"`
	Title         string        `json:"title"`
	Body          string        `json:"body"`
	Labels        []*Label      `json:"labels"`
	User          *User         `json:"user"`
	Head          *PRBranch     `json:"head"`
	Base          *PRBranch     `json:"base"`
	Assignees     []*User       `json:"assignees"`
	Testers       []*User       `json:"testers"`
	CreatedAt     FlexibleTime  `json:"created_at"`
	UpdatedAt     FlexibleTime  `json:"updated_at"`
	MergedAt      *FlexibleTime `json:"merged_at"`
	ClosedAt      *FlexibleTime `json:"closed_at"`
	CanMergeCheck bool          `json:"can_merge_check"`
}

IssuePR represents a Pull Request associated with an issue

func GetIssuePullRequests added in v0.2.11

func GetIssuePullRequests(client *Client, owner, repo string, number int, mode int) ([]IssuePR, error)

GetIssuePullRequests gets Pull Requests associated with an issue mode: 1 (enhanced mode, returns mergeable status), 0 (default, no mergeable status)

type Label

type Label struct {
	ID          interface{} `json:"id"`
	Name        string      `json:"name"`
	Color       string      `json:"color"`
	Description string      `json:"description"`
}

Label represents a GitCode label

func AddIssueLabels added in v0.2.4

func AddIssueLabels(client *Client, owner, repo string, number int, labels []string) ([]*Label, error)

AddIssueLabels adds labels to an issue by updating the issue

func AddLabelsToIssue

func AddLabelsToIssue(client *Client, owner, repo string, number int, labels []string) ([]Label, error)

AddLabelsToIssue adds labels to an issue

func CreateLabel

func CreateLabel(client *Client, owner, repo string, opts *CreateLabelOptions) (*Label, error)

CreateLabel creates a new label in a repository

func GetLabel

func GetLabel(client *Client, owner, repo, name string) (*Label, error)

GetLabel fetches a label by name

func ListRepoLabels

func ListRepoLabels(client *Client, owner, repo string) ([]Label, error)

ListRepoLabels lists labels for a repository

func SetIssueLabels

func SetIssueLabels(client *Client, owner, repo string, number int, labels []string) ([]Label, error)

SetIssueLabels sets (replaces) labels on an issue

func UpdateLabel

func UpdateLabel(client *Client, owner, repo, name string, opts *UpdateLabelOptions) (*Label, error)

UpdateLabel updates an existing label

type ListOptions added in v0.3.0

type ListOptions struct {
	Page    int
	PerPage int
	Order   string
}

ListOptions represents common list options

type MergePROptions

type MergePROptions struct {
	CommitTitle   string `json:"commit_title,omitempty"`
	CommitMessage string `json:"commit_message,omitempty"`
	SHA           string `json:"sha,omitempty"`
	MergeMethod   string `json:"merge_method,omitempty"`
}

MergePROptions represents options for merging a PR

type Milestone

type Milestone struct {
	ID          interface{} `json:"id"`
	Number      int         `json:"number"`
	Title       string      `json:"title"`
	Description string      `json:"description"`
	State       string      `json:"state"`
	DueOn       string      `json:"due_on"`
}

Milestone represents a GitCode milestone

func CloseMilestone

func CloseMilestone(client *Client, owner, repo string, number int) (*Milestone, error)

CloseMilestone closes a milestone

func CreateMilestone

func CreateMilestone(client *Client, owner, repo string, opts *CreateMilestoneOptions) (*Milestone, error)

CreateMilestone creates a new milestone

func GetMilestone

func GetMilestone(client *Client, owner, repo string, number int) (*Milestone, error)

GetMilestone fetches a milestone by number

func ListRepoMilestones

func ListRepoMilestones(client *Client, owner, repo string) ([]Milestone, error)

ListRepoMilestones lists milestones for a repository

func OpenMilestone

func OpenMilestone(client *Client, owner, repo string, number int) (*Milestone, error)

OpenMilestone reopens a milestone

func UpdateMilestone

func UpdateMilestone(client *Client, owner, repo string, number int, opts *UpdateMilestoneOptions) (*Milestone, error)

UpdateMilestone updates an existing milestone

type PRBranch

type PRBranch struct {
	Label string      `json:"label"`
	Ref   string      `json:"ref"`
	SHA   string      `json:"sha"`
	Repo  *Repository `json:"repo"`
}

PRBranch represents a branch in a PR

type PRComment

type PRComment struct {
	ID           interface{}  `json:"id"`
	DiscussionID string       `json:"discussion_id"`
	Body         string       `json:"body"`
	User         *User        `json:"user"`
	CreatedAt    FlexibleTime `json:"created_at"`
	UpdatedAt    FlexibleTime `json:"updated_at"`
	CommentType  string       `json:"comment_type"`
	Resolved     bool         `json:"resolved"`
	DiffFile     string       `json:"diff_file"`
	DiffPosition interface{}  `json:"diff_position"`
}

PRComment represents a comment on a PR

func CreatePRComment

func CreatePRComment(client *Client, owner, repo string, number int, opts *CreatePRCommentOptions) (*PRComment, error)

CreatePRComment creates a comment on a PR

func EditPRComment added in v0.2.5

func EditPRComment(client *Client, owner, repo string, commentID int, opts *EditPRCommentOptions) (*PRComment, error)

EditPRComment edits a PR comment

func ListPRComments

func ListPRComments(client *Client, owner, repo string, number int) ([]PRComment, error)

ListPRComments lists comments on a PR

type PRDiff added in v0.2.2

type PRDiff struct {
	NewBlobID string         `json:"new_blob_id"`
	Statistic *PRStatistic   `json:"statistic"`
	Type      string         `json:"type"`
	Path      string         `json:"path"`
	OldPath   string         `json:"old_path"`
	NewPath   string         `json:"new_path"`
	View      int            `json:"view"`
	Head      *PRDiffHead    `json:"head"`
	Content   *PRDiffContent `json:"content"`
}

PRDiff represents a single file diff

type PRDiffContent added in v0.2.2

type PRDiffContent struct {
	Text []*PRDiffLine `json:"text"`
}

PRDiffContent represents diff content

type PRDiffHead added in v0.2.2

type PRDiffHead struct {
	URL       string `json:"url"`
	CommitID  string `json:"commit_id"`
	Additions int    `json:"added_lines"`
	Deletions int    `json:"remove_lines"`
}

PRDiffHead represents diff head info

type PRDiffLine added in v0.2.2

type PRDiffLine struct {
	LineContent string      `json:"line_content"`
	OldLine     interface{} `json:"old_line"` // can be string "..." or object
	NewLine     interface{} `json:"new_line"` // can be string "..." or object
	Type        string      `json:"type"`
}

PRDiffLine represents a single diff line

type PRDiffRefs added in v0.2.2

type PRDiffRefs struct {
	BaseSHA  string `json:"base_sha"`
	StartSHA string `json:"start_sha"`
	HeadSHA  string `json:"head_sha"`
}

PRDiffRefs represents diff references

type PRFilesResponse added in v0.2.2

type PRFilesResponse struct {
	Code        int         `json:"code"`
	AddedLines  int         `json:"added_lines"`
	RemoveLines int         `json:"remove_lines"`
	Count       int         `json:"count"`
	DiffRefs    *PRDiffRefs `json:"diff_refs"`
	Diffs       []*PRDiff   `json:"diffs"`
}

PRFilesResponse represents the response from PR files API

func GetPRFiles added in v0.2.2

func GetPRFiles(client *Client, owner, repo string, number int) (*PRFilesResponse, error)

GetPRFiles gets the files and diffs of a PR

type PRListOptions

type PRListOptions struct {
	State     string `url:"state,omitempty"`
	Head      string `url:"head,omitempty"`
	Base      string `url:"base,omitempty"`
	Sort      string `url:"sort,omitempty"`
	Direction string `url:"direction,omitempty"`
	PerPage   int    `url:"per_page,omitempty"`
	Page      int    `url:"page,omitempty"`
}

PRListOptions represents options for listing PRs

type PRReview

type PRReview struct {
	ID          interface{}  `json:"id"`
	User        *User        `json:"user"`
	Body        string       `json:"body"`
	State       string       `json:"state"`
	SubmittedAt FlexibleTime `json:"submitted_at"`
}

PRReview represents a review on a PR

func CreatePRReview

func CreatePRReview(client *Client, owner, repo string, number int, opts *CreatePRReviewOptions) (*PRReview, error)

CreatePRReview creates a review on a PR

func ListPRReviews

func ListPRReviews(client *Client, owner, repo string, number int) ([]PRReview, error)

ListPRReviews lists reviews on a PR

type PRReviewComment

type PRReviewComment struct {
	Path     string `json:"path"`
	Position int    `json:"position"`
	Body     string `json:"body"`
}

PRReviewComment represents a comment in a review

type PRStatistic added in v0.2.2

type PRStatistic struct {
	Additions int `json:"additions"`
	Deletions int `json:"deletions"`
}

PRStatistic represents file change statistics

type PullRequest

type PullRequest struct {
	ID           interface{}  `json:"id"`
	Number       int          `json:"number"`
	Title        string       `json:"title"`
	Body         string       `json:"body"`
	State        string       `json:"state"`
	HTMLURL      string       `json:"html_url"`
	DiffURL      string       `json:"diff_url"`
	PatchURL     string       `json:"patch_url"`
	User         *User        `json:"user"`
	Head         *PRBranch    `json:"head"`
	Base         *PRBranch    `json:"base"`
	Merged       bool         `json:"merged"`
	MergedAt     *string      `json:"merged_at"`
	Mergeable    *bool        `json:"mergeable"`
	MergeState   interface{}  `json:"mergeable_state"`
	Draft        bool         `json:"draft"`
	CreatedAt    FlexibleTime `json:"created_at"`
	UpdatedAt    FlexibleTime `json:"updated_at"`
	ClosedAt     *string      `json:"closed_at"`
	Comments     int          `json:"comments"`
	Commits      int          `json:"commits"`
	Additions    int          `json:"additions"`
	Deletions    int          `json:"deletions"`
	ChangedFiles int          `json:"changed_files"`
	Labels       []*Label     `json:"labels"`
	Assignees    []*User      `json:"assignees"`
	Reviewers    []*User      `json:"requested_reviewers"`
}

PullRequest represents a GitCode pull request

func ClosePullRequest

func ClosePullRequest(client *Client, owner, repo string, number int) (*PullRequest, error)

ClosePullRequest closes a PR

func CreatePullRequest

func CreatePullRequest(client *Client, owner, repo string, opts *CreatePROptions) (*PullRequest, error)

CreatePullRequest creates a new PR

func EditPR added in v0.2.5

func EditPR(client *Client, owner, repo string, number int, opts *UpdatePROptions) (*PullRequest, error)

EditPR updates a PR's information

func GetPullRequest

func GetPullRequest(client *Client, owner, repo string, number int) (*PullRequest, error)

GetPullRequest fetches a PR by number

func ListPullRequests

func ListPullRequests(client *Client, owner, repo string, opts *PRListOptions) ([]PullRequest, error)

ListPullRequests lists pull requests for a repository

func MergePullRequest

func MergePullRequest(client *Client, owner, repo string, number int, opts *MergePROptions) (*PullRequest, error)

MergePullRequest merges a PR

func ReopenPullRequest

func ReopenPullRequest(client *Client, owner, repo string, number int) (*PullRequest, error)

ReopenPullRequest reopens a closed PR

func UpdatePullRequest

func UpdatePullRequest(client *Client, owner, repo string, number int, opts *UpdatePROptions) (*PullRequest, error)

UpdatePullRequest updates an existing PR

type Release

type Release struct {
	ID              interface{}    `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"`
	HTMLURL         string         `json:"html_url"`
	AssetsURL       string         `json:"assets_url"`
	UploadURL       string         `json:"upload_url"`
	CreatedAt       FlexibleTime   `json:"created_at"`
	PublishedAt     *FlexibleTime  `json:"published_at"`
	Author          *User          `json:"author"`
	Assets          []ReleaseAsset `json:"assets"`
}

Release represents a GitCode release

func CreateRelease

func CreateRelease(client *Client, owner, repo string, opts *CreateReleaseOptions) (*Release, error)

CreateRelease creates a new release

func GetLatestRelease

func GetLatestRelease(client *Client, owner, repo string) (*Release, error)

GetLatestRelease fetches the latest release for a repository

func GetRelease

func GetRelease(client *Client, owner, repo, tag string) (*Release, error)

GetRelease fetches a release by tag name

func GetReleaseByID

func GetReleaseByID(client *Client, owner, repo string, id int64) (*Release, error)

GetReleaseByID fetches a release by ID

func ListReleases

func ListReleases(client *Client, owner, repo string, opts *ReleaseListOptions) ([]Release, error)

ListReleases lists releases for a repository

func UpdateRelease

func UpdateRelease(client *Client, owner, repo string, id int64, opts *UpdateReleaseOptions) (*Release, error)

UpdateRelease updates an existing release by ID

func UpdateReleaseByTag

func UpdateReleaseByTag(client *Client, owner, repo, tag string, opts *UpdateReleaseOptions) (*Release, error)

UpdateReleaseByTag updates a release by tag name

func (*Release) GetID

func (r *Release) GetID() (int64, error)

GetID extracts the release ID as int64

type ReleaseAsset

type ReleaseAsset struct {
	ID                 int          `json:"id"`
	Name               string       `json:"name"`
	Label              string       `json:"label"`
	State              string       `json:"state"`
	ContentType        string       `json:"content_type"`
	Size               int          `json:"size"`
	Downloads          int          `json:"download_count"`
	URL                string       `json:"url"`
	BrowserDownloadURL string       `json:"browser_download_url"`
	CreatedAt          FlexibleTime `json:"created_at"`
	UpdatedAt          FlexibleTime `json:"updated_at"`
}

ReleaseAsset represents an asset in a release

func GetReleaseAsset

func GetReleaseAsset(client *Client, owner, repo string, assetID int64) (*ReleaseAsset, error)

GetReleaseAsset fetches a single release asset

func ListReleaseAssets

func ListReleaseAssets(client *Client, owner, repo string, releaseID int64) ([]ReleaseAsset, error)

ListReleaseAssets lists assets for a release

func UploadReleaseAsset

func UploadReleaseAsset(client *Client, owner, repo string, releaseID int64, filename string, content []byte, contentType string) (*ReleaseAsset, error)

UploadReleaseAsset uploads a file as a release asset

type ReleaseListOptions

type ReleaseListOptions struct {
	PerPage int `url:"per_page,omitempty"`
	Page    int `url:"page,omitempty"`
}

ReleaseListOptions represents options for listing releases

type ReplyPRCommentOptions added in v0.2.5

type ReplyPRCommentOptions struct {
	Body string `json:"body"`
}

ReplyPRCommentOptions represents options for replying to a PR comment

type ReplyPRCommentReply added in v0.2.5

type ReplyPRCommentReply struct {
	ID     string `json:"id"`
	NoteID int    `json:"noteId"`
	Body   string `json:"body"`
}

ReplyPRCommentReply represents the response from replying to a PR comment

func ReplyPRComment added in v0.2.5

func ReplyPRComment(client *Client, owner, repo string, number int, discussionID string, opts *ReplyPRCommentOptions) (*ReplyPRCommentReply, error)

ReplyPRComment replies to a PR comment discussion

type RepoListOptions

type RepoListOptions struct {
	Visibility  string `url:"visibility,omitempty"`
	Affiliation string `url:"affiliation,omitempty"`
	Type        string `url:"type,omitempty"`
	Sort        string `url:"sort,omitempty"`
	Direction   string `url:"direction,omitempty"`
	PerPage     int    `url:"per_page,omitempty"`
	Page        int    `url:"page,omitempty"`
}

RepoListOptions represents options for listing repositories

type Repository

type Repository struct {
	ID              interface{}  `json:"id"`
	Name            string       `json:"name"`
	FullName        string       `json:"full_name"`
	Description     string       `json:"description"`
	Private         bool         `json:"private"`
	Owner           *User        `json:"owner"`
	HTMLURL         string       `json:"web_url"`
	CloneURL        string       `json:"http_url_to_repo"`
	SSHURL          string       `json:"ssh_url_to_repo"`
	DefaultBranch   string       `json:"default_branch"`
	CreatedAt       FlexibleTime `json:"created_at"`
	UpdatedAt       FlexibleTime `json:"updated_at"`
	StargazersCount int          `json:"stargazers_count"`
	ForksCount      int          `json:"forks_count"`
	OpenIssuesCount int          `json:"open_issues_count"`
	Language        string       `json:"language"`
}

Repository represents a GitCode repository

func CreateOrgRepo

func CreateOrgRepo(client *Client, org string, opts *CreateRepoOptions) (*Repository, error)

CreateOrgRepo creates a new repository in an organization

func CreateRepo

func CreateRepo(client *Client, opts *CreateRepoOptions) (*Repository, error)

CreateRepo creates a new repository for the authenticated user

func ForkRepo

func ForkRepo(client *Client, owner, name string) (*Repository, error)

ForkRepo forks a repository

func GetRepo

func GetRepo(client *Client, owner, name string) (*Repository, error)

GetRepo fetches a repository by owner/name

func ListUserRepos

func ListUserRepos(client *Client, opts *RepoListOptions) ([]Repository, error)

ListUserRepos lists repositories for the authenticated user

type RepositoryCommit added in v0.3.0

type RepositoryCommit struct {
	SHA         string       `json:"sha"`
	URL         string       `json:"url"`
	HTMLURL     string       `json:"html_url"`
	CommentsURL string       `json:"comments_url"`
	Commit      *CommitInfo  `json:"commit"`
	Author      *User        `json:"author"`
	Committer   *User        `json:"committer"`
	Stats       *CommitStats `json:"stats"`
	Files       []CommitFile `json:"files"`
}

RepositoryCommit represents a detailed commit from the commits API

func GetCommit added in v0.3.0

func GetCommit(client *Client, owner, repo, sha string, showDiff bool) (*RepositoryCommit, error)

GetCommit fetches a single commit by SHA

type ResolvePRCommentOptions added in v0.2.5

type ResolvePRCommentOptions struct {
	Resolved bool `json:"resolved"`
}

ResolvePRCommentOptions represents options for resolving a PR comment

type ReviewPROptions added in v0.2.5

type ReviewPROptions struct {
	Force bool `json:"force,omitempty"` // Force approval (admin only)
}

ReviewPROptions represents options for reviewing a PR

type StatItem added in v0.3.0

type StatItem struct {
	Author    string `json:"author"`
	Additions int    `json:"additions"`
	Deletions int    `json:"deletions"`
	Total     int    `json:"total"`
}

StatItem represents a statistics item

type TestPROptions added in v0.2.5

type TestPROptions struct {
	Force bool `json:"force,omitempty"` // Force test pass (admin only)
}

TestPROptions represents options for PR test

type UpdateCommentOptions added in v0.3.7

type UpdateCommentOptions struct {
	Body string `json:"body"`
}

UpdateCommentOptions represents options for updating an issue comment.

type UpdateIssueOptions

type UpdateIssueOptions struct {
	Repo         string   `json:"repo,omitempty"`
	Title        string   `json:"title,omitempty"`
	Body         string   `json:"body,omitempty"`
	State        string   `json:"state,omitempty"`
	AssigneeIDs  []string `json:"assignee_ids,omitempty"`
	Labels       []string `json:"labels,omitempty"`
	Milestone    int      `json:"milestone,omitempty"`
	SecurityHole string   `json:"security_hole,omitempty"`
}

UpdateIssueOptions represents options for updating an issue

type UpdateLabelOptions

type UpdateLabelOptions struct {
	NewName     string `json:"new_name,omitempty"`
	Color       string `json:"color,omitempty"`
	Description string `json:"description,omitempty"`
}

UpdateLabelOptions represents options for updating a label

type UpdateMilestoneOptions

type UpdateMilestoneOptions struct {
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	State       string `json:"state,omitempty"`
	DueOn       string `json:"due_on,omitempty"`
}

UpdateMilestoneOptions represents options for updating a milestone

type UpdatePROptions

type UpdatePROptions struct {
	Title             string   `json:"title,omitempty"`
	Body              string   `json:"body,omitempty"`
	State             string   `json:"state,omitempty"`
	StateEvent        string   `json:"state_event,omitempty"`
	Base              string   `json:"base,omitempty"`
	Draft             *bool    `json:"draft,omitempty"`
	MilestoneNumber   int      `json:"milestone_number,omitempty"`
	Labels            []string `json:"labels,omitempty"`
	CloseRelatedIssue *bool    `json:"close_related_issue,omitempty"`
}

UpdatePROptions represents options for updating a PR

type UpdateReleaseOptions

type UpdateReleaseOptions struct {
	TagName         string `json:"tag_name,omitempty"`
	TargetCommitish string `json:"target_commitish,omitempty"`
	Name            string `json:"name,omitempty"`
	Body            string `json:"body,omitempty"`
	Draft           *bool  `json:"draft,omitempty"`
	Prerelease      *bool  `json:"prerelease,omitempty"`
}

UpdateReleaseOptions represents options for updating a release

type User

type User struct {
	ID        interface{} `json:"id"`
	Login     string      `json:"login"`
	Name      string      `json:"name"`
	Email     string      `json:"email"`
	AvatarURL string      `json:"avatar_url"`
	HTMLURL   string      `json:"html_url"`
	CreatedAt string      `json:"created_at"`
}

User represents a GitCode user

func CurrentUser

func CurrentUser(client *Client) (*User, error)

CurrentUser fetches the current authenticated user

func GetUser

func GetUser(client *Client, username string) (*User, error)

GetUser fetches a user by username

func VerifyToken

func VerifyToken(httpClient *http.Client, host, token string) (*User, error)

VerifyToken verifies that a token is valid by fetching the current user

func (*User) Username

func (u *User) Username() string

Username returns the user's login name

Source Files

  • client.go
  • queries_commit.go
  • queries_issue.go
  • queries_label_milestone.go
  • queries_pr.go
  • queries_release.go
  • queries_repo.go
  • queries_user.go
  • time.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL