thirdparty

package
v0.0.0-...-366f0b0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2019 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NumGithubRetries    = 5
	GithubSleepTimeSecs = 1 * time.Second
	GithubStatusBase    = "https://status.github.com"
	GithubAccessURL     = "https://github.com/login/oauth/access_token"

	GithubAPIStatusMinor = "minor"
	GithubAPIStatusMajor = "major"
	GithubAPIStatusGood  = "good"

	Github502Error = "502 Server Error"
)

Variables

View Source
var (
	MaxRedirects = 10
)

Functions

func CheckGithubAPILimit

func CheckGithubAPILimit(ctx context.Context, oauthToken string) (int64, error)

CheckGithubAPILimit queries Github for the number of API requests remaining

func FormGitUrl

func FormGitUrl(host, owner, repo, token string) string

func GetBranchEvent

func GetBranchEvent(ctx context.Context, oauthToken, repoOwner, repo, branch string) (*github.Branch, error)

GetBranchEvent gets the head of the a given branch via an API call to GitHub

func GetCommitEvent

func GetCommitEvent(ctx context.Context, oauthToken, repoOwner, repo, githash string) (*github.RepositoryCommit, error)

func GetGithubCommits

func GetGithubCommits(ctx context.Context, oauthToken, owner, repo, ref string, commitPage int) ([]*github.RepositoryCommit, int, error)

GetGithubCommits returns a slice of GithubCommit objects from the given commitsURL when provided a valid oauth token

func GetGithubFile

func GetGithubFile(ctx context.Context, oauthToken, owner, repo, path, hash string) (*github.RepositoryContent, error)

GetGithubFile returns a struct that contains the contents of files within a repository as Base64 encoded content.

func GetGithubMergeBaseRevision

func GetGithubMergeBaseRevision(ctx context.Context, oauthToken, repoOwner, repo, baseRevision, currentCommitHash string) (string, error)

func GetGithubPullRequest

func GetGithubPullRequest(ctx context.Context, token, baseOwner, baseRepo string, PRNumber int) (*github.PullRequest, error)

func GetGithubPullRequestDiff

func GetGithubPullRequestDiff(ctx context.Context, token string, gh patch.GithubPatch) (string, []patch.Summary, error)

GetGithubDiff downloads a diff from a Github Pull Request diff. This function does not use go-github because this operation is not supported

func GetGithubUser

func GetGithubUser(ctx context.Context, oauthToken, loginName string) (*github.User, error)

GetGithubUser fetches the github user with the given login name

func GetPatchSummaries

func GetPatchSummaries(patchContent string) ([]patch.Summary, error)

func GetPullRequestMergeBase

func GetPullRequestMergeBase(ctx context.Context, token string, data patch.GithubPatch) (string, error)

GetPullRequestMergeBase returns the merge base hash for the given PR. This function will retry up to 5 times, regardless of error response (unless error is the result of hitting an api limit)

func GitApplyNumstat

func GitApplyNumstat(patch string) (*bytes.Buffer, error)

GitApplyNumstat attempts to apply a given patch; it returns the patch's bytes if it is successful

func GitHubUserPermissionLevel

func GitHubUserPermissionLevel(ctx context.Context, token, owner, repo, username string) (string, error)

func GithubUserInOrganization

func GithubUserInOrganization(ctx context.Context, token, requiredOrganization, username string) (bool, error)

GithubUserInOrganization returns true if the given github user is in the given organization. The user with the attached token must have visibility into organization membership, including private members

func IsFileNotFound

func IsFileNotFound(err error) bool

func ParseGitSummary

func ParseGitSummary(gitOutput fmt.Stringer) (summaries []patch.Summary, err error)

ParseGitSummary takes in a buffer of data and parses it into a slice of git summaries. It returns an error if it is unable to parse the data

func ParseGitUrl

func ParseGitUrl(url string) (string, string, error)

func ValidatePR

func ValidatePR(pr *github.PullRequest) error

Types

type APIRequestError

type APIRequestError struct {
	Message          string `json:"message"`
	DocumentationUrl string `json:"documentation_url"`
}

When attempting to access the some API using authentication, requests may return 404 Not Found, instead of 403 Forbidden, under certain circumstances. For example, see https://developer.github.com/v3/#authentication. This struct should be used for errors in fetching a requested remote config.

func (APIRequestError) Error

func (are APIRequestError) Error() string

type APIResponseError

type APIResponseError struct {
	// contains filtered or unexported fields
}

func (APIResponseError) Error

func (are APIResponseError) Error() string

type APIUnmarshalError

type APIUnmarshalError struct {
	// contains filtered or unexported fields
}

func (APIUnmarshalError) Error

func (ue APIUnmarshalError) Error() string

type FileDecodeError

type FileDecodeError struct {
	Message string
}

func (FileDecodeError) Error

func (f FileDecodeError) Error() string

type FileNotFoundError

type FileNotFoundError struct {
	// contains filtered or unexported fields
}

This error should be returned when the requested remote configuration file can not be found.

func (FileNotFoundError) Error

func (nfe FileNotFoundError) Error() string

type GithubAuthParameters

type GithubAuthParameters struct {
	ClientId     string `json:"client_id"`
	ClientSecret string `json:"client_secret"`
	Code         string `json:"code"`
	RedirectUri  string `json:"redirect_uri"`
	State        string `json:"state"`
}

type GithubAuthResponse

type GithubAuthResponse struct {
	AccessToken string `json:"access_token"`
	Scope       string `json:"scope"`
	TokenType   string `json:"token_type"`
}

func GithubAuthenticate

func GithubAuthenticate(ctx context.Context, code, clientId, clientSecret string) (githubResponse *GithubAuthResponse, err error)

GithubAuthenticate does a POST to github with the code that it received, the ClientId, ClientSecret And returns the response which contains the accessToken associated with the user.

type GithubLoginUser

type GithubLoginUser struct {
	Login            string
	Id               int
	Company          string
	EmailAddress     string `json:"email"`
	Name             string
	OrganizationsURL string
}

func GetGithubTokenUser

func GetGithubTokenUser(ctx context.Context, token string, requiredOrg string) (*GithubLoginUser, bool, error)

GetGithubTokenUser fetches a github user associated with an oauth token, and if requiredOrg is specified, checks that it belongs to that org. Returns user object, if it was a member of the specified org (or false if not specified), and error

func (*GithubLoginUser) DisplayName

func (u *GithubLoginUser) DisplayName() string

func (*GithubLoginUser) Email

func (u *GithubLoginUser) Email() string

func (*GithubLoginUser) GetAPIKey

func (u *GithubLoginUser) GetAPIKey() string

func (*GithubLoginUser) IsNil

func (u *GithubLoginUser) IsNil() bool

func (*GithubLoginUser) Roles

func (u *GithubLoginUser) Roles() []string

func (*GithubLoginUser) Username

func (u *GithubLoginUser) Username() string

type JiraCreateTicketResponse

type JiraCreateTicketResponse struct {
	Id   string `json:"id"`
	Key  string `json:"key"`
	Self string `json:"self"`
}

JiraCreateTicketResponse contains the results of a JIRA create ticket API call.

type JiraHandler

type JiraHandler struct {
	MyHttp     httpClient
	JiraServer string
	UserName   string
	Password   string
}

func NewJiraHandler

func NewJiraHandler(server string, user string, password string) JiraHandler

func (*JiraHandler) CreateTicket

func (jiraHandler *JiraHandler) CreateTicket(fields map[string]interface{}) (*JiraCreateTicketResponse, error)

CreateTicket takes a map of fields to initialize a JIRA ticket with. Returns a response containing the new ticket's key, id, and API URL. See the JIRA API documentation for help.

func (*JiraHandler) GetJIRATicket

func (jiraHandler *JiraHandler) GetJIRATicket(key string) (*JiraTicket, error)

GetJIRATicket returns the ticket with the given key.

func (*JiraHandler) JQLSearch

func (jiraHandler *JiraHandler) JQLSearch(query string, startAt, maxResults int) (*JiraSearchResults, error)

JQLSearch runs the given JQL query against the given jira instance and returns the results in a JiraSearchResults

func (*JiraHandler) JQLSearchAll

func (jiraHandler *JiraHandler) JQLSearchAll(query string) ([]JiraTicket, error)

JQLSearchAll performs repeated JQL searches until the query has been exhausted

func (*JiraHandler) JiraHost

func (jiraHandler *JiraHandler) JiraHost() string

JiraHost returns the hostname of the jira service as configured.

func (*JiraHandler) UpdateTicket

func (jiraHandler *JiraHandler) UpdateTicket(key string, fields map[string]interface{}) error

UpdateTicket sets the given fields of the ticket with the given key. Returns any errors JIRA returns.

type JiraProject

type JiraProject struct {
	Id         string            `json:"id"`
	Self       string            `json:"self"`
	Key        string            `json:"key"`
	Name       string            `json:"name"`
	AvatarUrls map[string]string `json:"avatarUrls"`
}

type JiraResolution

type JiraResolution struct {
	Id          string `json:"id"`
	Self        string `json:"self"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

type JiraSearchResults

type JiraSearchResults struct {
	Expand     string       `json:"expand"`
	StartAt    int          `json:"startAt"`
	MaxResults int          `json:"maxResults"`
	Total      int          `json:"total"`
	Issues     []JiraTicket `json:"issues"`
}

JiraSearchResults marshal to and unmarshal from the json search results returned by the rest api at /rest/api/2/search?jql={jql}

type JiraStatus

type JiraStatus struct {
	Id   string `json:"id"`
	Self string `json:"self"`
	Name string `json:"name"`
}

type JiraTicket

type JiraTicket struct {
	Key    string        `json:"key"`
	Expand string        `json:"expand"`
	Fields *TicketFields `json:"fields"`
}

JiraTickets marshal to and unmarshal from the json issue returned by the rest api at /rest/api/latest/issue/{ticket_id}

type ResponseReadError

type ResponseReadError struct {
	// contains filtered or unexported fields
}

func (ResponseReadError) Error

func (re ResponseReadError) Error() string

type TicketFields

type TicketFields struct {
	IssueType   *TicketType     `json:"issuetype"`
	Summary     string          `json:"summary"`
	Description string          `json:"description"`
	Reporter    *User           `json:"reporter"`
	Assignee    *User           `json:"assignee"`
	Project     *JiraProject    `json:"project"`
	Resolution  *JiraResolution `json:"resolution"`
	Created     string          `json:"created"`
	Updated     string          `json:"updated"`
	Status      *JiraStatus     `json:"status"`
}

type TicketType

type TicketType struct {
	Id          string `json:"id"`
	Self        string `json:"self"`
	Description string `json:"description"`
	IconUrl     string `json:"iconUrl"`
	Name        string `json:"name"`
	Subtask     bool   `json:"subtask"`
}

type User

type User struct {
	Id           string            `json:"id"`
	Self         string            `json:"self"`
	Name         string            `json:"name"`
	EmailAddress string            `json:"emailAddress"`
	DisplayName  string            `json:"displayName"`
	Active       bool              `json:"active"`
	TimeZone     string            `json:"timeZone"`
	AvatarUrls   map[string]string `json:"avatarUrls"`
}

type YAMLFormatError

type YAMLFormatError struct {
	Message string
}

func (YAMLFormatError) Error

func (y YAMLFormatError) Error() string

Jump to

Keyboard shortcuts

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