Movatterモバイル変換


[0]ホーム

URL:


scm

package
v1.40.6Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License:BSD-2-Clause-PatentImports:12Imported by:161

Details

Repository

github.com/drone/go-scm

Links

Documentation

Index

Examples

Constants

View Source
const EmptyCommit = "0000000000000000000000000000000000000000"

EmptyCommit is an empty commit sha.

View Source
const SearchTimeFormat = "2006-01-02T15:04:05Z"

Variables

View Source
var (// ErrNotFound indicates a resource is not found.ErrNotFound =errors.New("Not Found")// ErrNotSupported indicates a resource endpoint is not// supported or implemented.ErrNotSupported =errors.New("Not Supported")// ErrNotAuthorized indicates the request is not// authorized or the user does not have access to the// resource.ErrNotAuthorized =errors.New("Not Authorized"))
View Source
var (// ErrSignatureInvalid is returned when the webhook// signature is invalid or cannot be calculated.ErrSignatureInvalid =errors.New("Invalid webhook signature")// ErrUnknownEvent is returned when the webhook event// is not recognized by the system.ErrUnknownEvent =errors.New("Unknown webhook event"))

Functions

funcConvertPrivateadded inv1.38.2

func ConvertPrivate(fromstring)bool

funcExpandRef

func ExpandRef(name, prefixstring)string

ExpandRef returns name expanded to the fully qualifiedreference path (e.g refs/heads/master).

funcExtractPullRequestadded inv1.14.1

func ExtractPullRequest(refstring)int

ExtractPullRequest returns name extraced pull requestnumber from the reference path.

funcIsBranchadded inv1.14.1

func IsBranch(refstring)bool

IsBranch returns true if the reference path points toa branch.

funcIsHashadded inv1.22.0

func IsHash(sstring)bool

IsHash returns true if the string is a commit hash.

funcIsPullRequestadded inv1.14.1

func IsPullRequest(refstring)bool

IsPullRequest returns true if the reference path pointsto a pull request object.

funcIsTagadded inv1.0.6

func IsTag(refstring)bool

IsTag returns true if the reference path points toa tag object.

funcJoin

func Join(owner, namestring)string

Join joins the repository owner and name segments tocreate a fully qualified repository name.

funcSplit

func Split(sstring) (owner, namestring)

Split splits the full repository name into segments.

funcTrimRef

func TrimRef(refstring)string

TrimRef returns ref without the path prefix.

funcWithContext

func WithContext(parentcontext.Context, token *Token)context.Context

WithContext returns a copy of parent in which the token value is set

Types

typeAction

type Actionint

Action identifies webhook actions.

const (ActionUnknownAction =iotaActionCreateActionUpdateActionDelete// issuesActionOpenActionReopenActionCloseActionLabelActionUnlabel// pull requestsActionSyncActionMergeActionReviewReady// issue commentActionEdit// releaseActionPublishActionUnpublishActionPrereleaseActionReleaseActionSubmittedActionDismissed)

Action values.

func (Action)MarshalJSON

func (aAction) MarshalJSON() ([]byte,error)

MarshalJSON returns the JSON-encoded Action.

func (Action)String

func (aAction) String() (sstring)

String returns the string representation of Action.

func (*Action)UnmarshalJSON

func (a *Action) UnmarshalJSON(data []byte)error

UnmarshalJSON unmarshales the JSON-encoded Action.

typeBranchHook

type BranchHook struct {RefReferenceRepoRepositoryActionActionSenderUser}

BranchHook represents a branch or tag event,eg create and delete github event types.

func (*BranchHook)Repository

func (h *BranchHook) Repository()Repository

typeBranchListOptionsadded inv1.30.0

type BranchListOptions struct {SearchTermstringIncludeCommitboolPageListOptionsListOptions}

BranchListOptions specifies optional branch search term and paginationparameters.

typeChange

type Change struct {PathstringAddedboolRenamedboolDeletedboolShastringBlobIDstringPrevFilePathstring}

Change represents a changed file.

typeClient

type Client struct {// HTTP client used to communicate with the API.Client *http.Client// Base URL for API requests.BaseURL *url.URL// Services used for communicating with the API.DriverDriverLinkerLinkerContentsContentServiceGitGitServiceOrganizationsOrganizationServiceIssuesIssueServiceMilestonesMilestoneServicePullRequestsPullRequestServiceRepositoriesRepositoryServiceReleasesReleaseServiceReviewsReviewServiceUsersUserServiceWebhooksWebhookService// DumpResponse optionally specifies a function to// dump the the response body for debugging purposes.// This can be set to httputil.DumpResponse.DumpResponse func(*http.Response,bool) ([]byte,error)// contains filtered or unexported fields}

Client manages communication with a version controlsystem API.

Example
package mainimport ("log""net/http""github.com/drone/go-scm/scm/driver/github")func main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}// Sets a custom http.Client. This can be used with// github.com/golang/oauth2 for authorization.client.Client = &http.Client{}}

func (*Client)Do

func (c *Client) Do(ctxcontext.Context, in *Request) (*Response,error)

Do sends an API request and returns the API response.The API response is JSON decoded and stored in thevalue pointed to by v, or returned as an error if anAPI error has occurred. If v implements the io.Writerinterface, the raw response will be written to v,without attempting to decode it.

func (*Client)Rate

func (c *Client) Rate()Rate

Rate returns a snapshot of the request rate limit forthe current client.

func (*Client)SetRate

func (c *Client) SetRate(rateRate)

SetRate set the last recorded request rate limit forthe current client.

typeComment

type Comment struct {IDintBodystringAuthorUserCreatedtime.TimeUpdatedtime.Time}

Comment represents a comment.

Example (Create)
package mainimport ("context""log""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}in := &scm.CommentInput{Body: "Found a bug",}comment, _, err := client.Issues.CreateComment(ctx, "octocat/Hello-World", 1, in)if err != nil {log.Fatal(err)}log.Println(comment.ID)}

Example (Find)
package mainimport ("context""log""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}comment, _, err := client.Issues.FindComment(ctx, "octocat/Hello-World", 1, 1)if err != nil {log.Fatal(err)}log.Println(comment.Body)}

Example (List)
package mainimport ("context""log""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}opts := scm.ListOptions{Page: 1,Size: 30,}comments, _, err := client.Issues.ListComments(ctx, "octocat/Hello-World", 1, opts)if err != nil {log.Fatal(err)}for _, comment := range comments {log.Println(comment.Body)}}

typeCommentInput

type CommentInput struct {Bodystring}

CommentInput provides the input fields required forcreating an issue comment.

typeCommit

type Commit struct {ShastringMessagestringAuthorSignatureCommitterSignatureLinkstring}

Commit represents a repository commit.

Example (Changes)
package mainimport ("context""log""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}opts := scm.ListOptions{Page: 1,Size: 30,}changes, _, err := client.Git.ListChanges(ctx, "octocat/Hello-World", "6dcb09b5b57875f334f61aebed695e2e4193db5e", opts)if err != nil {log.Fatal(err)}for _, change := range changes {log.Println(change.Path, change.Added, change.Deleted, change.Renamed)}}

Example (Find)
package mainimport ("context""log""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}commit, _, err := client.Git.FindCommit(ctx, "octocat/Hello-World", "6dcb09b5b57875f334f61aebed695e2e4193db5e")if err != nil {log.Fatal(err)}log.Println(commit.Sha, commit.Message, commit.Author.Login)}

Example (List)
package mainimport ("context""log""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}opts := scm.CommitListOptions{Ref:  "master",Page: 1,Size: 30,}commits, _, err := client.Git.ListCommits(ctx, "octocat/Hello-World", opts)if err != nil {log.Fatal(err)}for _, commit := range commits {log.Println(commit.Sha, commit.Message, commit.Author.Login)}}

typeCommitListOptions

type CommitListOptions struct {RefstringPageintSizeintPathstring}

CommitListOptions provides options for querying alist of repository commits.

typeContent

type Content struct {PathstringData   []byteShastringBlobIDstring}

Content stores the contents of a repository file.

Example (Find)
package mainimport ("context""log""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}content, _, err := client.Contents.Find(ctx, "octocat/Hello-World", "README", "6dcb09b5b57875f334f61aebed695e2e4193db5e")if err != nil {log.Fatal(err)}log.Println(content.Path, content.Data)}

typeContentInfoadded inv1.14.1

type ContentInfo struct {PathstringShastringBlobIDstringKindContentKind}

ContentInfo stores the kind of any content in a repository.

typeContentKindadded inv1.14.1

type ContentKindint

ContentKind defines the kind of a content in a directory.

const (ContentKindUnsupportedContentKind =iotaContentKindFileContentKindDirectoryContentKindSymlinkContentKindGitlink)

ContentKind values.

func (ContentKind)MarshalJSONadded inv1.21.0

func (kContentKind) MarshalJSON() ([]byte,error)

MarshalJSON returns the JSON-encoded Action.

func (ContentKind)Stringadded inv1.14.1

func (kContentKind) String()string

String returns the string representation of ContentKind.

func (*ContentKind)UnmarshalJSONadded inv1.14.1

func (k *ContentKind) UnmarshalJSON(data []byte)error

UnmarshalJSON unmarshales the JSON-encoded ContentKind.

typeContentParams

type ContentParams struct {RefstringBranchstringMessagestringData      []byteShastringBlobIDstringSignatureSignature}

ContentParams provide parameters for creating andupdating repository content.

typeContentService

type ContentService interface {// Find returns the repository file content by path.Find(ctxcontext.Context, repo, path, refstring) (*Content, *Response,error)// Create creates a new repository file.Create(ctxcontext.Context, repo, pathstring, params *ContentParams) (*Response,error)// Update updates a repository file.Update(ctxcontext.Context, repo, pathstring, params *ContentParams) (*Response,error)// Delete deletes a repository file.Delete(ctxcontext.Context, repo, pathstring, params *ContentParams) (*Response,error)// List returns a list of contents in a repository directory by path. It is// up to the driver to list the directory recursively or non-recursively,// but a robust driver should return a non-recursive list if possible.List(ctxcontext.Context, repo, path, refstring, optsListOptions) ([]*ContentInfo, *Response,error)}

ContentService provides access to repositroy content.

typeCreateBranchadded inv1.14.1

type CreateBranch =ReferenceInput

CreateBranch is a type alias for upstream projectsthat use the previous CreateBranch type name.

typeDeployHookadded inv1.0.8

type DeployHook struct {Data      interface{}DescstringNumberint64RefReferenceRepoRepositorySenderUserTargetstringTargetURLstringTaskstring}

DeployHook represents a deployment event. This iscurrently a GitHub-specific event type.

func (*DeployHook)Repositoryadded inv1.0.8

func (h *DeployHook) Repository()Repository

typeDeployStatusadded inv1.14.1

type DeployStatus struct {Numberint64StateStateDescstringTargetstringEnvironmentstringEnvironmentURLstring}

DeployStatus represents a deployment status.

typeDriver

type Driverint

Driver identifies source code management driver.

const (DriverUnknownDriver =iotaDriverGithubDriverGitlabDriverGogsDriverGiteaDriverBitbucketDriverStashDriverCodingDriverGiteeDriverAzureDriverHarness)

Driver values.

func (Driver)String

func (dDriver) String() (sstring)

String returns the string representation of Driver.

typeEmailadded inv1.22.0

type Email struct {ValuestringPrimaryboolVerifiedbool}

Email represents a user email.

typeExecutionadded inv1.40.0

type Execution struct {NumberintStatusExecutionStatusCreatedtime.TimeUpdatedtime.TimeURLstring}

Pipeline Execution details

typeExecutionStatusadded inv1.40.0

type ExecutionStatusint

Status defines an enum for execution status

const (StatusUnknownExecutionStatus =iotaStatusPendingStatusRunningStatusSuccessStatusFailedStatusCanceled)

funcConvertExecutionStatusadded inv1.40.0

func ConvertExecutionStatus(fromstring)ExecutionStatus

func (ExecutionStatus)MarshalJSONadded inv1.40.0

func (kExecutionStatus) MarshalJSON() ([]byte,error)

MarshalJSON returns the JSON-encoded Action.

func (ExecutionStatus)Stringadded inv1.40.0

func (kExecutionStatus) String()string

String returns the string representation of ExecutionStatus.

func (*ExecutionStatus)UnmarshalJSONadded inv1.40.0

func (k *ExecutionStatus) UnmarshalJSON(data []byte)error

UnmarshalJSON unmarshales the JSON-encoded ExecutionStatus.

typeGitService

type GitService interface {// CreateBranch creates a git branch by name given a sha.CreateBranch(ctxcontext.Context, repostring, params *ReferenceInput) (*Response,error)// FindBranch finds a git branch by name.FindBranch(ctxcontext.Context, repo, namestring) (*Reference, *Response,error)// FindCommit finds a git commit by ref.FindCommit(ctxcontext.Context, repo, refstring) (*Commit, *Response,error)// FindTag finds a git tag by name.FindTag(ctxcontext.Context, repo, namestring) (*Reference, *Response,error)// ListBranches returns a list of git branches.ListBranches(ctxcontext.Context, repostring, optsListOptions) ([]*Reference, *Response,error)// ListBranchesV2 returns a list of git branches based on the searchTerm passed.ListBranchesV2(ctxcontext.Context, repostring, optsBranchListOptions) ([]*Reference, *Response,error)// ListCommits returns a list of git commits.ListCommits(ctxcontext.Context, repostring, optsCommitListOptions) ([]*Commit, *Response,error)// ListChanges returns the changeset of a commit.ListChanges(ctxcontext.Context, repo, refstring, optsListOptions) ([]*Change, *Response,error)// ListTags returns a list of git tags.ListTags(ctxcontext.Context, repostring, optsListOptions) ([]*Reference, *Response,error)// CompareChanges returns the changeset between two// commits. If the source commit is not an ancestor// of the target commit, it is up to the driver to// return a 2-way or 3-way diff changeset.CompareChanges(ctxcontext.Context, repo, source, targetstring, optsListOptions) ([]*Change, *Response,error)}

GitService provides access to git resources.

typeHook

type Hook struct {IDstringNamestringTargetstringEvents     []stringActiveboolSkipVerifybool}

Hook represents a repository hook.

Example (Create)
package mainimport ("context""log""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}input := &scm.HookInput{Name:       "CI",Target:     "https://ci.example.com",Secret:     "topsecret",SkipVerify: false,Events: scm.HookEvents{Branch:             true,Issue:              false,IssueComment:       false,PullRequest:        true,PullRequestComment: false,Push:               true,ReviewComment:      false,Tag:                true,},}_, _, err = client.Repositories.CreateHook(ctx, "octocat/Hello-World", input)if err != nil {log.Fatal(err)}}

Example (Find)
package mainimport ("context""log""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}hook, _, err := client.Repositories.FindHook(ctx, "octocat/Hello-World", "1")if err != nil {log.Fatal(err)}log.Println(hook.ID, hook.Target, hook.Events)}

Example (List)
package mainimport ("context""log""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}opts := scm.ListOptions{Page: 1,Size: 30,}hooks, _, err := client.Repositories.ListHooks(ctx, "octocat/Hello-World", opts)if err != nil {log.Fatal(err)}for _, hook := range hooks {log.Println(hook.ID, hook.Target, hook.Events)}}

typeHookEvents

type HookEvents struct {BranchboolDeploymentboolIssueboolIssueCommentboolPipelineboolPullRequestboolPullRequestCommentboolPushboolReviewCommentboolTagbool}

HookEvents represents supported hook events.

typeHookInput

type HookInput struct {NamestringTargetstringSecretstringEventsHookEventsSkipVerifybool// NativeEvents are used to create hooks with// provider-specific event types that cannot be// abstracted or represented in HookEvents.NativeEvents []string}

HookInput provides the input fields required forcreating or updating repository webhooks.

typeIssue

type Issue struct {NumberintTitlestringBodystringLinkstringLabels      []stringClosedboolLockedboolAuthorUserPullRequestPullRequestCreatedtime.TimeUpdatedtime.Time}

Issue represents an issue.

Example (Close)
package mainimport ("context""log""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}_, err = client.Issues.Close(ctx, "octocat/Hello-World", 1)if err != nil {log.Fatal(err)}}

Example (Find)
package mainimport ("context""log""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}issue, _, err := client.Issues.Find(ctx, "octocat/Hello-World", 1)if err != nil {log.Fatal(err)}log.Println(issue.Number, issue.Title)}

Example (List)
package mainimport ("context""log""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}opts := scm.IssueListOptions{Page:   1,Size:   30,Open:   true,Closed: false,}issues, _, err := client.Issues.List(ctx, "octocat/Hello-World", opts)if err != nil {log.Fatal(err)}for _, issue := range issues {log.Println(issue.Number, issue.Title)}}

Example (Lock)
package mainimport ("context""log""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}_, err = client.Issues.Lock(ctx, "octocat/Hello-World", 1)if err != nil {log.Fatal(err)}}

Example (Unlock)
package mainimport ("context""log""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}_, err = client.Issues.Lock(ctx, "octocat/Hello-World", 1)if err != nil {log.Fatal(err)}}

typeIssueCommentHook

type IssueCommentHook struct {ActionActionRepoRepositoryIssueIssueCommentCommentSenderUser}

IssueCommentHook represents an issue comment event,eg issue_comment.

func (*IssueCommentHook)Repository

func (h *IssueCommentHook) Repository()Repository

typeIssueHook

type IssueHook struct {ActionActionRepoRepositoryIssueIssueSenderUser}

IssueHook represents an issue event, eg issues.

func (*IssueHook)Repository

func (h *IssueHook) Repository()Repository

typeIssueInput

type IssueInput struct {TitlestringBodystring}

IssueInput provides the input fields required forcreating or updating an issue.

typeIssueListOptions

type IssueListOptions struct {PageintSizeintOpenboolClosedbool}

IssueListOptions provides options for querying alist of repository issues.

typeIssueService

type IssueService interface {// Find returns the issue by number.Find(context.Context,string,int) (*Issue, *Response,error)// FindComment returns the issue comment.FindComment(context.Context,string,int,int) (*Comment, *Response,error)// List returns the repository issue list.List(context.Context,string,IssueListOptions) ([]*Issue, *Response,error)// ListComments returns the issue comment list.ListComments(context.Context,string,int,ListOptions) ([]*Comment, *Response,error)// Create creates a new issue.Create(context.Context,string, *IssueInput) (*Issue, *Response,error)// CreateComment creates a new issue comment.CreateComment(context.Context,string,int, *CommentInput) (*Comment, *Response,error)// DeleteComment deletes an issue comment.DeleteComment(context.Context,string,int,int) (*Response,error)// Close closes an issue.Close(context.Context,string,int) (*Response,error)// Lock locks an issue discussion.Lock(context.Context,string,int) (*Response,error)// Unlock unlocks an issue discussion.Unlock(context.Context,string,int) (*Response,error)}

IssueService provides access to issue resources.

typeLabeladded inv1.14.1

type Label struct {NamestringColorstring}

typeLinkeradded inv1.14.1

type Linker interface {// Resource returns a link to the resource.Resource(ctxcontext.Context, repostring, refReference) (string,error)// Diff returns a link to the diff.Diff(ctxcontext.Context, repostring, source, targetReference) (string,error)}

Linker provides deep links to resources.

typeListOptions

type ListOptions struct {URLstringPageintSizeintSortKeystringOrderstring}

ListOptions specifies optional paginationparameters.

typeMembershipadded inv1.14.1

type Membership struct {ActiveboolRoleRole}

Membership represents an organization membership.

typeMilestoneadded inv1.16.0

type Milestone struct {NumberintIDintTitlestringDescriptionstringLinkstringStatestringDueDatetime.Time}

Milestone the milestone

typeMilestoneInputadded inv1.16.0

type MilestoneInput struct {TitlestringDescriptionstringStatestringDueDatetime.Time}

MilestoneInput contains the information needed to create a milestone

typeMilestoneListOptionsadded inv1.16.0

type MilestoneListOptions struct {PageintSizeintOpenboolClosedbool}

MilestoneListOptions provides options for querying a list of repository milestones.

typeMilestoneServiceadded inv1.16.0

type MilestoneService interface {// Find returns the milestone for the given number in the given repositoryFind(context.Context,string,int) (*Milestone, *Response,error)// List returns a list of milestones in the given repositoryList(context.Context,string,MilestoneListOptions) ([]*Milestone, *Response,error)// Create creates a milestone in the given repositoryCreate(context.Context,string, *MilestoneInput) (*Milestone, *Response,error)// Update updates a milestone in the given repositoryUpdate(context.Context,string,int, *MilestoneInput) (*Milestone, *Response,error)// Delete deletes a milestone in the given repositoryDelete(context.Context,string,int) (*Response,error)}

MilestoneService provides access to creating, listing, updating, and deleting milestones

typeOrganization

type Organization struct {NamestringAvatarstring}

Organization represents an organization account.

Example (Find)
package mainimport ("context""log""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}org, _, err := client.Organizations.Find(ctx, "github")if err != nil {log.Fatal(err)}log.Println(org.Name)}

Example (List)
package mainimport ("context""log""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}opts := scm.ListOptions{Page: 1,Size: 30,}orgs, _, err := client.Organizations.List(ctx, opts)if err != nil {log.Fatal(err)}for _, org := range orgs {log.Println(org.Name)}}

typeOrganizationService

type OrganizationService interface {// Find returns the organization by name.Find(ctxcontext.Context, namestring) (*Organization, *Response,error)// FindMembership returns the organization membership// by a given user account.FindMembership(ctxcontext.Context, name, usernamestring) (*Membership, *Response,error)// List returns the user organization list.List(ctxcontext.Context, optsListOptions) ([]*Organization, *Response,error)}

OrganizationService provides access to organization resources.

typePage

type Page struct {NextintNextURLstringLastintFirstintPrevint}

Page represents parsed link rel values forpagination.

typePerm

type Perm struct {PullboolPushboolAdminbool}

Perm represents a user's repository permissions.

typePipelineHookadded inv1.40.0

type PipelineHook struct {CommitCommitExecutionExecutionPullRequestPullRequestRepoRepositorySenderUser}

PipelineHook

func (*PipelineHook)Repositoryadded inv1.40.0

func (h *PipelineHook) Repository()Repository

typePullRequest

type PullRequest struct {NumberintTitlestringBodystringShastringRefstringSourcestringTargetstringForkstringLinkstringDiffstringDraftboolClosedboolMergedboolMergestringBaseReferenceHeadReferenceAuthorUserCreatedtime.TimeUpdatedtime.TimeLabels  []Label}

PullRequest represents a repository pull request.

Example (Changes)
package mainimport ("context""log""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}opts := scm.ListOptions{Page: 1,Size: 30,}changes, _, err := client.PullRequests.ListChanges(ctx, "octocat/Hello-World", 1, opts)if err != nil {log.Fatal(err)}for _, change := range changes {log.Println(change.Path, change.Added, change.Deleted, change.Renamed)}}

Example (Close)
package mainimport ("context""log""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}_, err = client.PullRequests.Close(ctx, "octocat/Hello-World", 1)if err != nil {log.Fatal(err)}}

Example (Find)
package mainimport ("context""log""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}pr, _, err := client.PullRequests.Find(ctx, "octocat/Hello-World", 1)if err != nil {log.Fatal(err)}log.Println(pr.Number, pr.Title)}

Example (List)
package mainimport ("context""log""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}opts := scm.PullRequestListOptions{Page:   1,Size:   30,Open:   true,Closed: false,}prs, _, err := client.PullRequests.List(ctx, "octocat/Hello-World", opts)if err != nil {log.Fatal(err)}for _, pr := range prs {log.Println(pr.Number, pr.Title)}}

Example (Merge)
package mainimport ("context""log""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}_, err = client.PullRequests.Merge(ctx, "octocat/Hello-World", 1)if err != nil {log.Fatal(err)}}

typePullRequestCommentHook

type PullRequestCommentHook struct {ActionActionRepoRepositoryPullRequestPullRequestCommentCommentSenderUser}

PullRequestCommentHook represents an pull requestcomment event, eg pull_request_comment.

func (*PullRequestCommentHook)Repository

func (h *PullRequestCommentHook) Repository()Repository

typePullRequestHook

type PullRequestHook struct {ActionActionRepoRepositoryPullRequestPullRequestSenderUser}

PullRequestHook represents an pull request event,eg pull_request.

func (*PullRequestHook)Repository

func (h *PullRequestHook) Repository()Repository

typePullRequestInputadded inv1.14.1

type PullRequestInput struct {TitlestringBodystringSourcestringTargetstring}

PullRequestInput provides the input fields required for creating a pull request.

typePullRequestListOptions

type PullRequestListOptions struct {PageintSizeintOpenboolClosedbool}

PullRequestListOptions provides options for queryinga list of repository merge requests.

typePullRequestService

type PullRequestService interface {// Find returns the repository pull request by number.Find(context.Context,string,int) (*PullRequest, *Response,error)// FindComment returns the pull request comment by id.FindComment(context.Context,string,int,int) (*Comment, *Response,error)// Find returns the repository pull request list.List(context.Context,string,PullRequestListOptions) ([]*PullRequest, *Response,error)// ListChanges returns the pull request changeset.ListChanges(context.Context,string,int,ListOptions) ([]*Change, *Response,error)// ListComments returns the pull request comment list.ListComments(context.Context,string,int,ListOptions) ([]*Comment, *Response,error)// ListCommits returns the pull request commit list.ListCommits(context.Context,string,int,ListOptions) ([]*Commit, *Response,error)// Merge merges the repository pull request.Merge(context.Context,string,int) (*Response,error)// Close closes the repository pull request.Close(context.Context,string,int) (*Response,error)// Create creates a new pull request.Create(context.Context,string, *PullRequestInput) (*PullRequest, *Response,error)// CreateComment creates a new pull request comment.CreateComment(context.Context,string,int, *CommentInput) (*Comment, *Response,error)// DeleteComment deletes an pull request comment.DeleteComment(context.Context,string,int,int) (*Response,error)}

PullRequestService provides access to pull request resources.

typePushHook

type PushHook struct {RefstringBaseRefstringRepoRepositoryBeforestringAfterstringCommitCommitSenderUserCommits []Commit}

PushHook represents a push hook, eg push events.

func (*PushHook)Repository

func (h *PushHook) Repository()Repository

typeRate

type Rate struct {LimitintRemainingintResetint64}

Rate represents the rate limit for the currentclient.

typeReference

type Reference struct {NamestringPathstringShastring}

Reference represents a git reference.

typeReferenceInputadded inv1.28.0

type ReferenceInput struct {NamestringShastring}

ReferenceInput provides a SHA for creating a reference.

typeReleaseadded inv1.16.0

type Release struct {IDintTitlestringDescriptionstringLinkstringTagstringCommitishstringDraftboolPrereleaseboolCreatedtime.TimePublishedtime.Time}

Release the release

typeReleaseHookadded inv1.28.0

type ReleaseHook struct {ActionActionReleaseReleaseRepoRepositorySenderUser}

ReleaseHook represents a release event. This iscurrently a GitHub-specific event type.

func (*ReleaseHook)Repositoryadded inv1.28.0

func (h *ReleaseHook) Repository()Repository

typeReleaseInputadded inv1.16.0

type ReleaseInput struct {TitlestringDescriptionstringTagstringCommitishstringDraftboolPrereleasebool}

ReleaseInput contains the information needed to create a release

typeReleaseListOptionsadded inv1.16.0

type ReleaseListOptions struct {PageintSizeintOpenboolClosedbool}

ReleaseListOptions provides options for querying a list of repository releases.

typeReleaseServiceadded inv1.16.0

type ReleaseService interface {// Find returns the release for the given number in the given repositoryFind(context.Context,string,int) (*Release, *Response,error)// FindByTag returns the release for the given tag in the given repositoryFindByTag(context.Context,string,string) (*Release, *Response,error)// List returns a list of releases in the given repositoryList(context.Context,string,ReleaseListOptions) ([]*Release, *Response,error)// Create creates a release in the given repositoryCreate(context.Context,string, *ReleaseInput) (*Release, *Response,error)// Update updates a release in the given repositoryUpdate(context.Context,string,int, *ReleaseInput) (*Release, *Response,error)// UpdateByTag deletes a release in the given repository by tagUpdateByTag(context.Context,string,string, *ReleaseInput) (*Release, *Response,error)// Delete deletes a release in the given repositoryDelete(context.Context,string,int) (*Response,error)// DeleteByTag deletes a release in the given repository by tagDeleteByTag(context.Context,string,string) (*Response,error)}

ReleaseService provides access to creating, listing, updating, and deleting releases

typeRepoListOptionsadded inv1.30.0

type RepoListOptions struct {ListOptionsRepoSearchTerm}

RepoListOptions specifies optional repo search term and paginationparameters.

typeRepoSearchTermadded inv1.30.0

type RepoSearchTerm struct {RepoNamestringUserstring}

RepoSearchTerm specifies searchable parameters.

typeRepository

type Repository struct {IDstringNamespacestringNamestringPerm       *PermBranchstringArchivedboolPrivateboolVisibilityVisibilityClonestringCloneSSHstringLinkstringCreatedtime.TimeUpdatedtime.Time}

Repository represents a git repository.

Example (Find)
package mainimport ("context""log""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}repo, _, err := client.Repositories.Find(ctx, "octocat/Hello-World")if err != nil {log.Fatal(err)}log.Println(repo.Namespace, repo.Name)}

Example (List)
package mainimport ("context""log""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}opts := scm.ListOptions{Page: 1,Size: 30,}repos, _, err := client.Repositories.List(ctx, opts)if err != nil {log.Fatal(err)}for _, repo := range repos {log.Println(repo.Namespace, repo.Name)}}

typeRepositoryService

type RepositoryService interface {// Find returns a repository by name.Find(context.Context,string) (*Repository, *Response,error)// FindHook returns a repository hook.FindHook(context.Context,string,string) (*Hook, *Response,error)// FindPerms returns repository permissions.FindPerms(context.Context,string) (*Perm, *Response,error)// List returns a list of repositories.List(context.Context,ListOptions) ([]*Repository, *Response,error)// ListV2 returns a list of repositories based on the searchTerm passed.ListV2(context.Context,RepoListOptions) ([]*Repository, *Response,error)// ListNamespace returns a list of repos in namespaceListNamespace(context.Context,string,ListOptions) ([]*Repository, *Response,error)// ListHooks returns a list or repository hooks.ListHooks(context.Context,string,ListOptions) ([]*Hook, *Response,error)// ListStatus returns a list of commit statuses.ListStatus(context.Context,string,string,ListOptions) ([]*Status, *Response,error)// CreateHook creates a new repository hook.CreateHook(context.Context,string, *HookInput) (*Hook, *Response,error)// CreateStatus creates a new commit status.CreateStatus(context.Context,string,string, *StatusInput) (*Status, *Response,error)// UpdateHook updates an existing repository hook.UpdateHook(context.Context,string,string, *HookInput) (*Hook, *Response,error)// DeleteHook deletes a repository hook.DeleteHook(context.Context,string,string) (*Response,error)}

RepositoryService provides access to repository resources.

typeRequest

type Request struct {MethodstringPathstringHeaderhttp.HeaderBodyio.Reader}

Request represents an HTTP request.

typeResponse

type Response struct {IDstringStatusintHeaderhttp.HeaderBodyio.ReadCloserPagePage// Page valuesRateRate// Rate limit snapshot}

Response represents an HTTP response.

typeReview

type Review struct {IDintBodystringPathstringShastringLineintLinkstringAuthorUserCreatedtime.TimeUpdatedtime.Time}

Review represents a review comment.

Example (Create)
package mainimport ("context""log""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}in := &scm.ReviewInput{Line: 38,Path: "main.go",Body: "Run gofmt please",}review, _, err := client.Reviews.Create(ctx, "octocat/Hello-World", 1, in)if err != nil {log.Fatal(err)}log.Println(review.ID)}

Example (Find)
package mainimport ("context""log""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}review, _, err := client.Reviews.Find(ctx, "octocat/Hello-World", 1, 1)if err != nil {log.Fatal(err)}log.Println(review.Path,review.Line,review.Body,)}

Example (List)
package mainimport ("context""log""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}opts := scm.ListOptions{Page: 1,Size: 30,}reviews, _, err := client.Reviews.List(ctx, "octocat/Hello-World", 1, opts)if err != nil {log.Fatal(err)}for _, review := range reviews {log.Println(review.Path,review.Line,review.Body,)}}

typeReviewCommentHook

type ReviewCommentHook struct {ActionActionRepoRepositoryPullRequestPullRequestReviewReview}

ReviewCommentHook represents a pull request reviewcomment, eg pull_request_review_comment.

func (*ReviewCommentHook)Repository

func (h *ReviewCommentHook) Repository()Repository

typeReviewInput

type ReviewInput struct {BodystringShastringPathstringLineint}

ReviewInput provides the input fields required forcreating a review comment.

typeReviewService

type ReviewService interface {// Find returns the review comment by id.Find(context.Context,string,int,int) (*Review, *Response,error)// List returns the review comment list.List(context.Context,string,int,ListOptions) ([]*Review, *Response,error)// Create creates a review comment.Create(context.Context,string,int, *ReviewInput) (*Review, *Response,error)// Delete deletes a review comment.Delete(context.Context,string,int,int) (*Response,error)}

ReviewService provides access to review resources.

typeRoleadded inv1.14.1

type Roleint

Role defines membership roles.

const (RoleUndefinedRole =iotaRoleMemberRoleAdmin)

Role values.

func (Role)Stringadded inv1.14.1

func (rRole) String() (sstring)

String returns the string representation of Role.

typeSecretFunc

type SecretFunc func(webhookWebhook) (string,error)

SecretFunc provides the Webhook parser with thesecret key used to validate webhook authenticity.

typeSignature

type Signature struct {NamestringEmailstringDatetime.Time// Fields are optional. The provider may choose to// include account information in the response.LoginstringAvatarstring}

Signature identifies a git commit creator.

typeState

type Stateint

State represents the commit state.

const (StateUnknownState =iotaStatePendingStateRunningStateSuccessStateFailureStateCanceledStateError)

State values.

typeStatus

type Status struct {StateStateLabelstringDescstringTargetstring// TODO(bradrydzewski) this field is only used// by Bitbucket which requires a user-defined// key (label), title and description. We need// to cleanup this abstraction.Titlestring}

Status represents a commit status.

Example (Create)
package mainimport ("context""log""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}input := &scm.StatusInput{State:  scm.StateSuccess,Label:  "continuous-integation",Desc:   "Build has completed successfully",Target: "https://ci.example.com/octocat/hello-world/1",}_, _, err = client.Repositories.CreateStatus(ctx, "octocat/Hello-World", "6dcb09b5b57875f334f61aebed695e2e4193db5e", input)if err != nil {log.Fatal(err)}}

Example (List)
package mainimport ("context""log""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}opts := scm.ListOptions{Page: 1,Size: 30,}statuses, _, err := client.Repositories.ListStatus(ctx, "octocat/Hello-World", "6dcb09b5b57875f334f61aebed695e2e4193db5e", opts)if err != nil {log.Fatal(err)}for _, status := range statuses {log.Println(status.State, status.Target)}}

typeStatusInput

type StatusInput struct {StateStateLabelstringTitlestringDescstringTargetstring}

StatusInput provides the input fields required forcreating or updating commit statuses.

typeTagHook

type TagHook struct {RefReferenceRepoRepositoryActionActionSenderUser}

TagHook represents a tag event, eg create and deletegithub event types.

func (*TagHook)Repository

func (h *TagHook) Repository()Repository

typeToken

type Token struct {TokenstringRefreshstringExpirestime.Time}

Token represents the credentials used to authorizethe requests to access protected resources.

typeTokenKey

type TokenKey struct{}

TokenKey is the key to use with the context.WithValuefunction to associate an Token value with a context.

typeTokenSource

type TokenSource interface {Token(context.Context) (*Token,error)}

TokenSource returns a token.

typeUser

type User struct {IDstringLoginstringNamestringEmailstringAvatarstringCreatedtime.TimeUpdatedtime.Time}

User represents a user account.

Example (Find)
package mainimport ("context""log""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}user, _, err := client.Users.Find(ctx)if err != nil {log.Fatal(err)}log.Println(user.Login)}

Example (FindLogin)
package mainimport ("context""log""github.com/drone/go-scm/scm/driver/github")var ctx context.Contextfunc main() {client, err := github.New("https://api.github.com")if err != nil {log.Fatal(err)}user, _, err := client.Users.FindLogin(ctx, "octocat")if err != nil {log.Fatal(err)}log.Println(user.Login)}

typeUserService

type UserService interface {// Find returns the authenticated user.Find(context.Context) (*User, *Response,error)// FindEmail returns the authenticated user email.FindEmail(context.Context) (string, *Response,error)// FindLogin returns the user account by username.FindLogin(context.Context,string) (*User, *Response,error)// ListEmail returns the user email list.ListEmail(context.Context,ListOptions) ([]*Email, *Response,error)}

UserService provides access to user account resources.

typeVisibilityadded inv1.14.1

type Visibilityint

Visibility defines repository visibility.

const (VisibilityUndefinedVisibility =iotaVisibilityPublicVisibilityInternalVisibilityPrivate)

Role values.

funcConvertVisibilityadded inv1.38.2

func ConvertVisibility(fromstring)Visibility

func (Visibility)Stringadded inv1.14.1

func (vVisibility) String() (sstring)

String returns the string representation of Role.

typeWebhook

type Webhook interface {Repository()Repository}

Webhook defines a webhook for repository events.

Example
package mainimport ("log""net/http""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")func main() {client := github.NewDefault()secret := func(webhook scm.Webhook) (string, error) {return "topsecret", nil}handler := func(w http.ResponseWriter, r *http.Request) {webhook, err := client.Webhooks.Parse(r, secret)if err != nil {http.Error(w, err.Error(), http.StatusBadRequest)return}switch event := webhook.(type) {case *scm.PushHook:log.Println(event.Ref,event.Commit.Sha,event.Commit.Message,event.Repo.Namespace,event.Repo.Name,event.Sender.Login,)case *scm.BranchHook:case *scm.TagHook:case *scm.IssueHook:case *scm.IssueCommentHook:case *scm.PullRequestHook:case *scm.PullRequestCommentHook:case *scm.ReviewCommentHook:}}http.HandleFunc("/hook", handler)http.ListenAndServe(":8000", nil)}

Example (LookupSecret)
package mainimport ("database/sql""log""net/http""github.com/drone/go-scm/scm""github.com/drone/go-scm/scm/driver/github")var db *sql.DBfunc main() {client := github.NewDefault()secret := func(webhook scm.Webhook) (secret string, err error) {stmt := "SELECT secret FROM repos WHERE id = ?"repo := webhook.Repository()err = db.QueryRow(stmt, repo.ID).Scan(&secret)return}handler := func(w http.ResponseWriter, r *http.Request) {webhook, err := client.Webhooks.Parse(r, secret)if err != nil {http.Error(w, err.Error(), http.StatusBadRequest)return}switch event := webhook.(type) {case *scm.PushHook:log.Println(event.Ref,event.Commit.Sha,event.Commit.Message,event.Repo.Namespace,event.Repo.Name,event.Sender.Login,)}}http.HandleFunc("/hook", handler)http.ListenAndServe(":8000", nil)}

typeWebhookService

type WebhookService interface {// Parse returns the parsed the repository webhook payload.Parse(req *http.Request, fnSecretFunc) (Webhook,error)}

WebhookService provides abstract functions forparsing and validating webhooks requests.

Source Files

View all Source files

Directories

PathSynopsis
driver
azure
Package azure implements a azure client.
Package azure implements a azure client.
bitbucket
Package bitbucket implements a Bitbucket Cloud client.
Package bitbucket implements a Bitbucket Cloud client.
bitbucket/integration
Package integration implements a Bitbucket Cloud integration tests.
Package integration implements a Bitbucket Cloud integration tests.
gitea
Package gitea implements a Gitea client.
Package gitea implements a Gitea client.
gitee
Package gitee implements a Gitee client.
Package gitee implements a Gitee client.
github
Package github implements a GitHub client.
Package github implements a GitHub client.
gitlab
Package gitlab implements a GitLab client.
Package gitlab implements a GitLab client.
gogs
Package gogs implements a Gogs client.
Package gogs implements a Gogs client.
stash
Package stash implements a Bitbucket Server client.
Package stash implements a Bitbucket Server client.
Package normalize provides facilities for enriching data structures with missing information.
Package normalize provides facilities for enriching data structures with missing information.
Package transport provides facilities for setting up authenticated http.RoundTripper given credentials and base RoundTripper.
Package transport provides facilities for setting up authenticated http.RoundTripper given credentials and base RoundTripper.
Package traverse provides facilities for traversing and combining the paginated results.
Package traverse provides facilities for traversing and combining the paginated results.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp