Documentation ¶
Index ¶
- Constants
- Variables
- func ExpandRef(name, prefix string) string
- 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 CommitTree
- type Content
- type ContentParams
- type ContentService
- type DeployHook
- type Deployment
- type DeploymentInput
- type DeploymentService
- type DeploymentStatus
- type DeploymentStatusHook
- type DeploymentStatusInput
- type Driver
- 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 MergeableState
- type Milestone
- type MilestoneInput
- type MilestoneListOptions
- type MilestoneService
- type MissingHeader
- type MissingUsers
- type Organization
- 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 ReleaseHook
- 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 WatchHook
- type Webhook
- type WebhookKind
- 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 ( // 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 string = "APPROVED" ReviewStateChangesRequested string = "CHANGES_REQUESTED" ReviewStateCommented string = "COMMENTED" ReviewStateDismissed string = "DISMISSED" 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") )
var ( // ErrSignatureInvalid is returned when the webhook // signature is invalid or cannot be calculated. ErrSignatureInvalid = errors.New("Invalid webhook signature") )
Functions ¶
func ExpandRef ¶
ExpandRef returns name expanded to the fully qualified reference path (e.g refs/heads/master).
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 // 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
func (*BranchHook) Kind ¶ added in v1.5.47
func (h *BranchHook) Kind() WebhookKind
func (*BranchHook) Repository ¶
func (h *BranchHook) Repository() Repository
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
func (*CheckRunHook) Kind ¶ added in v1.5.59
func (h *CheckRunHook) Kind() WebhookKind
func (*CheckRunHook) Repository ¶ added in v1.5.59
func (h *CheckRunHook) Repository() Repository
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
func (*CheckSuiteHook) Kind ¶ added in v1.5.59
func (h *CheckSuiteHook) Kind() WebhookKind
func (*CheckSuiteHook) Repository ¶ added in v1.5.59
func (h *CheckSuiteHook) Repository() Repository
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 // 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 PullRequests PullRequestService Repositories RepositoryService Reviews ReviewService Users UserService Webhooks WebhookService // 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:
type CommitListOptions ¶
CommitListOptions provides options for querying a list of repository commits.
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 ¶
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) // Lists 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 reository file. Delete(ctx context.Context, repo, path, ref string) (*Response, error) }
ContentService provides access to repositroy content.
type DeployHook ¶
type DeployHook struct { Data interface{} Desc string Ref Reference Repo Repository Sender User Target string TargetURL string Task string 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
func (*DeployHook) Kind ¶ added in v1.5.47
func (h *DeployHook) Kind() WebhookKind
func (*DeployHook) Repository ¶
func (h *DeployHook) Repository() Repository
type Deployment ¶ added in v1.5.76
type Deployment struct { ID string Namespace string Name string Link string Sha string Ref 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 }
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 { Action Action Repo Repository Sender User Label Label Installation *InstallationRef }
DeploymentStatusHook represents a check suite event
func (*DeploymentStatusHook) GetInstallationRef ¶ added in v1.5.59
func (h *DeploymentStatusHook) GetInstallationRef() *InstallationRef
func (*DeploymentStatusHook) Kind ¶ added in v1.5.59
func (h *DeploymentStatusHook) Kind() WebhookKind
func (*DeploymentStatusHook) Repository ¶ added in v1.5.59
func (h *DeploymentStatusHook) Repository() Repository
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
func (*ForkHook) Kind ¶ added in v1.5.65
func (h *ForkHook) Kind() WebhookKind
func (*ForkHook) Repository ¶ added in v1.5.65
func (h *ForkHook) Repository() Repository
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 two commits. ListChanges(ctx context.Context, repo, ref 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 Issue bool IssueComment bool PullRequest bool PullRequestComment bool Push 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
func (*InstallationHook) Kind ¶ added in v1.5.47
func (h *InstallationHook) Kind() WebhookKind
func (*InstallationHook) Repository ¶ added in v1.5.43
func (h *InstallationHook) Repository() Repository
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
func (*InstallationRepositoryHook) Kind ¶ added in v1.5.65
func (h *InstallationRepositoryHook) Kind() WebhookKind
func (*InstallationRepositoryHook) Repository ¶ added in v1.5.65
func (h *InstallationRepositoryHook) Repository() Repository
type InstallationToken ¶ added in v1.5.43
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 PullRequest bool 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 Installation *InstallationRef }
IssueCommentHook represents an issue comment event, eg issue_comment.
func (*IssueCommentHook) GetInstallationRef ¶ added in v1.5.44
func (h *IssueCommentHook) GetInstallationRef() *InstallationRef
func (*IssueCommentHook) Kind ¶ added in v1.5.47
func (h *IssueCommentHook) Kind() WebhookKind
func (*IssueCommentHook) Repository ¶
func (h *IssueCommentHook) Repository() Repository
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
func (*IssueHook) Kind ¶ added in v1.5.47
func (h *IssueHook) Kind() WebhookKind
func (*IssueHook) Repository ¶
func (h *IssueHook) Repository() Repository
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
func (*LabelHook) Kind ¶ added in v1.5.59
func (h *LabelHook) Kind() WebhookKind
func (*LabelHook) Repository ¶ added in v1.5.59
func (h *LabelHook) Repository() Repository
type ListOptions ¶
ListOptions specifies optional pagination parameters.
type ListedIssueEvent ¶
ListedIssueEvent for listing events on an issue
type MergeableState ¶ added in v1.5.34
type MergeableState string
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 milestotne
type MilestoneInput ¶ added in v1.5.165
MilestoneInput contains the information needed to create a milestone
type MilestoneListOptions ¶ added in v1.5.165
MilestoneOptions provides options for querying a list of repository merge requests.
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 OrganizationService ¶
type OrganizationService interface { // Find returns the organization by name. Find(context.Context, string) (*Organization, *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) }
OrganizationService provides access to organization resources.
type Permissions ¶ added in v1.5.80
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
func (*PingHook) Repository ¶ added in v1.5.45
func (h *PingHook) Repository() Repository
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 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
func (*PullRequestCommentHook) Kind ¶ added in v1.5.47
func (h *PullRequestCommentHook) Kind() WebhookKind
func (*PullRequestCommentHook) Repository ¶
func (h *PullRequestCommentHook) Repository() Repository
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
func (*PullRequestHook) Kind ¶ added in v1.5.47
func (h *PullRequestHook) Kind() WebhookKind
func (*PullRequestHook) Repository ¶
func (h *PullRequestHook) Repository() Repository
type PullRequestHookBranch ¶
type PullRequestHookBranch struct { Ref PullRequestHookBranchFrom Sha PullRequestHookBranchFrom Repo Repository }
type PullRequestHookBranchFrom ¶
type PullRequestHookBranchFrom struct {
From string
}
type PullRequestHookChanges ¶
type PullRequestHookChanges struct {
Base PullRequestHookBranch
}
type PullRequestInput ¶ added in v1.5.71
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 }
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) // 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
func (*PushHook) Kind ¶ added in v1.5.47
func (h *PushHook) Kind() WebhookKind
func (*PushHook) Repository ¶
func (h *PushHook) Repository() Repository
type ReleaseHook ¶ added in v1.5.60
type ReleaseHook struct { Action Action Repo Repository Sender User Label Label Installation *InstallationRef }
ReleaseHook represents a release event
func (*ReleaseHook) GetInstallationRef ¶ added in v1.5.60
func (h *ReleaseHook) GetInstallationRef() *InstallationRef
func (*ReleaseHook) Kind ¶ added in v1.5.60
func (h *ReleaseHook) Kind() WebhookKind
func (*ReleaseHook) Repository ¶ added in v1.5.60
func (h *ReleaseHook) Repository() Repository
type Repository ¶
type Repository struct { ID string Namespace string Name string FullName string Perm *Perm Branch string Private 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
func (*RepositoryHook) Kind ¶ added in v1.5.65
func (h *RepositoryHook) Kind() WebhookKind
func (*RepositoryHook) Repository ¶ added in v1.5.65
func (h *RepositoryHook) Repository() Repository
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) // List returns a list of repositories for a given organisation ListOrganisation(context.Context, string, ListOptions) ([]*Repository, *Response, error) // List 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 creatings 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) // 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
func (*ReviewCommentHook) Kind ¶ added in v1.5.47
func (h *ReviewCommentHook) Kind() WebhookKind
func (*ReviewCommentHook) Repository ¶
func (h *ReviewCommentHook) Repository() Repository
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
func (*ReviewHook) Kind ¶ added in v1.5.94
func (h *ReviewHook) Kind() WebhookKind
func (*ReviewHook) Repository ¶ added in v1.5.94
func (h *ReviewHook) Repository() Repository
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
func (*StarHook) Kind ¶ added in v1.5.94
func (h *StarHook) Kind() WebhookKind
func (*StarHook) Repository ¶ added in v1.5.94
func (h *StarHook) Repository() Repository
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
func (*State) UnmarshalJSON ¶ added in v1.5.53
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
func (*StatusHook) Kind ¶ added in v1.5.59
func (h *StatusHook) Kind() WebhookKind
func (*StatusHook) Repository ¶ added in v1.5.59
func (h *StatusHook) Repository() Repository
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
func (*TagHook) Kind ¶ added in v1.5.47
func (h *TagHook) Kind() WebhookKind
func (*TagHook) Repository ¶
func (h *TagHook) Repository() Repository
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) // 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
func (*WatchHook) Kind ¶ added in v1.5.94
func (h *WatchHook) Kind() WebhookKind
func (*WatchHook) Repository ¶ added in v1.5.94
func (h *WatchHook) Repository() Repository
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) http.ListenAndServe(":8000", nil) }
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, ) } } http.HandleFunc("/hook", handler) http.ListenAndServe(":8000", nil) }
Output:
type WebhookKind ¶ added in v1.5.47
type WebhookKind string
const ( WebhookKindBranch WebhookKind = "branch" WebhookKindCheckRun WebhookKind = "check_run" WebhookKindCheckSuite WebhookKind = "check_suite" WebhookKindDeploy WebhookKind = "deploy" WebhookKindDeploymentStatus WebhookKind = "deployment_status" WebhookKindFork WebhookKind = "fork" WebhookKindInstallation WebhookKind = "installation" WebhookKindInstallationRepository WebhookKind = "installation_repository" WebhookKindIssue WebhookKind = "issue" WebhookKindIssueComment WebhookKind = "issue_comment" WebhookKindLabel WebhookKind = "label" WebhookKindPing WebhookKind = "ping" WebhookKindPullRequest WebhookKind = "pull_request" WebhookKindPullRequestComment WebhookKind = "pull_request_comment" WebhookKindPush WebhookKind = "push" WebhookKindRelease WebhookKind = "release" WebhookKindRepository WebhookKind = "repository" WebhookKindReview WebhookKind = "review" WebhookKindReviewCommentHook WebhookKind = "review_comment" WebhookKindStar WebhookKind = "star" WebhookKindStatus WebhookKind = "status" WebhookKindTag WebhookKind = "tag" 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.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
driver
|
|
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. |