github

package
v0.0.0-...-5952ad4 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2017 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DescribeUser

func DescribeUser(u *github.User) string

DescribeUser returns the Login string, which may be nil.

func GetLabelsWithPrefix

func GetLabelsWithPrefix(labels []github.Label, prefix string) []string

GetLabelsWithPrefix will return a slice of all label names in `labels` which start with given prefix.

func SetCombinedStatusLifetime

func SetCombinedStatusLifetime(lifetime time.Duration)

SetCombinedStatusLifetime will set the lifetime of CombinedStatus responses. Even though we would likely use conditional API calls hitting the CombinedStatus API every time we want to get a specific value is just too mean to github. This defaults to `combinedStatusLifetime` seconds. If you are doing local testing you may want to make this (much) shorter

Types

type Config

type Config struct {
	Org     string
	Project string
	Url     string

	State  string
	Labels []string

	TokenFile string
	TokenObj  *oauth2.Token

	Address string // if a munger runs a web server, where it should live
	WWWRoot string

	HTTPCacheDir  string
	HTTPCacheSize uint64

	MinPRNumber int
	MaxPRNumber int

	// If true, don't make any mutating API calls
	DryRun bool

	// Base sleep time for retry loops. Defaults to 1 second.
	BaseWaitTime time.Duration

	// Webhook configuration
	HookHandler *WebHook
	GithubKey   string `json:"-"`
	// contains filtered or unexported fields
}

Config is how we are configured to talk to github and provides access methods for doing so.

func (*Config) AddLabel

func (config *Config) AddLabel(label *github.Label) error

AddLabel adds a single github label to the repository.

func (*Config) AddRootFlags

func (config *Config) AddRootFlags(cmd *cobra.Command)

AddRootFlags will add all of the flags needed for the github config to the cobra command

func (*Config) ForEachIssueDo

func (config *Config) ForEachIssueDo(fn MungeFunction) error

ForEachIssueDo will run for each Issue in the project that matches:

  • pr.Number >= minPRNumber
  • pr.Number <= maxPRNumber

func (*Config) GetBranchCommits

func (config *Config) GetBranchCommits(branch string, limit int) ([]*github.RepositoryCommit, error)

GetBranchCommits gets recent commits for the given branch.

func (*Config) GetDebugStats

func (config *Config) GetDebugStats() DebugStats

GetDebugStats returns information about the bot iself. Things like how many API calls has it made, how many of each type, etc.

func (*Config) GetLabels

func (config *Config) GetLabels() ([]*github.Label, error)

GetLabels grabs all labels from a particular repository so you don't have to worry about paging.

func (*Config) GetObject

func (config *Config) GetObject(num int) (*MungeObject, error)

GetObject will return an object (with only the issue filled in)

func (*Config) GetUser

func (config *Config) GetUser(login string) (*github.User, error)

GetUser will return information about the github user with the given login name

func (*Config) ListAllIssues

func (config *Config) ListAllIssues(listOpts *github.IssueListByRepoOptions) ([]*github.Issue, error)

ListAllIssues grabs all issues matching the options, so you don't have to worry about paging. Enforces some constraints, like min/max PR number and having a valid user.

func (*Config) ListMilestones

func (config *Config) ListMilestones(state string) ([]*github.Milestone, bool)

ListMilestones will return all milestones of the given `state`

func (*Config) NewIssue

func (config *Config) NewIssue(title, body string, labels []string, owners []string) (*MungeObject, error)

NewIssue will file a new issue and return an object for it. If "owners" is not empty, the issue will be assigned to the owners.

func (*Config) NextExpectedUpdate

func (config *Config) NextExpectedUpdate(t time.Time)

NextExpectedUpdate will set the debug information concerning when the mungers are likely to run again.

func (*Config) PreExecute

func (config *Config) PreExecute() error

PreExecute will initialize the Config. It MUST be run before the config may be used to get information from Github

func (*Config) ResetAPICount

func (config *Config) ResetAPICount()

ResetAPICount will both reset the counters of how many api calls have been made but will also print the information from the last run.

func (*Config) ServeDebugStats

func (config *Config) ServeDebugStats(path string)

ServeDebugStats will serve out debug information at the path

func (*Config) SetBranchProtection

func (config *Config) SetBranchProtection(name string, contexts []string) error

SetBranchProtection protects a branch and sets the required contexts

func (*Config) SetClient

func (config *Config) SetClient(client *github.Client)

SetClient should ONLY be used by testing. Normal commands should use PreExecute()

func (*Config) Token

func (config *Config) Token() string

Token returns the token

func (*Config) UsersWithAccess

func (config *Config) UsersWithAccess() ([]*github.User, []*github.User, error)

UsersWithAccess returns two sets of users. The first set are users with push access. The second set is the specific set of user with pull access. If the repo is public all users will have pull access, but some with have it explicitly

type DebugStats

type DebugStats struct {
	Analytics      analytics
	APIPerSec      float64
	APICount       int
	CachedAPICount int
	NextLoopTime   time.Time
	LimitRemaining int
	LimitResetTime time.Time
}

DebugStats is a structure that tells information about how we have interacted with github

type MungeFunction

type MungeFunction func(*MungeObject) error

MungeFunction is the type that must be implemented and passed to ForEachIssueDo

type MungeObject

type MungeObject struct {
	Issue *github.Issue

	Annotations map[string]string //annotations are things you can set yourself.
	// contains filtered or unexported fields
}

MungeObject is the object that mungers deal with. It is a combination of different github API objects.

func NewTestObject

func NewTestObject(config *Config, issue *github.Issue, pr *github.PullRequest, commits []*github.RepositoryCommit, events []*github.IssueEvent) *MungeObject

NewTestObject should NEVER be used outside of _test.go code. It creates a MungeObject with the given fields. Normally these should be filled in lazily as needed

func (*MungeObject) AddAssignee

func (obj *MungeObject) AddAssignee(owner string) error

AddAssignee will assign `prNum` to the `owner` where the `owner` is asignee's github login

func (*MungeObject) AddLabel

func (obj *MungeObject) AddLabel(label string) error

AddLabel adds a single `label` to the issue

func (*MungeObject) AddLabels

func (obj *MungeObject) AddLabels(labels []string) error

AddLabels will add all of the named `labels` to the issue

func (*MungeObject) Branch

func (obj *MungeObject) Branch() (string, bool)

Branch returns the branch the PR is for. Return "" if this is not a PR or it does not have the required information.

func (*MungeObject) CloseIssuef

func (obj *MungeObject) CloseIssuef(format string, args ...interface{}) error

CloseIssuef will close the given issue with a message

func (*MungeObject) ClosePR

func (obj *MungeObject) ClosePR() bool

ClosePR will close the Given PR

func (*MungeObject) DeleteComment

func (obj *MungeObject) DeleteComment(comment *github.IssueComment) error

DeleteComment will remove the specified comment

func (*MungeObject) EditComment

func (obj *MungeObject) EditComment(comment *github.IssueComment, body string) error

EditComment will change the specified comment's body.

func (*MungeObject) FirstLabelTime

func (obj *MungeObject) FirstLabelTime(label string) *time.Time

FirstLabelTime returns the first time the request label was added to an issue. If the label was never added you will get a nil time.

func (*MungeObject) GetCommits

func (obj *MungeObject) GetCommits() ([]*github.RepositoryCommit, bool)

GetCommits returns all of the commits for a given PR

func (*MungeObject) GetEvents

func (obj *MungeObject) GetEvents() ([]*github.IssueEvent, bool)

GetEvents returns a list of all events for a given pr.

func (*MungeObject) GetFileContents

func (obj *MungeObject) GetFileContents(file, sha string) (string, error)

GetFileContents will return the contents of the `file` in the repo at `sha` as a string

func (*MungeObject) GetHeadAndBase

func (obj *MungeObject) GetHeadAndBase() (headSHA, baseRef string, ok bool)

GetHeadAndBase returns the head SHA and the base ref, so that you can get the base's sha in a second step. Purpose: if head and base SHA are the same across two merge attempts, we don't need to rerun tests.

func (*MungeObject) GetPR

func (obj *MungeObject) GetPR() (*github.PullRequest, bool)

GetPR will return the PR of the object.

func (*MungeObject) GetPRFixesList

func (obj *MungeObject) GetPRFixesList() []int

GetPRFixesList returns a list of issue numbers that are referenced in the PR body.

func (*MungeObject) GetSHAFromRef

func (obj *MungeObject) GetSHAFromRef(ref string) (sha string, ok bool)

GetSHAFromRef returns the current SHA of the given ref (i.e., branch).

func (*MungeObject) GetStatus

func (obj *MungeObject) GetStatus(context string) (*github.RepoStatus, bool)

GetStatus returns the actual requested status, or nil if not found

func (*MungeObject) GetStatusState

func (obj *MungeObject) GetStatusState(requiredContexts []string) (string, bool)

GetStatusState gets the current status of a PR.

  • If any member of the 'requiredContexts' list is missing, it is 'incomplete'
  • If any is 'pending', the PR is 'pending'
  • If any is 'error', the PR is in 'error'
  • If any is 'failure', the PR is 'failure'
  • Otherwise the PR is 'success'

func (*MungeObject) GetStatusTime

func (obj *MungeObject) GetStatusTime(context string) (*time.Time, bool)

GetStatusTime returns when the status was set

func (*MungeObject) HasLabel

func (obj *MungeObject) HasLabel(name string) bool

HasLabel returns if the label `name` is in the array of `labels`

func (*MungeObject) HasLabels

func (obj *MungeObject) HasLabels(names []string) bool

HasLabels returns if all of the label `names` are in the array of `labels`

func (*MungeObject) IsForBranch

func (obj *MungeObject) IsForBranch(branch string) (bool, bool)

IsForBranch return true if the object is a PR for a branch with the given name. It return false if it is not a pr, it isn't against the given branch, or we can't tell

func (*MungeObject) IsMergeable

func (obj *MungeObject) IsMergeable() (bool, bool)

IsMergeable will return if the PR is mergeable. It will pause and get the PR again if github did not respond the first time. So the hopefully github will have a response the second time. If we have no answer twice, we return false

func (*MungeObject) IsMerged

func (obj *MungeObject) IsMerged() (bool, bool)

IsMerged returns if the issue in question was already merged

func (*MungeObject) IsPR

func (obj *MungeObject) IsPR() bool

IsPR returns if the obj is a PR or an Issue.

func (*MungeObject) IsStatusSuccess

func (obj *MungeObject) IsStatusSuccess(requiredContexts []string) (bool, bool)

IsStatusSuccess makes sure that the combined status for all commits in a PR is 'success'

func (*MungeObject) LabelCreator

func (obj *MungeObject) LabelCreator(label string) (string, bool)

LabelCreator returns the login name of the user who (last) created the given label

func (*MungeObject) LabelSet

func (obj *MungeObject) LabelSet() sets.String

LabelSet returns the name of all of the labels applied to the object as a kubernetes string set.

func (*MungeObject) LabelTime

func (obj *MungeObject) LabelTime(label string) (*time.Time, bool)

LabelTime returns the last time the request label was added to an issue. If the label was never added you will get a nil time.

func (*MungeObject) LastModifiedTime

func (obj *MungeObject) LastModifiedTime() (*time.Time, bool)

LastModifiedTime returns the time the last commit was made BUG: this should probably return the last time a git push happened or something like that.

func (*MungeObject) ListComments

func (obj *MungeObject) ListComments() ([]*github.IssueComment, bool)

ListComments returns all comments for the issue/PR in question

func (*MungeObject) ListFiles

func (obj *MungeObject) ListFiles() ([]*github.CommitFile, bool)

ListFiles returns all changed files in a pull-request

func (*MungeObject) ListReviewComments

func (obj *MungeObject) ListReviewComments() ([]*github.PullRequestComment, bool)

ListReviewComments returns all review (diff) comments for the PR in question

func (*MungeObject) ListReviews

func (obj *MungeObject) ListReviews() ([]*github.PullRequestReview, bool)

ListReviews returns a list of the Pull Request Reviews on a PR.

func (*MungeObject) MergeCommit

func (obj *MungeObject) MergeCommit() (*string, bool)

MergeCommit will return the sha of the merge. PRs which have not merged (or if we hit an error) will return nil

func (*MungeObject) MergePR

func (obj *MungeObject) MergePR(who string) bool

MergePR will merge the given PR, duh "who" is who is doing the merging, like "submit-queue"

func (*MungeObject) MergedAt

func (obj *MungeObject) MergedAt() (*time.Time, bool)

MergedAt returns the time an issue was merged (for nil if unmerged)

func (*MungeObject) ModifiedAfterLabeled

func (obj *MungeObject) ModifiedAfterLabeled(label string) (after bool, ok bool)

ModifiedAfterLabeled returns true if the PR was updated after the last time the label was applied.

func (*MungeObject) Number

func (obj *MungeObject) Number() int

Number is short for *obj.Issue.Number.

func (*MungeObject) OpenPR

func (obj *MungeObject) OpenPR(numTries int) bool

OpenPR will attempt to open the given PR. It will attempt to reopen the pr `numTries` before returning an error and giving up.

func (*MungeObject) Org

func (obj *MungeObject) Org() string

Org is getter for obj.config.Org

func (*MungeObject) Priority

func (obj *MungeObject) Priority() int

Priority returns the priority an issue was labeled with. The labels must take the form 'priority/[pP][0-9]+' or math.MaxInt32 if unset

If a PR has both priority/p0 and priority/p1 it will be considered a p0.

func (*MungeObject) Project

func (obj *MungeObject) Project() string

Project is getter for obj.config.Project

func (*MungeObject) Refresh

func (obj *MungeObject) Refresh() bool

Refresh will refresh the Issue (and PR if this is a PR) (not the commits or events)

func (*MungeObject) ReleaseMilestone

func (obj *MungeObject) ReleaseMilestone() (string, bool)

ReleaseMilestone returns the name of the 'release' milestone or an empty string if none found. Release milestones are determined by the format "vX.Y"

func (*MungeObject) ReleaseMilestoneDue

func (obj *MungeObject) ReleaseMilestoneDue() (time.Time, bool)

ReleaseMilestoneDue returns the due date for a milestone. It ONLY looks at milestones of the form 'vX.Y' where X and Y are integeters. Return the maximum possible time if there is no milestone or the milestone doesn't look like a release milestone

func (*MungeObject) RemoveAssignees

func (obj *MungeObject) RemoveAssignees(assignees ...string) error

RemoveAssignees removes the passed-in assignees from the github PR's assignees list

func (*MungeObject) RemoveLabel

func (obj *MungeObject) RemoveLabel(label string) error

RemoveLabel will remove the `label` from the PR

func (*MungeObject) SetMilestone

func (obj *MungeObject) SetMilestone(title string) bool

SetMilestone will set the milestone to the value specified

func (*MungeObject) SetStatus

func (obj *MungeObject) SetStatus(state, url, description, statusContext string) bool

SetStatus allowes you to set the Github Status

func (*MungeObject) WaitForNotPending

func (obj *MungeObject) WaitForNotPending(requiredContexts []string) bool

WaitForNotPending will check if the github status is "pending" (CI still running) if so it will sleep and try again until all required status hooks have complete returns true if it completed and false if it timed out

func (*MungeObject) WaitForPending

func (obj *MungeObject) WaitForPending(requiredContexts []string) bool

WaitForPending will wait for a PR to move into Pending. This is useful because the request to test a PR again is asynchronous with the PR actually moving into a pending state returns true if it completed and false if it timed out

func (*MungeObject) WriteComment

func (obj *MungeObject) WriteComment(msg string) error

WriteComment will send the `msg` as a comment to the specified PR

type StatusChange

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

StatusChange keeps track of issue/commit for status changes

func NewStatusChange

func NewStatusChange() *StatusChange

NewStatusChange creates a new status change tracker

func (*StatusChange) CommitStatusChanged

func (s *StatusChange) CommitStatusChanged(commit string)

CommitStatusChanged must be called when the status for this commit has changed

func (*StatusChange) PopChangedPullRequests

func (s *StatusChange) PopChangedPullRequests() []int

PopChangedPullRequests returns the list of issues changed since last call

func (*StatusChange) UpdatePullRequestHead

func (s *StatusChange) UpdatePullRequestHead(pullRequestID int, newHead string)

UpdatePullRequestHead updates the head commit for a pull-request

type WebHook

type WebHook struct {
	GithubKey string `json:"-"`
	Status    *StatusChange
}

WebHook listen for events and list changed issues asynchronously

func NewWebHookAndListen

func NewWebHookAndListen(githubKey string, address string) *WebHook

NewWebHookAndListen creates a new WebHook and listen to it

func (*WebHook) Listen

func (webhook *WebHook) Listen(address string)

Listen receives webhooks.

func (*WebHook) PopIssues

func (webhook *WebHook) PopIssues() []int

PopIssues returns the list of issues that changed since last time it was called

func (WebHook) ServeHTTP

func (webhook WebHook) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP receives the webhook, and process it

func (*WebHook) UpdatePullRequest

func (webhook *WebHook) UpdatePullRequest(id int, head string)

UpdatePullRequest will add the pull-request's last commit

type WithListOpt

WithListOpt configures the options to list comments of github issue.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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