Documentation ¶
Overview ¶
Package maintainerbot contains tools for running automated tasks on a Github repo.
Call maintainerbot.New() to create a new bot, then register tasks on it with bot.RegisterTask(). Finally, bot.Run() will run the tasks in a loop, calling each Task periodically. The Task can do whatever it needs to do to update the repository as it sees fit.
Example ¶
package main import ( "context" "os" "time" "github.com/sourcegraph/maintainerbot" "github.com/sourcegraph/maintainerbot/tasks" ) func main() { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond) defer cancel() token := os.Getenv("GITHUB_TOKEN") ghc := maintainerbot.NewGitHubClient(token, 0) bot := maintainerbot.New("golang", "go", token) spreadsheetURL := "https://docs.google.com/spreadsheets/d/<key>/export?format=csv&sheet=0" cla := tasks.NewCLAChecker(ghc, "http://example.com/sign-cla", tasks.NewSpreadsheetFetcher(spreadsheetURL)) cla.StartFetch(ctx) congrats := tasks.NewCongratulator(ghc, "Congrats, @{{ .Username }}!") bot.RegisterTask(cla) bot.RegisterTask(congrats) bot.Run(ctx) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Bot ¶
type Bot struct { // Directory for caching local data about issues and pull requests. // Defaults to $HOME/var/maintainerbot. DataDir string // Interval between queries to send to GitHub. Defaults to 720ms, which // works out to 5000 queries per hour. GitHubRateLimit time.Duration // contains filtered or unexported fields }
func (*Bot) RegisterTask ¶
RegisterTask registers t with the bot. When the Bot is running, t will be called periodically with the latest repo contents.
type Task ¶
type Task interface {
Do(ctx context.Context, repo *maintner.GitHubRepo) error
}
Task is any periodic task that you would like to run on the repository.
Example ¶
package main import ( "context" "os" "strings" maintainerbot "github.com/sourcegraph/maintainerbot" "golang.org/x/build/maintner" ) type docTask struct{} // Do labels each GitHub issue containing the word "doc" in the title with the // "Documentation" label. func (d *docTask) Do(ctx context.Context, repo *maintner.GitHubRepo) error { return repo.ForeachIssue(func(gi *maintner.GitHubIssue) error { if gi.Closed || gi.PullRequest || !strings.Contains(gi.Title, "doc") || gi.HasLabel("Documentation") { return nil } // Issue needs a "documentation" label, add it here. return nil }) } func main() { d := &docTask{} bot := maintainerbot.New("rails", "rails", os.Getenv("GITHUB_TOKEN")) bot.RegisterTask(d) bot.Run(context.TODO()) }
Output:
Directories ¶
Path | Synopsis |
---|---|
The sgbot command runs automated tasks against the Sourcegraph Github repo.
|
The sgbot command runs automated tasks against the Sourcegraph Github repo. |
Package tasks contains a list of tasks that can be run with the bot.
|
Package tasks contains a list of tasks that can be run with the bot. |
Click to show internal directories.
Click to hide internal directories.