git

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IssueTypeIssue       = IssueType("issue")
	IssueTypePullRequest = IssueType("pull_request")
)

IssueType constants

View Source
const (
	CommitStatusStateSuccess = CommitStatusState("success")
	CommitStatusStateFailure = CommitStatusState("failure")
	CommitStatusStateError   = CommitStatusState("error")
	CommitStatusStatePending = CommitStatusState("pending")
)

CommitStatusStates

View Source
const (
	MergeMethodSquash = MergeMethod("squash")
	MergeMethodMerge  = MergeMethod("merge")
)

MergeMethod types

View Source
const (
	EventTypePullRequest              = EventType("pull_request")
	EventTypePush                     = EventType("push")
	EventTypeIssueComment             = EventType("issue_comment")
	EventTypePullRequestReview        = EventType("pull_request_review")
	EventTypePullRequestReviewComment = EventType("pull_request_review_comment")
)

Event Types

View Source
const (
	PullRequestStateOpen   = PullRequestState("open")
	PullRequestStateClosed = PullRequestState("closed")
)

Pull Request states

View Source
const (
	PullRequestActionReOpen      = PullRequestAction("reopened")
	PullRequestActionOpen        = PullRequestAction("opened")
	PullRequestActionClose       = PullRequestAction("closed")
	PullRequestActionSynchronize = PullRequestAction("synchronize")
	PullRequestActionLabeled     = PullRequestAction("labeled")
	PullRequestActionUnlabeled   = PullRequestAction("unlabeled")
)

Pull Request actions

View Source
const (
	PullRequestReviewStateApproved   = PullRequestReviewState("approved")
	PullRequestReviewStateUnapproved = PullRequestReviewState("changes_requested")
)

Pull Request review state

View Source
const (
	FakeSha = "0000000000000000000000000000000000000000"
)

FakeSha is a fake SHA for a commit

Variables

This section is empty.

Functions

func GetChangedLinesFromDiff

func GetChangedLinesFromDiff(diffString string) (int, int, error)

GetChangedLinesFromDiff parses a diffString and returns the number of changed lines (additions / deletions)

func GetPaginatedRequest

func GetPaginatedRequest(apiURL string, header map[string]string, newObj func() interface{}, accumulate func(interface{})) error

GetPaginatedRequest gets paginated APIs and accumulates them together

func RequestHTTP

func RequestHTTP(method string, uri string, header map[string]string, data interface{}) ([]byte, http.Header, error)

RequestHTTP requests api call

Types

type Base

type Base struct {
	Ref string
	Sha string
}

Base is a reference for base commit

type Branch

type Branch struct {
	Name     string
	CommitID string
}

Branch is a branch info

type Change

type Change struct {
	Filename    string
	OldFilename string
	Additions   int
	Deletions   int
	Changes     int // Changes should be equal to the addition of Additions and Deletions
}

Change is a diff of a changed file

type Client

type Client interface {
	Init() error

	ListWebhook() ([]WebhookEntry, error)
	RegisterWebhook(url string) error
	DeleteWebhook(id int) error
	ParseWebhook(http.Header, []byte) (*Webhook, error)

	ListCommitStatuses(ref string) ([]CommitStatus, error)
	SetCommitStatus(sha string, status CommitStatus) error

	GetUserInfo(user string) (*User, error)
	CanUserWriteToRepo(user User) (bool, error)

	RegisterComment(issueType IssueType, issueNo int, body string) error

	ListPullRequests(onlyOpen bool) ([]PullRequest, error)
	GetPullRequest(id int) (*PullRequest, error)
	MergePullRequest(id int, sha string, method MergeMethod, message string) error
	GetPullRequestDiff(id int) (*Diff, error)
	ListPullRequestCommits(id int) ([]Commit, error)

	SetLabel(issueType IssueType, id int, label string) error
	DeleteLabel(issueType IssueType, id int, label string) error

	GetBranch(branch string) (*Branch, error)
}

Client is a git client interface

type Comment

type Comment struct {
	Body string

	CreatedAt *metav1.Time
}

Comment is a comment body

type Commit

type Commit struct {
	SHA       string
	Message   string
	Author    User
	Committer User
}

Commit is a commit structure

type CommitStatus

type CommitStatus struct {
	Context     string
	State       CommitStatusState
	Description string
	TargetURL   string
}

CommitStatus is a commit status body

type CommitStatusState

type CommitStatusState string

CommitStatusState is a commit status type

type Diff

type Diff struct {
	Changes []Change
}

Diff is a diff between commits or of a pull-request

type EventType

type EventType string

EventType is a type of webhook event

type Head struct {
	Ref string
	Sha string
}

Head is a reference for head commit

type Issue

type Issue struct {
	PullRequest *PullRequest
}

Issue is an issue related to the Comment

type IssueComment

type IssueComment struct {
	Comment     Comment
	Issue       Issue
	Author      User
	ReviewState PullRequestReviewState
}

IssueComment is a common structure for issue comment

type IssueLabel

type IssueLabel struct {
	Name string
}

IssueLabel is a label struct

type IssueType

type IssueType string

IssueType is a type of the issue

type LinkHeader

type LinkHeader []LinkHeaderEntry

LinkHeader is a header list for "Link"

func ParseLinkHeader

func ParseLinkHeader(h string) LinkHeader

ParseLinkHeader parses url, rel from the header "Link"

func (LinkHeader) Find

func (l LinkHeader) Find(rel string) *LinkHeaderEntry

Find finds a rel from the LinkHeader

type LinkHeaderEntry

type LinkHeaderEntry struct {
	URL string
	Rel string
}

LinkHeaderEntry is an entry for a LinkHeader

type MergeMethod

type MergeMethod string

MergeMethod is method kind

type PullRequest

type PullRequest struct {
	ID        int
	Title     string
	State     PullRequestState
	Action    PullRequestAction
	Author    User
	URL       string
	Base      Base
	Head      Head
	Labels    []IssueLabel
	Mergeable bool

	// LabelChanged
	LabelChanged []IssueLabel
}

PullRequest is a common structure for pull request events

type PullRequestAction

type PullRequestAction string

PullRequestAction is an action of the pull request event

type PullRequestReviewState

type PullRequestReviewState string

PullRequestReviewState is a state of the pr's review

type PullRequestState

type PullRequestState string

PullRequestState is a state of the pull request

type Push

type Push struct {
	Ref string
	Sha string
}

Push is a common structure for push events

type Repository

type Repository struct {
	Name string
	URL  string
}

Repository is a repository of the git

type UnauthorizedError

type UnauthorizedError struct {
	User string
	Repo string
}

UnauthorizedError is an error struct for git clients

func (*UnauthorizedError) Error

func (e *UnauthorizedError) Error() string

Error returns error string

type User

type User struct {
	ID    int
	Name  string
	Email string
}

User is who triggered the event

type Webhook

type Webhook struct {
	EventType EventType
	Repo      Repository
	Sender    User

	Push         *Push
	PullRequest  *PullRequest
	IssueComment *IssueComment
}

Webhook is a common structure for git webhooks github-specific or gitlab-specific webhook bodies are converted to this structure before being consumed

type WebhookEntry

type WebhookEntry struct {
	ID  int
	URL string
}

WebhookEntry is a body of registered webhook list

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL