Documentation ¶
Index ¶
- Constants
- Variables
- func ExpandRef(name, prefix string) string
- func IsScmNotFound(err error) bool
- func IsTag(ref string) bool
- func IsUnknownWebhook(err error) bool
- func Join(owner, name string) string
- func Split(s string) (owner, name string)
- func TrimRef(ref string) string
- func URLJoin(paths ...string) string
- func WithContext(parent context.Context, token *Token) context.Context
- type Account
- type Action
- type AppService
- type BranchHook
- type Change
- type CheckRunHook
- type CheckSuiteHook
- type Client
- type CombinedStatus
- type Comment
- type CommentInput
- type Commit
- type CommitListOptions
- type CommitService
- type CommitStatus
- type CommitStatusAuthor
- type CommitStatusUpdateOptions
- type CommitTree
- type Content
- type ContentParams
- type ContentService
- type DeployHook
- type DeployStatus
- type Deployment
- type DeploymentInput
- type DeploymentService
- type DeploymentStatus
- type DeploymentStatusHook
- type DeploymentStatusInput
- type Driver
- type Email
- type ExtraUsers
- type FileEntry
- type ForkHook
- type GitService
- type GraphQLService
- type Hook
- type HookEvents
- type HookInput
- type Installation
- type InstallationHook
- type InstallationRef
- type InstallationRepositoryHook
- type InstallationToken
- type Invitation
- type Issue
- type IssueCommentHook
- type IssueHook
- type IssueInput
- type IssueListOptions
- type IssueService
- type Label
- type LabelHook
- type ListOptions
- type ListedIssueEvent
- type Membership
- type MergeableState
- type Milestone
- type MilestoneInput
- type MilestoneListOptions
- type MilestoneService
- type MissingHeader
- type MissingUsers
- type Organization
- type OrganizationInput
- type OrganizationPendingInvite
- type OrganizationService
- type Page
- type Perm
- type Permissions
- type PingHook
- type PullRequest
- type PullRequestBranch
- type PullRequestCommentHook
- type PullRequestHook
- type PullRequestHookBranch
- type PullRequestHookBranchFrom
- type PullRequestHookChanges
- type PullRequestInput
- type PullRequestListOptions
- type PullRequestMergeOptions
- type PullRequestService
- type PushCommit
- type PushHook
- type Rate
- type Reference
- type ReferenceInput
- type Release
- type ReleaseHook
- type ReleaseInput
- type ReleaseListOptions
- type ReleaseService
- type Repository
- type RepositoryHook
- type RepositoryInput
- type RepositoryService
- type Request
- type Response
- type Review
- type ReviewComment
- type ReviewCommentHook
- type ReviewCommentInput
- type ReviewHook
- type ReviewInput
- type ReviewService
- type ReviewSubmitInput
- type SearchIssue
- type SearchOptions
- type SecretFunc
- type Signature
- type StarHook
- type State
- type StateCannotBeChanged
- type Status
- type StatusHook
- type StatusInput
- type TagHook
- type Team
- type TeamMember
- type Token
- type TokenKey
- type TokenSource
- type UnknownWebhook
- type User
- type UserService
- type UserToken
- type WatchHook
- type Webhook
- type WebhookKind
- type WebhookService
- type WebhookWrapper
Examples ¶
- Client
- Comment (Create)
- Comment (Find)
- Comment (List)
- Commit (Changes)
- Commit (Find)
- Commit (List)
- Commit (ListOnBranch)
- 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)
- Reference (FindBranch)
- Reference (FindTag)
- Reference (ListBranch)
- Reference (ListTag)
- Repository (Find)
- Repository (List)
- Review (Create)
- Review (Find)
- Review (List)
- Status (Create)
- Status (List)
- User (Find)
- User (FindLogin)
- Webhook
- Webhook (LookupSecret)
Constants ¶
const ( // NoPermission means the user has no permission to access the repository NoPermission = "none" // ReadPermission means the user has read access to the repository ReadPermission = "read" // WritePermission means the user has write/push access to the repository WritePermission = "write" // AdminPermission means the user has full admin access to the repository AdminPermission = "admin" )
const ( // ReviewStateApproved is used for approved reviews ReviewStateApproved string = "APPROVED" // ReviewStateChangesRequested is used for reviews with changes requested ReviewStateChangesRequested string = "CHANGES_REQUESTED" // ReviewStateCommented is used for reviews with comments ReviewStateCommented string = "COMMENTED" // ReviewStateDismissed is used for reviews that have been dismissed ReviewStateDismissed string = "DISMISSED" // ReviewStatePending is used for reviews that are awaiting response ReviewStatePending string = "PENDING" )
const EmptyCommit = "0000000000000000000000000000000000000000"
EmptyCommit is an empty commit sha.
const SearchTimeFormat = "2006-01-02T15:04:05Z"
SearchTimeFormat is a time.Time format string for ISO8601 which is the format that GitHub requires for times specified as part of a search query.
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") // ErrForbidden indicates the user does not have access to // the resource, this is similar to 401, but in this case, // re-authenticating will make no difference. ErrForbidden = errors.New("Forbidden") )
var ( // ErrSignatureInvalid is returned when the webhook // signature is invalid or cannot be calculated. ErrSignatureInvalid = errors.New("invalid webhook signature") )
var ( // ErrUnknownEvent is returned when the webhook event // is not recognized by the system. ErrUnknownEvent = errors.New("unknown webhook event") )
Functions ¶
func ExpandRef ¶
ExpandRef returns name expanded to the fully qualified reference path (e.g refs/heads/master).
func IsScmNotFound ¶ added in v1.6.18
IsScmNotFound returns true if the resource is not found
func IsUnknownWebhook ¶
IsUnknownWebhook returns true if the error is an unknown webhook
func Join ¶
Join joins the repository owner and name segments to create a fully qualified repository name.
Types ¶
type Action ¶
type Action int
Action identifies webhook actions.
const ( ActionCreate Action = iota + 1 ActionUpdate ActionDelete // issues ActionOpen ActionReopen ActionClose ActionLabel ActionUnlabel // pull requests ActionSync ActionMerge ActionAssigned ActionUnassigned ActionReviewRequested ActionReviewRequestRemoved ActionReadyForReview ActionConvertedToDraft // reviews ActionEdited ActionSubmitted ActionDismissed // check run / check suite ActionCompleted )
Action values.
func (Action) MarshalJSON ¶
MarshalJSON returns the JSON-encoded Action.
func (*Action) UnmarshalJSON ¶
UnmarshalJSON unmarshales the JSON-encoded Action.
type AppService ¶ added in v1.5.43
type AppService interface { CreateInstallationToken(ctx context.Context, id int64) (*InstallationToken, *Response, error) GetRepositoryInstallation(ctx context.Context, fullName string) (*Installation, *Response, error) GetOrganisationInstallation(ctx context.Context, organisation string) (*Installation, *Response, error) GetUserInstallation(ctx context.Context, user string) (*Installation, *Response, error) }
AppService for GitHub App support
type BranchHook ¶
type BranchHook struct { Ref Reference Repo Repository Action Action Sender User Installation *InstallationRef }
BranchHook represents a branch or tag event, eg create and delete github event types.
func (*BranchHook) GetInstallationRef ¶ added in v1.5.44
func (h *BranchHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*BranchHook) Kind ¶ added in v1.5.47
func (h *BranchHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*BranchHook) Repository ¶
func (h *BranchHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type Change ¶
type Change struct { Path string PreviousPath string Added bool Renamed bool Deleted bool Patch string Additions int Deletions int Changes int BlobURL string Sha string }
Change represents a changed file.
type CheckRunHook ¶ added in v1.5.59
type CheckRunHook struct { Action Action Repo Repository Sender User Label Label Installation *InstallationRef }
CheckRunHook represents a check run event
func (*CheckRunHook) GetInstallationRef ¶ added in v1.5.59
func (h *CheckRunHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*CheckRunHook) Kind ¶ added in v1.5.59
func (h *CheckRunHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*CheckRunHook) Repository ¶ added in v1.5.59
func (h *CheckRunHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type CheckSuiteHook ¶ added in v1.5.59
type CheckSuiteHook struct { Action Action Repo Repository Sender User Label Label Installation *InstallationRef }
CheckSuiteHook represents a check suite event
func (*CheckSuiteHook) GetInstallationRef ¶ added in v1.5.59
func (h *CheckSuiteHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*CheckSuiteHook) Kind ¶ added in v1.5.59
func (h *CheckSuiteHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*CheckSuiteHook) Repository ¶ added in v1.5.59
func (h *CheckSuiteHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type Client ¶
type Client struct { // HTTP client used to communicate with the API. Client *http.Client // Base URL for API requests. BaseURL *url.URL GraphQLURL *url.URL // Username is the optional user name for the client Username string // Services used for communicating with the API. Driver Driver Apps AppService Contents ContentService Deployments DeploymentService Git GitService GraphQL GraphQLService Organizations OrganizationService Issues IssueService Milestones MilestoneService Releases ReleaseService PullRequests PullRequestService Repositories RepositoryService Reviews ReviewService Users UserService Webhooks WebhookService Commits CommitService // 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 control system API.
Example ¶
package main import ( "log" "net/http" "github.com/jenkins-x/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{} }
Output:
func (*Client) Do ¶
Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.
type CombinedStatus ¶
CombinedStatus is the latest statuses for a ref.
type Comment ¶
type Comment struct { ID int Body string Author User Link string Version int Created time.Time Updated time.Time }
Comment represents a comment.
Example (Create) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) }
Output:
Example (Find) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) }
Output:
Example (List) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) } }
Output:
type CommentInput ¶
type CommentInput struct {
Body string
}
CommentInput provides the input fields required for creating an issue comment.
type Commit ¶
type Commit struct { Sha string Message string Tree CommitTree Author Signature Committer Signature Link string }
Commit represents a repository commit.
Example (Changes) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) } }
Output:
Example (Find) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) }
Output:
Example (List) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) } }
Output:
Example (ListOnBranch) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func main() { client, err := github.New("https://api.github.com") if err != nil { log.Fatal(err) } opts := scm.CommitListOptions{ Sha: "test", 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) } }
Output:
type CommitListOptions ¶
CommitListOptions provides options for querying a list of repository commits.
type CommitService ¶ added in v1.9.2
type CommitService interface { UpdateCommitStatus(ctx context.Context, repo string, sha string, options *CommitStatusUpdateOptions) (*CommitStatus, *Response, error) }
CommitService commit interface
type CommitStatus ¶ added in v1.9.2
type CommitStatus struct { Status string Created time.Time Started time.Time Name string AllowFailure bool Author CommitStatusAuthor Description string Sha string TargetURL string Finished time.Time ID int Ref string Coverage float64 }
CommitStatus for commit status
type CommitStatusAuthor ¶ added in v1.9.2
type CommitStatusAuthor struct { Username string State string WebURL string AvatarURL string ID int Name string }
CommitStatusAuthor for commit author
type CommitStatusUpdateOptions ¶ added in v1.9.2
type CommitStatusUpdateOptions struct { ID string Sha string State string Ref string Name string TargetURL string Description string Coverage float64 PipelineID *int }
CommitStatusUpdateOptions for update options
type CommitTree ¶
CommitTree represents a commit tree
type Content ¶
Content stores the contents of a repository file.
Example (Find) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) }
Output:
type ContentParams ¶
type ContentParams struct { Ref string Branch string Message string Data []byte Sha string BlobID string Signature Signature }
ContentParams provide parameters for creating and updating repository content.
type ContentService ¶
type ContentService interface { // Find returns the repository file content by path. Find(ctx context.Context, repo, path, ref string) (*Content, *Response, error) // List the files or directories at the given path List(ctx context.Context, repo, path, ref string) ([]*FileEntry, *Response, error) // Create creates a new repository file. Create(ctx context.Context, repo, path string, params *ContentParams) (*Response, error) // Update updates a repository file. Update(ctx context.Context, repo, path string, params *ContentParams) (*Response, error) // Delete deletes a repository file. Delete(ctx context.Context, repo, path string, params *ContentParams) (*Response, error) }
ContentService provides access to repository content.
type DeployHook ¶
type DeployHook struct { Deployment Deployment Action Action Ref Reference Repo Repository Sender User Label Label Installation *InstallationRef }
DeployHook represents a deployment event. This is currently a GitHub-specific event type.
func (*DeployHook) GetInstallationRef ¶ added in v1.5.44
func (h *DeployHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*DeployHook) Kind ¶ added in v1.5.47
func (h *DeployHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*DeployHook) Repository ¶
func (h *DeployHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type DeployStatus ¶ added in v1.11.22
type DeployStatus struct { Number int64 State State Desc string Target string Environment string EnvironmentURL string }
DeployStatus represents a deployment status.
type Deployment ¶ added in v1.5.76
type Deployment struct { ID string Namespace string Name string Link string Sha string Ref string Task string FullName string Description string OriginalEnvironment string Environment string RepositoryLink string StatusLink string Author *User Created time.Time Updated time.Time TransientEnvironment bool ProductionEnvironment bool Payload interface{} }
Deployment represents a request to deploy a version/ref/sha in some environment
type DeploymentInput ¶ added in v1.5.76
type DeploymentInput struct { Ref string Task string Payload string Environment string Description string RequiredContexts []string AutoMerge bool TransientEnvironment bool ProductionEnvironment bool }
DeploymentInput the input to create a new deployment
type DeploymentService ¶ added in v1.5.76
type DeploymentService interface { // Find find a deployment by id. Find(ctx context.Context, repoFullName string, deploymentID string) (*Deployment, *Response, error) // List returns a list of deployments. List(ctx context.Context, repoFullName string, opts *ListOptions) ([]*Deployment, *Response, error) // Create creates a new deployment. Create(ctx context.Context, repoFullName string, deployment *DeploymentInput) (*Deployment, *Response, error) // Delete deletes a deployment. Delete(ctx context.Context, repoFullName string, deploymentID string) (*Response, error) // FindStatus find a deployment status by id. FindStatus(ctx context.Context, repoFullName string, deploymentID string, statusID string) (*DeploymentStatus, *Response, error) // List returns a list of deployments. ListStatus(ctx context.Context, repoFullName string, deploymentID string, options *ListOptions) ([]*DeploymentStatus, *Response, error) // Create creates a new deployment. CreateStatus(ctx context.Context, repoFullName string, deploymentID string, deployment *DeploymentStatusInput) (*DeploymentStatus, *Response, error) }
DeploymentService a service for working with deployments and deployment services
type DeploymentStatus ¶ added in v1.5.76
type DeploymentStatus struct { ID string State string Author *User Description string Environment string DeploymentLink string EnvironmentLink string LogLink string RepositoryLink string TargetLink string Created time.Time Updated time.Time }
DeploymentStatus represents the status of a deployment
type DeploymentStatusHook ¶ added in v1.5.59
type DeploymentStatusHook struct { Deployment Deployment DeploymentStatus DeploymentStatus Action Action Repo Repository Sender User Label Label Installation *InstallationRef }
DeploymentStatusHook represents a deployment status event. This is currently a GitHub-specific event type.
func (*DeploymentStatusHook) GetInstallationRef ¶ added in v1.5.59
func (h *DeploymentStatusHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*DeploymentStatusHook) Kind ¶ added in v1.5.59
func (h *DeploymentStatusHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*DeploymentStatusHook) Repository ¶ added in v1.5.59
func (h *DeploymentStatusHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type DeploymentStatusInput ¶ added in v1.5.76
type DeploymentStatusInput struct { State string TargetLink string LogLink string Description string Environment string EnvironmentLink string AutoInactive bool }
DeploymentStatusInput the input to creating a status of a deployment
type Driver ¶
type Driver int
Driver identifies source code management driver.
type ExtraUsers ¶
ExtraUsers is an error specifying the users that could not be unassigned.
func (ExtraUsers) Error ¶
func (e ExtraUsers) Error() string
type ForkHook ¶ added in v1.5.65
type ForkHook struct { Repo Repository Sender User Installation *InstallationRef }
ForkHook represents a fork event
func (*ForkHook) GetInstallationRef ¶ added in v1.5.65
func (h *ForkHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*ForkHook) Kind ¶ added in v1.5.65
func (h *ForkHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*ForkHook) Repository ¶ added in v1.5.65
func (h *ForkHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type GitService ¶
type GitService interface { // FindBranch finds a git branch by name. FindBranch(ctx context.Context, repo, name string) (*Reference, *Response, error) // FindCommit finds a git commit by ref. FindCommit(ctx context.Context, repo, ref string) (*Commit, *Response, error) // FindTag finds a git tag by name. FindTag(ctx context.Context, repo, name string) (*Reference, *Response, error) // ListBranches returns a list of git branches. ListBranches(ctx context.Context, repo string, opts *ListOptions) ([]*Reference, *Response, error) // ListCommits returns a list of git commits. ListCommits(ctx context.Context, repo string, opts CommitListOptions) ([]*Commit, *Response, error) // ListChanges returns the changeset between a commit and its parent. ListChanges(ctx context.Context, repo, ref string, opts *ListOptions) ([]*Change, *Response, error) // CompareCommits returns the changeset between two commits. CompareCommits(ctx context.Context, repo, ref1, ref2 string, opts *ListOptions) ([]*Change, *Response, error) // ListTags returns a list of git tags. ListTags(ctx context.Context, repo string, opts *ListOptions) ([]*Reference, *Response, error) // FindRef returns the SHA of the given ref, such as "heads/master". FindRef(ctx context.Context, repo, ref string) (string, *Response, error) // DeleteRef deletes the given ref DeleteRef(ctx context.Context, repo, ref string) (*Response, error) // CreateRef creates a new ref CreateRef(ctx context.Context, repo, ref, sha string) (*Reference, *Response, error) }
GitService provides access to git resources.
type GraphQLService ¶ added in v1.5.34
type GraphQLService interface {
Query(ctx context.Context, q interface{}, vars map[string]interface{}) error
}
GraphQLService the API to performing GraphQL queries
type Hook ¶
type Hook struct { ID string Name string Target string Events []string Active bool SkipVerify bool }
Hook represents a repository hook.
Example (Create) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) } }
Output:
Example (Find) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) }
Output:
Example (List) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) } }
Output:
type HookEvents ¶
type HookEvents struct { Branch bool Deployment bool DeploymentStatus bool Issue bool IssueComment bool PullRequest bool PullRequestComment bool Push bool Release bool Review bool ReviewComment bool Tag bool }
HookEvents represents supported hook events.
type HookInput ¶
type HookInput struct { Name string Target string Secret string Events HookEvents SkipVerify bool // 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 for creating or updating repository webhooks.
type Installation ¶ added in v1.5.43
type Installation struct { ID int64 AppID int64 TargetID int64 TargetType string RepositorySelection string Account Account AccessTokensLink string RepositoriesURL string Link string Events []string CreatedAt *time.Time UpdatedAt *time.Time }
Installation represents a GitHub app install
type InstallationHook ¶ added in v1.5.43
type InstallationHook struct { Action Action Repos []*Repository Sender User Installation *Installation }
InstallationHook represents an installation of a GitHub App
func (*InstallationHook) GetInstallationRef ¶ added in v1.5.44
func (h *InstallationHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*InstallationHook) Kind ¶ added in v1.5.47
func (h *InstallationHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*InstallationHook) Repository ¶ added in v1.5.43
func (h *InstallationHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type InstallationRef ¶ added in v1.5.44
InstallationRef references a GitHub app install on a webhook
type InstallationRepositoryHook ¶ added in v1.5.65
type InstallationRepositoryHook struct { Action Action RepositorySelection string ReposAdded []*Repository ReposRemoved []*Repository Sender User Installation *Installation }
InstallationRepositoryHook represents an installation of a GitHub App
func (*InstallationRepositoryHook) GetInstallationRef ¶ added in v1.5.65
func (h *InstallationRepositoryHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*InstallationRepositoryHook) Kind ¶ added in v1.5.65
func (h *InstallationRepositoryHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*InstallationRepositoryHook) Repository ¶ added in v1.5.65
func (h *InstallationRepositoryHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type InstallationToken ¶ added in v1.5.43
InstallationToken is the token used for interacting with the app
type Invitation ¶ added in v1.5.150
type Invitation struct { ID int64 Repo *Repository Invitee *User Inviter *User Permissions string Link string Created time.Time }
Invitation represents a repo invitation
type Issue ¶
type Issue struct { Number int Title string Body string Link string State string Labels []string Closed bool Locked bool Author User Assignees []User ClosedBy *User PullRequest *PullRequest Created time.Time Updated time.Time }
Issue represents an issue.
Example (Close) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) } }
Output:
Example (Find) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) }
Output:
Example (List) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) } }
Output:
Example (Lock) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) } }
Output:
Example (Unlock) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) } }
Output:
type IssueCommentHook ¶
type IssueCommentHook struct { Action Action Repo Repository Issue Issue Comment Comment Sender User GUID string Installation *InstallationRef }
IssueCommentHook represents an issue comment event, eg issue_comment.
func (*IssueCommentHook) GetInstallationRef ¶ added in v1.5.44
func (h *IssueCommentHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*IssueCommentHook) Kind ¶ added in v1.5.47
func (h *IssueCommentHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*IssueCommentHook) Repository ¶
func (h *IssueCommentHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type IssueHook ¶
type IssueHook struct { Action Action Repo Repository Issue Issue Sender User Installation *InstallationRef }
IssueHook represents an issue event, eg issues.
func (*IssueHook) GetInstallationRef ¶ added in v1.5.44
func (h *IssueHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*IssueHook) Kind ¶ added in v1.5.47
func (h *IssueHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*IssueHook) Repository ¶
func (h *IssueHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type IssueInput ¶
IssueInput provides the input fields required for creating or updating an issue.
type IssueListOptions ¶
IssueListOptions provides options for querying a list of repository issues.
type IssueService ¶
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) // Find returns the issue by number. Search(context.Context, SearchOptions) ([]*SearchIssue, *Response, error) // ListComments returns the issue comment list. ListComments(context.Context, string, int, *ListOptions) ([]*Comment, *Response, error) // ListLabels returns the labels on an issue ListLabels(context.Context, string, int, *ListOptions) ([]*Label, *Response, error) // ListEvents returns the events creating and removing the labels on an issue ListEvents(context.Context, string, int, *ListOptions) ([]*ListedIssueEvent, *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) // EditComment edits an existing issue comment. EditComment(context.Context, string, int, int, *CommentInput) (*Comment, *Response, error) // Close closes an issue. Close(context.Context, string, int) (*Response, error) // Reopen reopens a closed issue. Reopen(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) // AddLabel adds a label to an issue AddLabel(ctx context.Context, repo string, number int, label string) (*Response, error) // DeleteLabel deletes a label from an issue DeleteLabel(ctx context.Context, repo string, number int, label string) (*Response, error) // AssignIssue assigns one or more users to an issue AssignIssue(ctx context.Context, repo string, number int, logins []string) (*Response, error) // UnassignIssue removes the assignment of ne or more users on an issue UnassignIssue(ctx context.Context, repo string, number int, logins []string) (*Response, error) // SetMilestone adds a milestone to an issue SetMilestone(ctx context.Context, repo string, issueID int, number int) (*Response, error) // ClearMilestone removes the milestone from an issue ClearMilestone(ctx context.Context, repo string, id int) (*Response, error) }
IssueService provides access to issue resources.
type LabelHook ¶ added in v1.5.59
type LabelHook struct { Action Action Repo Repository Sender User Label Label Installation *InstallationRef }
LabelHook represents a label event
func (*LabelHook) GetInstallationRef ¶ added in v1.5.59
func (h *LabelHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*LabelHook) Kind ¶ added in v1.5.59
func (h *LabelHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*LabelHook) Repository ¶ added in v1.5.59
func (h *LabelHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type ListOptions ¶
ListOptions specifies optional pagination parameters.
type ListedIssueEvent ¶
ListedIssueEvent for listing events on an issue
type Membership ¶ added in v1.5.177
Membership describes the membership a user has to an organisation
type MergeableState ¶ added in v1.5.34
type MergeableState string
MergeableState represents whether the PR can be merged
const ( // MergeableStateMergeable The pull request can be merged. MergeableStateMergeable MergeableState = "mergeable" // MergeableStateConflicting The pull request cannot be merged due to merge conflicts. MergeableStateConflicting MergeableState = "conflicting" // MergeableStateUnknown The mergeability of the pull request is still being calculated. MergeableStateUnknown MergeableState = "" )
Action values.
func ToMergeableState ¶ added in v1.5.34
func ToMergeableState(text string) MergeableState
ToMergeableState converts the given string to a mergeable state
func (MergeableState) String ¶ added in v1.5.34
func (s MergeableState) String() string
String returns the string representation
type Milestone ¶ added in v1.5.34
type Milestone struct { Number int ID int Title string Description string Link string State string DueDate *time.Time }
Milestone the milestone
type MilestoneInput ¶ added in v1.5.165
MilestoneInput contains the information needed to create a milestone
type MilestoneListOptions ¶ added in v1.5.165
MilestoneListOptions provides options for querying a list of repository milestones.
type MilestoneService ¶ added in v1.5.165
type MilestoneService interface { // Find returns the milestone for the given number in the given repository Find(context.Context, string, int) (*Milestone, *Response, error) // List returns a list of milestones in the given repository List(context.Context, string, MilestoneListOptions) ([]*Milestone, *Response, error) // Create creates a milestone in the given repository Create(context.Context, string, *MilestoneInput) (*Milestone, *Response, error) // Update updates a milestone in the given repository Update(context.Context, string, int, *MilestoneInput) (*Milestone, *Response, error) // Delete deletes a milestone in the given repository Delete(context.Context, string, int) (*Response, error) }
MilestoneService provides access to creating, listing, updating, and deleting milestones
type MissingHeader ¶
type MissingHeader struct {
Header string
}
MissingHeader if the webhook has a missing header
func (MissingHeader) Error ¶
func (e MissingHeader) Error() string
type MissingUsers ¶
MissingUsers is an error specifying the users that could not be unassigned.
func (MissingUsers) Error ¶
func (m MissingUsers) Error() string
type Organization ¶
type Organization struct { ID int Name string Avatar string Permissions Permissions }
Organization represents an organization account.
Example (Find) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) }
Output:
Example (List) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) } }
Output:
type OrganizationInput ¶ added in v1.5.174
OrganizationInput provides the input fields required for creating a new organization.
type OrganizationPendingInvite ¶ added in v1.5.176
OrganizationPendingInvite represents a pending invite to an organisation
type OrganizationService ¶
type OrganizationService interface { // Find returns the organization by name. Find(context.Context, string) (*Organization, *Response, error) // Create creates an organization. Create(context.Context, *OrganizationInput) (*Organization, *Response, error) // Delete deletes an organization. Delete(context.Context, string) (*Response, error) // List returns the user organization list. List(context.Context, *ListOptions) ([]*Organization, *Response, error) // ListTeams returns the user organization list. ListTeams(ctx context.Context, org string, ops *ListOptions) ([]*Team, *Response, error) // IsMember returns true if the user is a member of the organization IsMember(ctx context.Context, org string, user string) (bool, *Response, error) // IsAdmin returns true if the user is an admin of the organization IsAdmin(ctx context.Context, org string, user string) (bool, *Response, error) // ListTeamMembers lists the members of a team with a given role ListTeamMembers(ctx context.Context, id int, role string, ops *ListOptions) ([]*TeamMember, *Response, error) // ListOrgMembers lists the members of the organization ListOrgMembers(ctx context.Context, org string, ops *ListOptions) ([]*TeamMember, *Response, error) // ListPendingInvitations lists the pending invitations for an organisation ListPendingInvitations(ctx context.Context, org string, ops *ListOptions) ([]*OrganizationPendingInvite, *Response, error) // AcceptPendingInvitation accepts a pending invitation for an organisation AcceptOrganizationInvitation(ctx context.Context, org string) (*Response, error) // ListMemberships lists organisation memberships for the authenticated user ListMemberships(ctx context.Context, opts *ListOptions) ([]*Membership, *Response, error) }
OrganizationService provides access to organization resources.
type Permissions ¶ added in v1.5.80
type Permissions struct { MembersCreatePrivate bool MembersCreatePublic bool MembersCreateInternal bool }
Permissions represents the possible permissions a user can have on an org
type PingHook ¶ added in v1.5.45
type PingHook struct { Repo Repository Sender User Installation *InstallationRef GUID string }
PingHook a ping webhook.
func (*PingHook) GetInstallationRef ¶ added in v1.5.45
func (h *PingHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*PingHook) Kind ¶ added in v1.5.47
func (h *PingHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*PingHook) Repository ¶ added in v1.5.45
func (h *PingHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type PullRequest ¶
type PullRequest struct { Number int Title string Body string Labels []*Label Sha string Ref string Source string Target string Base PullRequestBranch Head PullRequestBranch Fork string State string Closed bool Draft bool Merged bool Mergeable bool Rebaseable bool MergeableState MergeableState MergeSha string Author User Assignees []User Reviewers []User Milestone Milestone Created time.Time Updated time.Time // Link links to the main pull request page Link string // DiffLink links to the diff report of a pull request DiffLink string }
PullRequest represents a repository pull request.
Example (Changes) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) } }
Output:
Example (Close) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) } }
Output:
Example (Find) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) }
Output:
Example (List) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) } }
Output:
Example (Merge) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func main() { client, err := github.New("https://api.github.com") if err != nil { log.Fatal(err) } _, err = client.PullRequests.Merge(ctx, "octocat/Hello-World", 1, nil) if err != nil { log.Fatal(err) } }
Output:
func (*PullRequest) Repository ¶ added in v1.5.34
func (pr *PullRequest) Repository() Repository
Repository returns the base repository where the PR will merge to
type PullRequestBranch ¶
type PullRequestBranch struct { Ref string Sha string Repo Repository }
PullRequestBranch contains information about a particular branch in a PR.
type PullRequestCommentHook ¶
type PullRequestCommentHook struct { Action Action Repo Repository PullRequest PullRequest Comment Comment Sender User GUID string Installation *InstallationRef }
PullRequestCommentHook represents an pull request comment event, eg pull_request_comment.
func (*PullRequestCommentHook) GetInstallationRef ¶ added in v1.5.44
func (h *PullRequestCommentHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*PullRequestCommentHook) Kind ¶ added in v1.5.47
func (h *PullRequestCommentHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*PullRequestCommentHook) Repository ¶
func (h *PullRequestCommentHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type PullRequestHook ¶
type PullRequestHook struct { Action Action Repo Repository Label Label PullRequest PullRequest Sender User Changes PullRequestHookChanges GUID string Installation *InstallationRef }
PullRequestHook represents an pull request event, eg pull_request.
func (*PullRequestHook) GetInstallationRef ¶ added in v1.5.44
func (h *PullRequestHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*PullRequestHook) Kind ¶ added in v1.5.47
func (h *PullRequestHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*PullRequestHook) Repository ¶
func (h *PullRequestHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type PullRequestHookBranch ¶
type PullRequestHookBranch struct { Ref PullRequestHookBranchFrom Sha PullRequestHookBranchFrom Repo Repository }
PullRequestHookBranch represents a branch in a PR
type PullRequestHookBranchFrom ¶
type PullRequestHookBranchFrom struct {
From string
}
PullRequestHookBranchFrom represents the branch or ref a PR is from
type PullRequestHookChanges ¶
type PullRequestHookChanges struct {
Base PullRequestHookBranch
}
PullRequestHookChanges represents the changes in a PR
type PullRequestInput ¶ added in v1.5.71
PullRequestInput provides the input needed to create or update a PR.
type PullRequestListOptions ¶
type PullRequestListOptions struct { Page int Size int Open bool Closed bool Labels []string UpdatedAfter *time.Time UpdatedBefore *time.Time CreatedAfter *time.Time CreatedBefore *time.Time }
PullRequestListOptions provides options for querying a list of repository merge requests.
type PullRequestMergeOptions ¶ added in v1.5.95
type PullRequestMergeOptions struct { CommitTitle string // Extra detail to append to automatic commit message. (Optional.) SHA string // SHA that pull request head must match to allow merge. (Optional.) // The merge method to use. Possible values include: "merge", "squash", and "rebase" with the default being merge. (Optional.) MergeMethod string // Merge automatically once the pipeline completes. (Supported only in gitlab) MergeWhenPipelineSucceeds bool // Signals to the SCM to remove the source branch during merge DeleteSourceBranch bool }
PullRequestMergeOptions lets you define how a pull request will be merged.
type PullRequestService ¶
type PullRequestService interface { // Find returns the repository pull request by number. Find(context.Context, string, int) (*PullRequest, *Response, error) // Update modifies an existing pull request. Update(context.Context, string, int, *PullRequestInput) (*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) // ListCommits returns the pull request commits. ListCommits(context.Context, string, int, *ListOptions) ([]*Commit, *Response, error) // ListComments returns the pull request comment list. ListComments(context.Context, string, int, *ListOptions) ([]*Comment, *Response, error) // ListLabels returns the labels on a pull request ListLabels(context.Context, string, int, *ListOptions) ([]*Label, *Response, error) // ListEvents returns the events creating and removing the labels on an pull request ListEvents(context.Context, string, int, *ListOptions) ([]*ListedIssueEvent, *Response, error) // Merge merges the repository pull request. Merge(context.Context, string, int, *PullRequestMergeOptions) (*Response, error) // Close closes the repository pull request. Close(context.Context, string, int) (*Response, error) // Reopen reopens a closed repository pull request. Reopen(context.Context, string, int) (*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) // EditComment edits an existing pull request comment. EditComment(context.Context, string, int, int, *CommentInput) (*Comment, *Response, error) // AddLabel adds a label to a pull request. AddLabel(ctx context.Context, repo string, number int, label string) (*Response, error) // DeleteLabel deletes a label from a pull request DeleteLabel(ctx context.Context, repo string, number int, label string) (*Response, error) // AssignIssue assigns one or more users to an issue AssignIssue(ctx context.Context, repo string, number int, logins []string) (*Response, error) // UnassignIssue removes the assignment of ne or more users on an issue UnassignIssue(ctx context.Context, repo string, number int, logins []string) (*Response, error) // Create creates a new pull request in a repo. Create(context.Context, string, *PullRequestInput) (*PullRequest, *Response, error) // RequestReview adds one or more users as a reviewer on a pull request. RequestReview(ctx context.Context, repo string, number int, logins []string) (*Response, error) // UnrequestReview removes one or more users as a reviewer on a pull request. UnrequestReview(ctx context.Context, repo string, number int, logins []string) (*Response, error) // SetMilestone adds a milestone to a pull request SetMilestone(ctx context.Context, repo string, prID int, number int) (*Response, error) // ClearMilestone removes the milestone from a pull request ClearMilestone(ctx context.Context, repo string, prID int) (*Response, error) }
PullRequestService provides access to pull request resources.
type PushCommit ¶
type PushCommit struct { ID string Message string Added []string Removed []string Modified []string }
PushCommit represents general info about a commit.
type PushHook ¶
type PushHook struct { Ref string BaseRef string Repo Repository Before string After string Created bool Deleted bool Forced bool Compare string Commits []PushCommit Commit Commit Sender User GUID string Installation *InstallationRef }
PushHook represents a push hook, eg push events.
func (*PushHook) GetInstallationRef ¶ added in v1.5.44
func (h *PushHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*PushHook) Kind ¶ added in v1.5.47
func (h *PushHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*PushHook) Repository ¶
func (h *PushHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type Reference ¶
Reference represents a git reference.
Example (FindBranch) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func main() { client, err := github.New("https://api.github.com") if err != nil { log.Fatal(err) } branch, _, err := client.Git.FindBranch(ctx, "octocat/Hello-World", "master") if err != nil { log.Fatal(err) } log.Println(branch.Name, branch.Sha) }
Output:
Example (FindTag) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func main() { client, err := github.New("https://api.github.com") if err != nil { log.Fatal(err) } tag, _, err := client.Git.FindTag(ctx, "octocat/Hello-World", "v1.0.0") if err != nil { log.Fatal(err) } log.Println(tag.Name, tag.Sha) }
Output:
Example (ListBranch) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func main() { client, err := github.New("https://api.github.com") if err != nil { log.Fatal(err) } opts := scm.ListOptions{ Page: 1, Size: 30, } branches, _, err := client.Git.ListBranches(ctx, "octocat/Hello-World", &opts) if err != nil { log.Fatal(err) } for _, branch := range branches { log.Println(branch.Name, branch.Sha) } }
Output:
Example (ListTag) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func main() { client, err := github.New("https://api.github.com") if err != nil { log.Fatal(err) } opts := scm.ListOptions{ Page: 1, Size: 30, } tags, _, err := client.Git.ListTags(ctx, "octocat/Hello-World", &opts) if err != nil { log.Fatal(err) } for _, tag := range tags { log.Println(tag.Name, tag.Sha) } }
Output:
type ReferenceInput ¶ added in v1.11.22
ReferenceInput provides a SHA for creating a reference.
type Release ¶ added in v1.5.192
type Release struct { ID int Title string Description string Link string Tag string Commitish string Draft bool Prerelease bool Created time.Time Published time.Time }
Release the release
type ReleaseHook ¶ added in v1.5.60
type ReleaseHook struct { Action Action Repo Repository Release Release Sender User Label Label Installation *InstallationRef }
ReleaseHook represents a release event
func (*ReleaseHook) GetInstallationRef ¶ added in v1.5.60
func (h *ReleaseHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*ReleaseHook) Kind ¶ added in v1.5.60
func (h *ReleaseHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*ReleaseHook) Repository ¶ added in v1.5.60
func (h *ReleaseHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type ReleaseInput ¶ added in v1.5.192
type ReleaseInput struct { Title string Description string Tag string Commitish string Draft bool Prerelease bool }
ReleaseInput contains the information needed to create a release
type ReleaseListOptions ¶ added in v1.5.192
ReleaseListOptions provides options for querying a list of repository releases.
type ReleaseService ¶ added in v1.5.192
type ReleaseService interface { // Find returns the release for the given number in the given repository Find(context.Context, string, int) (*Release, *Response, error) // FindByTag returns the release for the given tag in the given repository FindByTag(context.Context, string, string) (*Release, *Response, error) // List returns a list of releases in the given repository List(context.Context, string, ReleaseListOptions) ([]*Release, *Response, error) // Create creates a release in the given repository Create(context.Context, string, *ReleaseInput) (*Release, *Response, error) // Update updates a release in the given repository Update(context.Context, string, int, *ReleaseInput) (*Release, *Response, error) // Update updates a release in the given repository by tag UpdateByTag(context.Context, string, string, *ReleaseInput) (*Release, *Response, error) // Delete deletes a release in the given repository Delete(context.Context, string, int) (*Response, error) // Delete deletes a release in the given repository by tag DeleteByTag(context.Context, string, string) (*Response, error) }
ReleaseService provides access to creating, listing, updating, and deleting releases
type Repository ¶
type Repository struct { ID string Namespace string Name string FullName string Perm *Perm Branch string Private bool Archived bool Clone string CloneSSH string Link string Created time.Time Updated time.Time }
Repository represents a git repository.
Example (Find) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) }
Output:
Example (List) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) } }
Output:
type RepositoryHook ¶ added in v1.5.65
type RepositoryHook struct { Action Action Repo Repository Sender User Installation *InstallationRef }
RepositoryHook represents a repository event
func (*RepositoryHook) GetInstallationRef ¶ added in v1.5.65
func (h *RepositoryHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*RepositoryHook) Kind ¶ added in v1.5.65
func (h *RepositoryHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*RepositoryHook) Repository ¶ added in v1.5.65
func (h *RepositoryHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type RepositoryInput ¶ added in v1.5.74
type RepositoryInput struct { Namespace string Name string Description string Homepage string Private bool }
RepositoryInput provides the input fields required for creating a new repository.
type RepositoryService ¶
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) // ListOrganisation returns a list of repositories for a given organisation ListOrganisation(context.Context, string, *ListOptions) ([]*Repository, *Response, error) // ListUser returns a list of repositories for a given user. ListUser(context.Context, string, *ListOptions) ([]*Repository, *Response, error) // ListLabels returns the labels on a repo ListLabels(context.Context, string, *ListOptions) ([]*Label, *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) // FindCombinedStatus returns the combined status for a ref FindCombinedStatus(ctx context.Context, repo, ref string) (*CombinedStatus, *Response, error) // Create creates a new repository . Create(context.Context, *RepositoryInput) (*Repository, *Response, error) // Fork creates a new repository as a fork of an existing one. Fork(context.Context, *RepositoryInput, string) (*Repository, *Response, error) // CreateHook creates a new repository webhook. CreateHook(context.Context, string, *HookInput) (*Hook, *Response, error) // UpdateHook edit a repository webhook UpdateHook(context.Context, string, *HookInput) (*Hook, *Response, error) // CreateStatus creates a new commit status. CreateStatus(context.Context, string, string, *StatusInput) (*Status, *Response, error) // DeleteHook deletes a repository webhook. DeleteHook(context.Context, string, string) (*Response, error) // IsCollaborator returns true if the user is a collaborator on the repository IsCollaborator(ctx context.Context, repo string, user string) (bool, *Response, error) // AddCollaborator adds a collaborator to the repository AddCollaborator(ctx context.Context, repo, user, permission string) (bool, bool, *Response, error) // ListCollaborators lists the collaborators on a repository ListCollaborators(ctx context.Context, repo string, ops *ListOptions) ([]User, *Response, error) // FindUserPermission returns the user's permission level for a repo FindUserPermission(ctx context.Context, repo string, user string) (string, *Response, error) // Delete deletes a repository Delete(ctx context.Context, repo string) (*Response, error) }
RepositoryService provides access to repository resources.
type Response ¶
type Response struct { ID string Status int Header http.Header Body io.ReadCloser Page Page // Page values Rate Rate // Rate limit snapshot }
Response represents an HTTP response.
func (*Response) PopulatePageValues ¶ added in v1.5.170
func (r *Response) PopulatePageValues()
PopulatePageValues parses the HTTP Link response headers and populates the various pagination link values in the Response.
Copyright 2013 The go-github AUTHORS. All rights reserved. https://github.com/google/go-github
type Review ¶
type Review struct { ID int Body string Sha string Link string State string Author User Created time.Time Updated time.Time }
Review represents a review.
Example (Create) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func main() { client, err := github.New("https://api.github.com") if err != nil { log.Fatal(err) } in := &scm.ReviewInput{ Sha: "7044a8a032e85b6ab611033b2ac8af7ce85805b2", Event: "COMMENT", Comments: []*scm.ReviewCommentInput{ { 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) }
Output:
Example (Find) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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.Sha, review.State, review.Body, ) }
Output:
Example (List) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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.Sha, review.State, review.Body, ) } }
Output:
type ReviewComment ¶ added in v1.5.140
type ReviewComment struct { ID int Body string Path string Sha string Line int Link string Author User Created time.Time Updated time.Time }
ReviewComment represents a review comment.
type ReviewCommentHook ¶
type ReviewCommentHook struct { Action Action Repo Repository PullRequest PullRequest Review Review Installation *InstallationRef }
ReviewCommentHook represents a pull request review comment, eg pull_request_review_comment.
func (*ReviewCommentHook) GetInstallationRef ¶ added in v1.5.44
func (h *ReviewCommentHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*ReviewCommentHook) Kind ¶ added in v1.5.47
func (h *ReviewCommentHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*ReviewCommentHook) Repository ¶
func (h *ReviewCommentHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type ReviewCommentInput ¶ added in v1.5.140
ReviewCommentInput provides the input fields required for creating a review comment.
type ReviewHook ¶
type ReviewHook struct { Action Action PullRequest PullRequest Repo Repository Review Review Installation *InstallationRef // GUID is included in the header of the request received by Github. GUID string }
ReviewHook represents a review web hook
func (*ReviewHook) GetInstallationRef ¶ added in v1.5.94
func (h *ReviewHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*ReviewHook) Kind ¶ added in v1.5.94
func (h *ReviewHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*ReviewHook) Repository ¶ added in v1.5.94
func (h *ReviewHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type ReviewInput ¶
type ReviewInput struct { Body string Sha string Event string Comments []*ReviewCommentInput }
ReviewInput provides the input fields required for creating or updating a review.
type ReviewService ¶
type ReviewService interface { // Find returns the review by id. Find(context.Context, string, int, int) (*Review, *Response, error) // List returns the review list. List(context.Context, string, int, *ListOptions) ([]*Review, *Response, error) // Create creates a review. Create(context.Context, string, int, *ReviewInput) (*Review, *Response, error) // Delete deletes a review. Delete(context.Context, string, int, int) (*Response, error) // ListComments returns comments from a review ListComments(context.Context, string, int, int, *ListOptions) ([]*ReviewComment, *Response, error) // Update updates the body of a review Update(context.Context, string, int, int, string) (*Review, *Response, error) // Submit submits a pending review Submit(context.Context, string, int, int, *ReviewSubmitInput) (*Review, *Response, error) // Dismiss dismisses a review Dismiss(context.Context, string, int, int, string) (*Review, *Response, error) }
ReviewService provides access to review resources.
type ReviewSubmitInput ¶ added in v1.5.140
ReviewSubmitInput provides the input fields required for submitting a pending review.
type SearchIssue ¶ added in v1.5.34
type SearchIssue struct { Issue Repository Repository }
SearchIssue for the results of a search which queries across repositories
type SearchOptions ¶ added in v1.5.34
SearchOptions thte query options for a search
func (*SearchOptions) QueryArgument ¶ added in v1.5.34
func (o *SearchOptions) QueryArgument() string
QueryArgument returns the query argument for the search using '+' to separate the search terms while escaping :
type SecretFunc ¶
SecretFunc provides the Webhook parser with the secret key used to validate webhook authenticity.
type Signature ¶
type Signature struct { Name string Email string Date time.Time // Fields are optional. The provider may choose to // include account information in the response. Login string Avatar string }
Signature identifies a git commit creator.
type StarHook ¶ added in v1.5.94
type StarHook struct { Action Action StarredAt time.Time Repo Repository Sender User }
StarHook represents a star event. This is currently GitHub-specific.
func (*StarHook) GetInstallationRef ¶ added in v1.5.94
func (h *StarHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*StarHook) Kind ¶ added in v1.5.94
func (h *StarHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*StarHook) Repository ¶ added in v1.5.94
func (h *StarHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type State ¶
type State int
State represents the commit state.
const ( StateUnknown State = iota StateFailure StateCanceled StateError StateExpected StatePending StateRunning StateSuccess )
State values.
func (State) MarshalJSON ¶ added in v1.5.53
MarshalJSON marshals State to JSON
func (*State) UnmarshalJSON ¶ added in v1.5.53
UnmarshalJSON unmarshals JSON to State
type StateCannotBeChanged ¶
type StateCannotBeChanged struct {
Message string
}
StateCannotBeChanged represents the error that occurs when a resource cannot be changed
func (StateCannotBeChanged) Error ¶
func (s StateCannotBeChanged) Error() string
type Status ¶
Status represents a commit status.
Example (Create) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) } }
Output:
Example (List) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) } }
Output:
func ConvertStatusInputToStatus ¶
func ConvertStatusInputToStatus(input *StatusInput) *Status
ConvertStatusInputToStatus converts the input to a status
func ConvertStatusInputsToStatuses ¶
func ConvertStatusInputsToStatuses(inputs []*StatusInput) []*Status
ConvertStatusInputsToStatuses converts the inputs to status objects
type StatusHook ¶ added in v1.5.59
type StatusHook struct { Action Action Repo Repository Sender User Label Label Installation *InstallationRef }
StatusHook represents a status event
func (*StatusHook) GetInstallationRef ¶ added in v1.5.59
func (h *StatusHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*StatusHook) Kind ¶ added in v1.5.59
func (h *StatusHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*StatusHook) Repository ¶ added in v1.5.59
func (h *StatusHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type StatusInput ¶
StatusInput provides the input fields required for creating or updating commit statuses.
type TagHook ¶
type TagHook struct { Ref Reference Repo Repository Action Action Sender User Installation *InstallationRef }
TagHook represents a tag event, eg create and delete github event types.
func (*TagHook) GetInstallationRef ¶ added in v1.5.44
func (h *TagHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*TagHook) Kind ¶ added in v1.5.47
func (h *TagHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*TagHook) Repository ¶
func (h *TagHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type Team ¶
type Team struct { ID int Name string Slug string Description string Privacy string // Parent is populated in queries Parent *Team // ParentTeamID is only valid when creating / editing teams ParentTeamID int }
Team is a organizational team
type TeamMember ¶
TeamMember is a member of an organizational team
type Token ¶
Token represents the credentials used to authorize the requests to access protected resources.
type TokenKey ¶
type TokenKey struct{}
TokenKey is the key to use with the context.WithValue function to associate an Token value with a context.
type TokenSource ¶
TokenSource returns a token.
type UnknownWebhook ¶
type UnknownWebhook struct {
Event string
}
UnknownWebhook if the webhook is unknown
func (UnknownWebhook) Error ¶
func (e UnknownWebhook) Error() string
type User ¶
type User struct { ID int Login string Name string Email string Avatar string Link string IsAdmin bool `json:"isAdmin,omitempty"` Created time.Time Updated time.Time }
User represents a user account.
Example (Find) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) }
Output:
Example (FindLogin) ¶
package main import ( "context" "log" "github.com/jenkins-x/go-scm/scm/driver/github" ) var ctx context.Context func 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) }
Output:
type UserService ¶
type UserService interface { // Find returns the authenticated user. Find(context.Context) (*User, *Response, error) // CreateToken creates a user token. CreateToken(context.Context, string, string) (*UserToken, *Response, error) // DeleteToken deletes a user token. DeleteToken(context.Context, int64) (*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) // ListInvitations lists repository or organization invitations for the current user ListInvitations(context.Context) ([]*Invitation, *Response, error) // AcceptInvitation accepts an invitation for the current user AcceptInvitation(context.Context, int64) (*Response, error) }
UserService provides access to user account resources.
type WatchHook ¶ added in v1.5.94
type WatchHook struct { Action string Repo Repository Sender User Installation *InstallationRef }
WatchHook represents a watch event. This is currently GitHub-specific.
func (*WatchHook) GetInstallationRef ¶ added in v1.5.94
func (h *WatchHook) GetInstallationRef() *InstallationRef
GetInstallationRef returns the installation reference if the webhook is invoked on a GitHub App
func (*WatchHook) Kind ¶ added in v1.5.94
func (h *WatchHook) Kind() WebhookKind
Kind returns the kind of webhook
func (*WatchHook) Repository ¶ added in v1.5.94
func (h *WatchHook) Repository() Repository
Repository defines the repository webhook and provides a convenient way to get the associated repository without having to cast the type.
type Webhook ¶
type Webhook interface { Repository() Repository GetInstallationRef() *InstallationRef Kind() WebhookKind }
Webhook defines a webhook for repository events.
Example ¶
package main import ( "log" "net/http" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/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) err := http.ListenAndServe(":8000", nil) // #nosec G114 if err != nil { log.Fatal(err) } }
Output:
Example (LookupSecret) ¶
package main import ( "database/sql" "log" "net/http" "github.com/jenkins-x/go-scm/scm" "github.com/jenkins-x/go-scm/scm/driver/github" ) var db *sql.DB func 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, ) default: log.Fatal(err) } } http.HandleFunc("/hook", handler) err := http.ListenAndServe(":8000", nil) // #nosec G114 if err != nil { log.Fatal(err) } }
Output:
type WebhookKind ¶ added in v1.5.47
type WebhookKind string
WebhookKind is the kind of webhook event represented
const ( // WebhookKindBranch is for branch events WebhookKindBranch WebhookKind = "branch" // WebhookKindCheckRun is for check run events WebhookKindCheckRun WebhookKind = "check_run" // WebhookKindCheckSuite is for check suite events WebhookKindCheckSuite WebhookKind = "check_suite" // WebhookKindDeploy is for deploy events WebhookKindDeploy WebhookKind = "deploy" // WebhookKindDeploymentStatus is for deployment status events WebhookKindDeploymentStatus WebhookKind = "deployment_status" // WebhookKindFork is for fork events WebhookKindFork WebhookKind = "fork" // WebhookKindInstallation is for app installation events WebhookKindInstallation WebhookKind = "installation" // WebhookKindInstallationRepository is for app installation in a repository events WebhookKindInstallationRepository WebhookKind = "installation_repository" // WebhookKindIssue is for issue events WebhookKindIssue WebhookKind = "issue" // WebhookKindIssueComment is for issue comment events WebhookKindIssueComment WebhookKind = "issue_comment" // WebhookKindLabel is for label events WebhookKindLabel WebhookKind = "label" // WebhookKindPing is for ping events WebhookKindPing WebhookKind = "ping" // WebhookKindPullRequest is for pull request events WebhookKindPullRequest WebhookKind = "pull_request" // WebhookKindPullRequestComment is for pull request comment events WebhookKindPullRequestComment WebhookKind = "pull_request_comment" // WebhookKindPush is for push events WebhookKindPush WebhookKind = "push" // WebhookKindRelease is for release events WebhookKindRelease WebhookKind = "release" // WebhookKindRepository is for repository events WebhookKindRepository WebhookKind = "repository" // WebhookKindReview is for review events WebhookKindReview WebhookKind = "review" // WebhookKindReviewCommentHook is for review comment events WebhookKindReviewCommentHook WebhookKind = "review_comment" // WebhookKindStar is for star events WebhookKindStar WebhookKind = "star" // WebhookKindStatus is for status events WebhookKindStatus WebhookKind = "status" // WebhookKindTag is for tag events WebhookKindTag WebhookKind = "tag" // WebhookKindWatch is for watch events WebhookKindWatch WebhookKind = "watch" )
type WebhookService ¶
type WebhookService interface { // Parse returns the parsed the repository webhook payload. Parse(req *http.Request, fn SecretFunc) (Webhook, error) }
WebhookService provides abstract functions for parsing and validating webhooks requests.
type WebhookWrapper ¶ added in v1.10.7
type WebhookWrapper struct { PingHook *PingHook `json:",omitempty"` PushHook *PushHook `json:",omitempty"` BranchHook *BranchHook `json:",omitempty"` CheckRunHook *CheckRunHook `json:",omitempty"` CheckSuiteHook *CheckSuiteHook `json:",omitempty"` DeployHook *DeployHook `json:",omitempty"` DeploymentStatusHook *DeploymentStatusHook `json:",omitempty"` ForkHook *ForkHook `json:",omitempty"` TagHook *TagHook `json:",omitempty"` IssueHook *IssueHook `json:",omitempty"` IssueCommentHook *IssueCommentHook `json:",omitempty"` InstallationHook *InstallationHook `json:",omitempty"` InstallationRepositoryHook *InstallationRepositoryHook `json:",omitempty"` LabelHook *LabelHook `json:",omitempty"` ReleaseHook *ReleaseHook `json:",omitempty"` RepositoryHook *RepositoryHook `json:",omitempty"` PullRequestHook *PullRequestHook `json:",omitempty"` PullRequestCommentHook *PullRequestCommentHook `json:",omitempty"` ReviewCommentHook *ReviewCommentHook `json:",omitempty"` WatchHook *WatchHook `json:",omitempty"` StarHook *StarHook `json:",omitempty"` }
WebhookWrapper lets us parse any webhook
func (*WebhookWrapper) ToWebhook ¶ added in v1.10.7
func (h *WebhookWrapper) ToWebhook() (Webhook, error)
ToWebhook converts the webhook wrapper to a webhook
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. |
gitea
Package gitea implements a Gitea client.
|
Package gitea implements a Gitea 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 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. |