Documentation ¶
Index ¶
- func DescribeUser(u *github.User) string
- func GetLabelsWithPrefix(labels []github.Label, prefix string) []string
- func SetCombinedStatusLifetime(lifetime time.Duration)
- type Config
- func (config *Config) AddLabel(label *github.Label) error
- func (config *Config) AddRootFlags(cmd *cobra.Command)
- func (config *Config) ForEachIssueDo(fn MungeFunction) error
- func (config *Config) GetBranchCommits(branch string, limit int) ([]*github.RepositoryCommit, error)
- func (config *Config) GetDebugStats() DebugStats
- func (config *Config) GetLabels() ([]*github.Label, error)
- func (config *Config) GetObject(num int) (*MungeObject, error)
- func (config *Config) GetUser(login string) (*github.User, error)
- func (config *Config) ListAllIssues(listOpts *github.IssueListByRepoOptions) ([]*github.Issue, error)
- func (config *Config) ListMilestones(state string) ([]*github.Milestone, bool)
- func (config *Config) NewIssue(title, body string, labels []string, owner string) (*MungeObject, error)
- func (config *Config) NextExpectedUpdate(t time.Time)
- func (config *Config) PreExecute() error
- func (config *Config) ResetAPICount()
- func (config *Config) ServeDebugStats(path string)
- func (config *Config) SetBranchProtection(name string, contexts []string) error
- func (config *Config) SetClient(client *github.Client)
- func (config *Config) Token() string
- func (config *Config) UsersWithAccess() ([]*github.User, []*github.User, error)
- type DebugStats
- type MungeFunction
- type MungeObject
- func (obj *MungeObject) AddLabel(label string) error
- func (obj *MungeObject) AddLabels(labels []string) error
- func (obj *MungeObject) AssignPR(owner string) error
- func (obj *MungeObject) Branch() (string, bool)
- func (obj *MungeObject) CloseIssuef(format string, args ...interface{}) error
- func (obj *MungeObject) ClosePR() bool
- func (obj *MungeObject) DeleteComment(comment *github.IssueComment) error
- func (obj *MungeObject) EditComment(comment *github.IssueComment, body string) error
- func (obj *MungeObject) FirstLabelTime(label string) *time.Time
- func (obj *MungeObject) GetCommits() ([]*github.RepositoryCommit, bool)
- func (obj *MungeObject) GetEvents() ([]*github.IssueEvent, bool)
- func (obj *MungeObject) GetFileContents(file, sha string) (string, error)
- func (obj *MungeObject) GetHeadAndBase() (headSHA, baseRef string, ok bool)
- func (obj *MungeObject) GetPR() (*github.PullRequest, bool)
- func (obj *MungeObject) GetPRFixesList() []int
- func (obj *MungeObject) GetSHAFromRef(ref string) (sha string, ok bool)
- func (obj *MungeObject) GetStatus(context string) (*github.RepoStatus, bool)
- func (obj *MungeObject) GetStatusState(requiredContexts []string) (string, bool)
- func (obj *MungeObject) GetStatusTime(context string) (*time.Time, bool)
- func (obj *MungeObject) HasLabel(name string) bool
- func (obj *MungeObject) HasLabels(names []string) bool
- func (obj *MungeObject) IsForBranch(branch string) (bool, bool)
- func (obj *MungeObject) IsMergeable() (bool, bool)
- func (obj *MungeObject) IsMerged() (bool, bool)
- func (obj *MungeObject) IsPR() bool
- func (obj *MungeObject) IsStatusSuccess(requiredContexts []string) (bool, bool)
- func (obj *MungeObject) LabelCreator(label string) (string, bool)
- func (obj *MungeObject) LabelSet() sets.String
- func (obj *MungeObject) LabelTime(label string) (*time.Time, bool)
- func (obj *MungeObject) LastModifiedTime() (*time.Time, bool)
- func (obj *MungeObject) ListComments(withListOpts ...WithListOpt) ([]*github.IssueComment, bool)
- func (obj *MungeObject) ListFiles() ([]*github.CommitFile, bool)
- func (obj *MungeObject) ListReviewComments() ([]*github.PullRequestComment, bool)
- func (obj *MungeObject) MergeCommit() (*string, bool)
- func (obj *MungeObject) MergePR(who string) bool
- func (obj *MungeObject) MergedAt() (*time.Time, bool)
- func (obj *MungeObject) ModifiedAfterLabeled(label string) (after bool, ok bool)
- func (obj *MungeObject) Number() int
- func (obj *MungeObject) OpenPR(numTries int) bool
- func (obj *MungeObject) Priority() int
- func (obj *MungeObject) Refresh() bool
- func (obj *MungeObject) ReleaseMilestone() (string, bool)
- func (obj *MungeObject) ReleaseMilestoneDue() (time.Time, bool)
- func (obj *MungeObject) RemoveLabel(label string) error
- func (obj *MungeObject) SetMilestone(title string) bool
- func (obj *MungeObject) SetStatus(state, url, description, context string) bool
- func (obj *MungeObject) UnassignPR(assignees ...string) error
- func (obj *MungeObject) WaitForNotPending(requiredContexts []string) bool
- func (obj *MungeObject) WaitForPending(requiredContexts []string) bool
- func (obj *MungeObject) WriteComment(msg string) error
- type WithListOpt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DescribeUser ¶
DescribeUser returns the Login string, which may be nil.
func GetLabelsWithPrefix ¶
GetLabelsWithPrefix will return a slice of all label names in `labels` which start with given prefix.
func SetCombinedStatusLifetime ¶
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 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 // contains filtered or unexported fields }
Config is how we are configured to talk to github and provides access methods for doing so.
func (*Config) AddRootFlags ¶
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 ¶
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 ¶
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 ¶
ListMilestones will return all milestones of the given `state`
func (*Config) NewIssue ¶
func (config *Config) NewIssue(title, body string, labels []string, owner string) (*MungeObject, error)
NewIssue will file a new issue and return an object for it. If "owner" is not empty, the issue will be assigned to "owner".
func (*Config) NextExpectedUpdate ¶
NextExpectedUpdate will set the debug information concerning when the mungers are likely to run again.
func (*Config) PreExecute ¶
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 ¶
ServeDebugStats will serve out debug information at the path
func (*Config) SetBranchProtection ¶
SetBranchProtection protects a branch and sets the required contexts
func (*Config) SetClient ¶
SetClient should ONLY be used by testing. Normal commands should use PreExecute()
func (*Config) UsersWithAccess ¶
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 TestObject ¶
func TestObject(config *Config, issue *github.Issue, pr *github.PullRequest, commits []*github.RepositoryCommit, events []*github.IssueEvent) *MungeObject
TestObject 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) 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) AssignPR ¶
func (obj *MungeObject) AssignPR(owner string) error
AssignPR will assign `prNum` to the `owner` where the `owner` is asignee's github login
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(withListOpts ...WithListOpt) ([]*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) 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) 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) 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) 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, context string) bool
SetStatus allowes you to set the Github Status
func (*MungeObject) UnassignPR ¶
func (obj *MungeObject) UnassignPR(assignees ...string) error
UnassignPR removes the passed-in assignees from the github PR's assignees list
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 WithListOpt ¶
type WithListOpt func(*github.IssueListCommentsOptions) *github.IssueListCommentsOptions
WithListOpt configures the options to list comments of github issue.