tasks

package
v0.0.0-...-d8ca063 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package tasks contains a list of tasks that can be run with the bot.

All tasks in this package should satisfy the maintainerbot.Task interface.

// 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
    })
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CLAChecker

type CLAChecker struct {
	// Return true from CanSkipCLA to post a "CLA not necessary" success message
	// on matching PR's. If nil, all PR's are assumed to need a CLA.
	CanSkipCLA func(*github.PullRequest, []*github.CommitFile) bool
	// contains filtered or unexported fields
}

CLAChecker can fetch and validate that pull request authors have signed a CLA.

func NewCLAChecker

func NewCLAChecker(ghc *github.Client, claURL string, fetcher ContributorFetcher) *CLAChecker

func (*CLAChecker) Do

func (c *CLAChecker) Do(ctx context.Context, repo *maintner.GitHubRepo) error

Do checks whether every open pull request in the repository has been submitted by a user who signed the CLA. If not, Do posts a failing Status Check on the pull request build until the user signs the CLA.

func (*CLAChecker) StartFetch

func (c *CLAChecker) StartFetch(ctx context.Context)

StartFetch will begin periodically fetching contributors from the background repository, until the provided context is canceled.

type CongratsData

type CongratsData struct {
	Username string
}

CongratsData is the field that gets rendered into the template provided by NewCongratulator. More fields may be added.

type Congratulator

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

Congratulator congratulates new contributors, and posts a welcome message on the first PR they opened against the project.

To avoid posting the same message multiple times, Congratulator uses a label ("new-contributor") to track when it has already posted a message on a given pull request.

Example
package main

import (
	"context"
	"os"

	"github.com/sourcegraph/maintainerbot"
	"github.com/sourcegraph/maintainerbot/tasks"
)

func main() {
	ghc := maintainerbot.NewGitHubClient(os.Getenv("GITHUB_TOKEN"), 0)
	bot := maintainerbot.New("rails", "rails", os.Getenv("GITHUB_TOKEN"))
	task := tasks.NewCongratulator(ghc, "Congrats on your first PR, @{{ .Username }}!")
	bot.RegisterTask(task)
	bot.Run(context.TODO())
}
Output:

func NewCongratulator

func NewCongratulator(ghc *github.Client, templ string) *Congratulator

NewCongratulator returns a new Congratulator. templ should be a message to post on the pull request. You can use markdown or HTML in templ, as long as Github will accept it.

In addition, you can use the fields on CongratsData as fields in your template. For example, you could write "Congrats, @{{ .Username }}!" and Congratulator will substitute in the contributor's username when the comment is posted.

func (*Congratulator) Do

type ContributorFetcher

type ContributorFetcher interface {
	LoadContributors(ctx context.Context) ([]string, error)
}

ContributorFetcher is any struct that can fetch and return a list of contributors that have signed the CLA. You can provide a custom implementation in CLAChecker, or use the provided SpreadsheetFetcher to fetch from a Google Sheet.

type SpreadsheetFetcher

type SpreadsheetFetcher struct {

	// Column name to match against, defaults to "Github Username", matches are
	// case insensitive.
	ColumnName string
	// contains filtered or unexported fields
}

SpreadsheetFetcher fetches data from a Google spreadsheet. The SpreadsheetFetcher will search for the first column in the document that contains "Github Username" in the cell in the column's first row. For example, if the CSV looks like:

Name,Address,Twitch Username,Your Github Username
Kevin,"123 Main St",kevintwitch,kevinburke

We would read usernames from the rightmost column in the document.

func NewSpreadsheetFetcher

func NewSpreadsheetFetcher(sheetURL string) *SpreadsheetFetcher

NewSpreadsheetFetcher creates a SpreadsheetFetcher that can fetch usernames from the given spreadsheet.

sheetURL should be the CSV url for a given Google spreadsheet, something like:

"https://docs.google.com/spreadsheets/d/<key>/export?format=csv&sheet=0"

where "key" is unique for each spreadsheet and "sheet=0" would be the first sheet in the document.

func (*SpreadsheetFetcher) LoadContributors

func (s *SpreadsheetFetcher) LoadContributors(ctx context.Context) ([]string, error)

LoadContributors satisfies the ContributorFetcher interface. In particular, it fetches the provided sheetURL in NewSpreadsheetFetcher, then searches for the first column with a first row that contains SpreadsheetFetcher.ColumnName. All subsequent rows in that column are returned.

Jump to

Keyboard shortcuts

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