auto-reply

module
v0.0.0-...-2443087 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: BSD-3-Clause

README

auto-reply

An open source gardener. This is a technology for powering GitHub bots. It's really rough around the edges but it currently powers @jekyllbot.

Build Status

Configuring

If you want to configure a secret to validate your payload from GitHub, then set it as the environment variable GITHUB_WEBHOOK_SECRET. This is the same value you enter in the web interface when setting up the "Secret" for your webhook.

I could use your thoughts on this! Currently, it's a hodge-podge. The documentation for each package will provide more details on this. Currently we have the following packages, with varying levels of configuration:

  • affinity – assigns issues based on team mentions and those team captains. See Jekyll's docs for more info.
  • autopull – detects pushes to branches which start with pull/ and automatically creates a PR for them
  • chlog – creates GitHub releases when a new tag is pushed, and powers "@jekyllbot: merge (+category)"
  • jekyll/deprecate – comments on and closes issues to issues on certain repos with a per-repo stock message
  • jekyll/issuecomment – provides handlers for removing pending-feedback and stale labels when a comment comes through
  • labeler – removes pending-rebase label when a PR is pushed to and is mergeable (and helper functions for manipulating labels)
  • lgtm – adds a jekyllbot/lgtm CI status and handles LGTM counting

Installing

This is intended for use with servers, so you'd do something like:

package main

import (
	"flag"
	"log"
	"net/http"

	"github.com/parkr/auto-reply/affinity"
	"github.com/parkr/auto-reply/ctx"
	"github.com/parkr/auto-reply/hooks"
)

var context *ctx.Context

func main() {
	var port string
	flag.StringVar(&port, "port", "8080", "The port to serve to")
	flag.Parse()
	context = ctx.NewDefaultContext()

	http.HandleFunc("/_ping", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "text/plain")
		w.Write([]byte("ok\n"))
	}))

	// Add your event handlers. Check out the documentation for the
	// github.com/parkr/auto-reply/hooks package to see all supported events.
	eventHandlers := hooks.EventHandlerMap{}

	// Build the affinity handler.
	aff := &affinity.Handler{}
	aff.AddRepo("myorg", "myproject")
	aff.AddTeam(context, 123) // @myorg/performance
	aff.AddTeam(context, 456) // @myorg/documentation

	// Add the affinity handler's various event handlers to the event handlers map :)
	eventHandlers.AddHandler(hooks.IssuesEvent, aff.AssignIssueToAffinityTeamCaptain)
	eventHandlers.AddHandler(hooks.IssueCommentEvent, aff.AssignIssueToAffinityTeamCaptainFromComment)
	eventHandlers.AddHandler(hooks.PullRequestEvent, aff.RequestReviewFromAffinityTeamCaptain)

	// Create the webhook handler. GlobalHandler takes the list of event handlers from
	// its configuration and fires each of them based on the X-GitHub-Event header from
	// the webhook payload.
	myOrgHandler := &hooks.GlobalHandler{
		Context:       context,
		EventHandlers: eventHandlers,
	}
	http.Handle("/_github/myproject", myOrgHandler)

	log.Printf("Listening on :%s", port)
	log.Fatal(http.ListenAndServe(":"+port, nil))
}

Writing Custom Handlers

For now, all you have to do is write a function which satisfies the hooks.EventHandler type. At the moment, each handler can accept only one type of event. If you want to accept the issue_comment event, then you should be able to perform a successful type assertion:

func MyIssueCommentHandler(context *ctx.Context, payload interface{}) error {
    event, err := payload.(*github.IssueCommentEvent)
    if err != nil {
        return context.NewError("MyIssueCommentHandler: hm, didn't get an IssueCommentEvent: %v", err)
    }

    // Handle your issue comment event in a type-safe way here.
}

Then you register that with your project. Taking the two examples above, you'd add MyIssueCommentHandler to the eventHandlers[hooks.IssueCommentEvent] array:

eventHandlers := hooks.EventHandlerMap{}
eventHandlers.AddHandler(hooks.IssueCommentEvent, MyIssueCommentHandler)

And it should work!

Optional: Mark-and-sweep Stale Issues

One big issue we have in Jekyll is "stale" issues, that is, issues which were opened and abandoned after a few months of activity. The code in cmd/mark-and-sweep-stale-issues is still Jekyll-specific but I'd love a PR which abstracts out the configuration into a file or something!

License

This code is licensed under BSD 3-clause as specified in the LICENSE file in this repository.

Directories

Path Synopsis
affinity assigns issues based on team mentions and those team captains.
affinity assigns issues based on team mentions and those team captains.
auth provides a means of determining use permissions on GitHub.com for repositories.
auth provides a means of determining use permissions on GitHub.com for repositories.
autopull provides a webhook which will automatically create pull requests for a push to a special branch name prefix.
autopull provides a webhook which will automatically create pull requests for a push to a special branch name prefix.
chlog provides a means of acting on the repository changelog.
chlog provides a means of acting on the repository changelog.
cmd
check-for-outdated-dependencies
check-for-outdated-dependencies takes a repo
check-for-outdated-dependencies takes a repo
freeze-ancient-issues
A command-line utility to lock old issues.
A command-line utility to lock old issues.
jekyllbot
jekyllbot is the server which controls @jekyllbot on GitHub.
jekyllbot is the server which controls @jekyllbot on GitHub.
mark-and-sweep-stale-issues
A command-line utility to mark and sweep Jekyll issues for staleness.
A command-line utility to mark and sweep Jekyll issues for staleness.
unearth
A command-line utility to run a search query and display results.
A command-line utility to run a search query and display results.
unify-labels
unify-labels is a CLI which will add, rename, or change the color of labels so they match the Jekyll org's requirements.
unify-labels is a CLI which will add, rename, or change the color of labels so they match the Jekyll org's requirements.
common is a library I made because I was lazy and didn't know better.
common is a library I made because I was lazy and didn't know better.
ctx is magic; it is basically my own "context" package before I realized that "context" existed.
ctx is magic; it is basically my own "context" package before I realized that "context" existed.
hooks is the entrypoint for this project: it handles the GitHub webhooks and funnels the data into the various action functions registered to it.
hooks is the entrypoint for this project: it handles the GitHub webhooks and funnels the data into the various action functions registered to it.
jekyll is the configuration of handlers and such specific to the org's requirements.
jekyll is the configuration of handlers and such specific to the org's requirements.
deprecate
deprecate closes issues on deprecated repos and leaves a nice comment for the user.
deprecate closes issues on deprecated repos and leaves a nice comment for the user.
issuecomment
issuecomment has 2 handlers: one to unlabel stale issues, and one to remove the pending-feedback label.
issuecomment has 2 handlers: one to unlabel stale issues, and one to remove the pending-feedback label.
SOMEWHAT DEPRECATED: labeler provides actions which add labels to issues based on criteria.
SOMEWHAT DEPRECATED: labeler provides actions which add labels to issues based on criteria.
lgtm contains the functionality to handle approval from maintainers.
lgtm contains the functionality to handle approval from maintainers.

Jump to

Keyboard shortcuts

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