api

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 7 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 has no ID")

ErrNoReleaseID is returned when release has no ID

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 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 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"`
	ErrorName  string `json:"error"`
}

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) 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) 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 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"`
	Assignees []string `json:"assignees,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       *time.Time `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 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 time.Time   `json:"created_at"`
	UpdatedAt time.Time   `json:"updated_at"`
	ClosedAt  *time.Time  `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 time.Time   `json:"created_at"`
	UpdatedAt time.Time   `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) ([]IssueComment, error)

ListIssueComments lists comments on an issue

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

IssueListOptions represents options for listing issues

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 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      string      `json:"number"`
	Title       string      `json:"title"`
	Description string      `json:"description"`
	State       string      `json:"state"`
	DueOn       *time.Time  `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    time.Time   `json:"created_at"`
	UpdatedAt    time.Time   `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 time.Time   `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    time.Time   `json:"created_at"`
	UpdatedAt    time.Time   `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       time.Time      `json:"created_at"`
	PublishedAt     *time.Time     `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          time.Time `json:"created_at"`
	UpdatedAt          time.Time `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       time.Time   `json:"created_at"`
	UpdatedAt       time.Time   `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 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 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 UpdateIssueOptions

type UpdateIssueOptions struct {
	Repo      string   `json:"repo,omitempty"`
	Title     string   `json:"title,omitempty"`
	Body      string   `json:"body,omitempty"`
	State     string   `json:"state,omitempty"`
	Assignees []string `json:"assignees,omitempty"`
	Labels    []string `json:"labels,omitempty"`
	Milestone int      `json:"milestone,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       *time.Time `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_issue.go
  • queries_label_milestone.go
  • queries_pr.go
  • queries_release.go
  • queries_repo.go
  • queries_user.go

Jump to

Keyboard shortcuts

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