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 Action
- type BranchHook
- type Change
- type Client
- type CombinedStatus
- type Comment
- type CommentInput
- type Commit
- type CommitListOptions
- type CommitTree
- type Content
- type ContentParams
- type ContentService
- type DeployHook
- type Driver
- type ExtraUsers
- type GitService
- type GraphQLService
- type Hook
- type HookEvents
- type HookInput
- type Issue
- type IssueCommentHook
- type IssueHook
- type IssueInput
- type IssueListOptions
- type IssueService
- type Label
- type ListOptions
- type ListedIssueEvent
- type MergeableState
- type Milestone
- type MissingHeader
- type MissingUsers
- type Organization
- type OrganizationService
- type Page
- type Perm
- type PullRequest
- type PullRequestBranch
- type PullRequestCommentHook
- type PullRequestHook
- type PullRequestHookBranch
- type PullRequestHookBranchFrom
- type PullRequestHookChanges
- type PullRequestListOptions
- type PullRequestService
- type PushCommit
- type PushHook
- type Rate
- type Reference
- type Repository
- type RepositoryService
- type Request
- type Response
- type Review
- type ReviewCommentHook
- type ReviewHook
- type ReviewInput
- type ReviewService
- type SearchIssue
- type SearchOptions
- type SecretFunc
- type Signature
- type State
- type StateCannotBeChanged
- type Status
- type StatusInput
- type TagHook
- type Team
- type TeamMember
- type Token
- type TokenKey
- type TokenSource
- type UnknownWebhook
- type User
- type UserService
- type Webhook
- type WebhookSerializer
- 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 ( 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.
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 )
Action values.
func (Action) MarshalJSON ¶
MarshalJSON returns the JSON-encoded Action.
func (*Action) UnmarshalJSON ¶
UnmarshalJSON unmarshales the JSON-encoded Action.
type BranchHook ¶
type BranchHook struct { Ref Reference Repo Repository Action Action Sender User }
BranchHook represents a branch or tag event, eg create and delete github event types.
func (*BranchHook) Repository ¶
func (h *BranchHook) Repository() Repository
type Change ¶
type Change struct { Path string Added bool Renamed bool Deleted bool Additions int Deletions int Changes int BlobURL string Sha string }
Change represents a changed file.
type Client ¶
type Client struct { // HTTP client used to communicate with the API. Client *http.Client // Base URL for API requests. BaseURL *url.URL // Services used for communicating with the API. Driver Driver Contents ContentService Git GitService Organizations OrganizationService Issues IssueService PullRequests PullRequestService Repositories RepositoryService Reviews ReviewService Users UserService Webhooks WebhookService GraphQL GraphQLService // 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 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) // Create creates a new repositroy 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 }
DeployHook represents a deployment event. This is currently a GitHub-specific event type.
func (*DeployHook) Repository ¶
func (h *DeployHook) Repository() Repository
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 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) }
GitService provides access to git resources.
type GraphQLService ¶
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 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 }
IssueCommentHook represents an issue comment event, eg issue_comment.
func (*IssueCommentHook) Repository ¶
func (h *IssueCommentHook) Repository() Repository
type IssueHook ¶
type IssueHook struct { Action Action Repo Repository Issue Issue Sender User }
IssueHook represents an issue event, eg issues.
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 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) // Close closes an issue. Close(context.Context, string, int) (*Response, error) // Lock locks an issue discussion. Lock(context.Context, string, int) (*Response, error) // Unlock unlocks an issue discussion. Unlock(context.Context, string, int) (*Response, error) // 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 asigns 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) }
IssueService provides access to issue resources.
type ListOptions ¶
ListOptions specifies optional pagination parameters.
type ListedIssueEvent ¶
ListedIssueEvent for listing events on an issue
type MergeableState ¶
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 ¶
func ToMergeableState(text string) MergeableState
ToMergeableState converts the given string to a mergeable state
func (MergeableState) String ¶
func (s MergeableState) String() string
String returns the string representation
type Milestone ¶
type Milestone struct { Number int ID int Title string Description string Link string State string }
Milestone the milestotne
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 ¶
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 organiation IsMember(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) }
OrganizationService provides access to organization resources.
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 Link string State string Closed bool Draft bool Merged bool Mergeable bool Rebaseable bool MergeableState MergeableState MergeSha string Author User Assignees []User Milestone Milestone Created time.Time Updated time.Time }
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) if err != nil { log.Fatal(err) } }
Output:
func (*PullRequest) Repository ¶
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 }
PullRequestCommentHook represents an pull request comment event, eg pull_request_comment.
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 }
PullRequestHook represents an pull request event, eg pull_request.
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 PullRequestListOptions ¶
PullRequestListOptions provides options for querying a list of repository merge requests.
type PullRequestService ¶
type PullRequestService interface { // Find returns the repository pull request by number. Find(context.Context, string, int) (*PullRequest, *Response, error) // FindComment returns the pull request comment by id. FindComment(context.Context, string, int, int) (*Comment, *Response, error) // Find returns the repository pull request list. List(context.Context, string, PullRequestListOptions) ([]*PullRequest, *Response, error) // ListChanges returns the pull request changeset. ListChanges(context.Context, string, int, ListOptions) ([]*Change, *Response, error) // ListComments returns the pull request comment list. ListComments(context.Context, string, int, ListOptions) ([]*Comment, *Response, error) // Merge merges the repository pull request. Merge(context.Context, string, int) (*Response, error) // Close closes the repository pull request. Close(context.Context, string, int) (*Response, error) // CreateComment creates a new pull request comment. CreateComment(context.Context, string, int, *CommentInput) (*Comment, *Response, error) // DeleteComment deletes an pull request comment. DeleteComment(context.Context, string, int, int) (*Response, error) }
PullRequestService provides access to pull request resources.
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 }
PushHook represents a push hook, eg push events.
func (*PushHook) Repository ¶
func (h *PushHook) 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 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) // 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) // 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, user string) (bool, *Response, error) // ListCollaborators lists the collaborators on a repository ListCollaborators(ctx context.Context, repo string) ([]User, *Response, error) // FindUserPermission returns the user's permission level for a repo FindUserPermission(ctx context.Context, repo string, user string) (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.
type Review ¶
type Review struct { ID int Body string Path string Sha string Line int Link string State string Author User Created time.Time Updated time.Time }
Review represents a review 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.ReviewInput{ Line: 38, Path: "main.go", Body: "Run gofmt please", } review, _, err := client.Reviews.Create(ctx, "octocat/Hello-World", 1, in) if err != nil { log.Fatal(err) } log.Println(review.ID) }
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.Path, review.Line, 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.Path, review.Line, review.Body, ) } }
Output:
type ReviewCommentHook ¶
type ReviewCommentHook struct { Action Action Repo Repository PullRequest PullRequest Review Review }
ReviewCommentHook represents a pull request review comment, eg pull_request_review_comment.
func (*ReviewCommentHook) Repository ¶
func (h *ReviewCommentHook) Repository() Repository
type ReviewHook ¶
type ReviewHook struct { Action Action PullRequest PullRequest Repo Repository Review Review // GUID is included in the header of the request received by Github. GUID string }
ReviewHook represents a review web hook
type ReviewInput ¶
ReviewInput provides the input fields required for creating a review comment.
type ReviewService ¶
type ReviewService interface { // Find returns the review comment by id. Find(context.Context, string, int, int) (*Review, *Response, error) // List returns the review comment list. List(context.Context, string, int, ListOptions) ([]*Review, *Response, error) // Create creates a review comment. Create(context.Context, string, int, *ReviewInput) (*Review, *Response, error) // Delete deletes a review comment. Delete(context.Context, string, int, int) (*Response, error) }
ReviewService provides access to review resources.
type SearchIssue ¶
type SearchIssue struct { Issue Repository Repository }
SearchIssue for the results of a search which queries across repositories
type SearchOptions ¶
SearchOptions thte query options for a search
func (*SearchOptions) QueryArgument ¶
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 State ¶
type State int
State represents the commit 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 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 }
TagHook represents a tag event, eg create and delete github event types.
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 ¶
type TeamMember struct {
Login string `json:"login"`
}
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 { Login string Name string Email string Avatar string Link string 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) }
UserService provides access to user account resources.
type Webhook ¶
type Webhook interface {
Repository() Repository
}
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 WebhookSerializer ¶
WebhookSerializer wraps Webhook and assigns a type for unmarshalling. Use this if you need to deserialize Webhooks of uknown concrete type.
func (*WebhookSerializer) MarshalJSON ¶
func (wu *WebhookSerializer) MarshalJSON() ([]byte, error)
MarshalJSON adds a type field to a serialized Webhook so that it can be deserialized into the same concrete type.
func (*WebhookSerializer) UnmarshalJSON ¶
func (wu *WebhookSerializer) UnmarshalJSON(b []byte) error
UnmarshalJSON supports deserialization of GitEventSpec.ParsedWebhook into a concrete implementation of scm.Webhook
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. |