scm
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Index¶
- Constants
- Variables
- func ConvertPrivate(from string) bool
- func ExpandRef(name, prefix string) string
- func ExtractPullRequest(ref string) int
- func IsBranch(ref string) bool
- func IsHash(s string) bool
- func IsPullRequest(ref string) bool
- func IsTag(ref string) bool
- func Join(owner, name string) string
- func Split(s string) (owner, name string)
- func TrimRef(ref string) string
- func WithContext(parent context.Context, token *Token) context.Context
- type Action
- type BranchHook
- type BranchListOptions
- type Change
- type Client
- type Comment
- type CommentInput
- type Commit
- type CommitListOptions
- type Content
- type ContentInfo
- type ContentKind
- type ContentParams
- type ContentService
- type CreateBranch
- type DeployHook
- type DeployStatus
- type Driver
- type Email
- type Execution
- type ExecutionStatus
- type GitService
- type Hook
- type HookEvents
- type HookInput
- type Issue
- type IssueCommentHook
- type IssueHook
- type IssueInput
- type IssueListOptions
- type IssueService
- type Label
- type Linker
- type ListOptions
- type Membership
- type Milestone
- type MilestoneInput
- type MilestoneListOptions
- type MilestoneService
- type Organization
- type OrganizationService
- type Page
- type Perm
- type PipelineHook
- type PullRequest
- type PullRequestCommentHook
- type PullRequestHook
- type PullRequestInput
- type PullRequestListOptions
- type PullRequestService
- type PushHook
- type Rate
- type Reference
- type ReferenceInput
- type Release
- type ReleaseHook
- type ReleaseInput
- type ReleaseListOptions
- type ReleaseService
- type RepoListOptions
- type RepoSearchTerm
- type Repository
- type RepositoryService
- type Request
- type Response
- type Review
- type ReviewCommentHook
- type ReviewInput
- type ReviewService
- type Role
- type SecretFunc
- type Signature
- type State
- type Status
- type StatusInput
- type TagHook
- type Token
- type TokenKey
- type TokenSource
- type User
- type UserService
- type Visibility
- type Webhook
- type WebhookService
Examples¶
- Client
- Comment (Create)
- Comment (Find)
- Comment (List)
- Commit (Changes)
- Commit (Find)
- Commit (List)
- Content (Find)
- Hook (Create)
- Hook (Find)
- Hook (List)
- Issue (Close)
- Issue (Find)
- Issue (List)
- Issue (Lock)
- Issue (Unlock)
- Organization (Find)
- Organization (List)
- PullRequest (Changes)
- PullRequest (Close)
- PullRequest (Find)
- PullRequest (List)
- PullRequest (Merge)
- Repository (Find)
- Repository (List)
- Review (Create)
- Review (Find)
- Review (List)
- Status (Create)
- Status (List)
- User (Find)
- User (FindLogin)
- Webhook
- Webhook (LookupSecret)
Constants¶
const EmptyCommit = "0000000000000000000000000000000000000000"EmptyCommit is an empty commit sha.
const SearchTimeFormat = "2006-01-02T15:04:05Z"Variables¶
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"))
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¶
funcConvertPrivate¶added inv1.38.2
funcExpandRef¶
ExpandRef returns name expanded to the fully qualifiedreference path (e.g refs/heads/master).
funcExtractPullRequest¶added inv1.14.1
ExtractPullRequest returns name extraced pull requestnumber from the reference path.
funcIsPullRequest¶added inv1.14.1
IsPullRequest returns true if the reference path pointsto a pull request object.
funcJoin¶
Join joins the repository owner and name segments tocreate a fully qualified repository name.
Types¶
typeAction¶
type Actionint
Action identifies webhook actions.
const (ActionUnknownAction =iotaActionCreateActionUpdateActionDelete// issuesActionOpenActionReopenActionCloseActionLabelActionUnlabel// pull requestsActionSyncActionMergeActionReviewReady// issue commentActionEdit// releaseActionPublishActionUnpublishActionPrereleaseActionReleaseActionSubmittedActionDismissed)
Action values.
func (Action)MarshalJSON¶
MarshalJSON returns the JSON-encoded Action.
func (*Action)UnmarshalJSON¶
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
typeBranchListOptions¶added 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¶
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.
typeComment¶
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¶
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¶
CommitListOptions provides options for querying alist of repository commits.
typeContent¶
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)}typeContentInfo¶added inv1.14.1
type ContentInfo struct {PathstringShastringBlobIDstringKindContentKind}ContentInfo stores the kind of any content in a repository.
typeContentKind¶added inv1.14.1
type ContentKindint
ContentKind defines the kind of a content in a directory.
const (ContentKindUnsupportedContentKind =iotaContentKindFileContentKindDirectoryContentKindSymlinkContentKindGitlink)
ContentKind values.
func (ContentKind)MarshalJSON¶added inv1.21.0
func (kContentKind) MarshalJSON() ([]byte,error)
MarshalJSON returns the JSON-encoded Action.
func (ContentKind)String¶added inv1.14.1
func (kContentKind) String()string
String returns the string representation of ContentKind.
func (*ContentKind)UnmarshalJSON¶added 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.
typeCreateBranch¶added inv1.14.1
type CreateBranch =ReferenceInput
CreateBranch is a type alias for upstream projectsthat use the previous CreateBranch type name.
typeDeployHook¶added inv1.0.8
type DeployHook struct {Data interface{}DescstringNumberint64RefReferenceRepoRepositorySenderUserTargetstringTargetURLstringTaskstring}DeployHook represents a deployment event. This iscurrently a GitHub-specific event type.
func (*DeployHook)Repository¶added inv1.0.8
func (h *DeployHook) Repository()Repository
typeDeployStatus¶added inv1.14.1
type DeployStatus struct {Numberint64StateStateDescstringTargetstringEnvironmentstringEnvironmentURLstring}DeployStatus represents a deployment status.
typeDriver¶
type Driverint
Driver identifies source code management driver.
typeExecutionStatus¶added inv1.40.0
type ExecutionStatusint
Status defines an enum for execution status
const (StatusUnknownExecutionStatus =iotaStatusPendingStatusRunningStatusSuccessStatusFailedStatusCanceled)
funcConvertExecutionStatus¶added inv1.40.0
func ConvertExecutionStatus(fromstring)ExecutionStatus
func (ExecutionStatus)MarshalJSON¶added inv1.40.0
func (kExecutionStatus) MarshalJSON() ([]byte,error)
MarshalJSON returns the JSON-encoded Action.
func (ExecutionStatus)String¶added inv1.40.0
func (kExecutionStatus) String()string
String returns the string representation of ExecutionStatus.
func (*ExecutionStatus)UnmarshalJSON¶added 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¶
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¶
IssueInput provides the input fields required forcreating or updating an issue.
typeIssueListOptions¶
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.
typeLinker¶added 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¶
ListOptions specifies optional paginationparameters.
typeMembership¶added inv1.14.1
Membership represents an organization membership.
typeMilestone¶added inv1.16.0
type Milestone struct {NumberintIDintTitlestringDescriptionstringLinkstringStatestringDueDatetime.Time}Milestone the milestone
typeMilestoneInput¶added inv1.16.0
MilestoneInput contains the information needed to create a milestone
typeMilestoneListOptions¶added inv1.16.0
MilestoneListOptions provides options for querying a list of repository milestones.
typeMilestoneService¶added 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¶
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.
typePipelineHook¶added inv1.40.0
type PipelineHook struct {CommitCommitExecutionExecutionPullRequestPullRequestRepoRepositorySenderUser}PipelineHook
func (*PipelineHook)Repository¶added 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
typePullRequestInput¶added inv1.14.1
PullRequestInput provides the input fields required for creating a pull request.
typePullRequestListOptions¶
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
typeReferenceInput¶added inv1.28.0
ReferenceInput provides a SHA for creating a reference.
typeRelease¶added inv1.16.0
type Release struct {IDintTitlestringDescriptionstringLinkstringTagstringCommitishstringDraftboolPrereleaseboolCreatedtime.TimePublishedtime.Time}Release the release
typeReleaseHook¶added inv1.28.0
type ReleaseHook struct {ActionActionReleaseReleaseRepoRepositorySenderUser}ReleaseHook represents a release event. This iscurrently a GitHub-specific event type.
func (*ReleaseHook)Repository¶added inv1.28.0
func (h *ReleaseHook) Repository()Repository
typeReleaseInput¶added inv1.16.0
type ReleaseInput struct {TitlestringDescriptionstringTagstringCommitishstringDraftboolPrereleasebool}ReleaseInput contains the information needed to create a release
typeReleaseListOptions¶added inv1.16.0
ReleaseListOptions provides options for querying a list of repository releases.
typeReleaseService¶added 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
typeRepoListOptions¶added inv1.30.0
type RepoListOptions struct {ListOptionsRepoSearchTerm}RepoListOptions specifies optional repo search term and paginationparameters.
typeRepoSearchTerm¶added inv1.30.0
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.
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¶
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.
typeSecretFunc¶
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.
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¶
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¶
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¶
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.
typeVisibility¶added inv1.14.1
type Visibilityint
Visibility defines repository visibility.
const (VisibilityUndefinedVisibility =iotaVisibilityPublicVisibilityInternalVisibilityPrivate)
Role values.
funcConvertVisibility¶added inv1.38.2
func ConvertVisibility(fromstring)Visibility
func (Visibility)String¶added 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¶
Directories¶
| Path | Synopsis |
|---|---|
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. |