github

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2016 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package github provides a plugin for building Github integrations into github.com/ajm188/slack.

The package exports a number of package-wide variables, which may be used to configure the parameters used for authenticating with the Github API. See the documentation on each variable for what is is used for.

Here is an example of how one might use this library to register a hook that opens Github issues:

import (
    "github.com/ajm188/slack"
    "github.com/ajm188/slack/plugins/github"
)

func main() {
    bot := slack.NewBot(myToken)
    // configure auth for github plugin
    github.OpenIssue(bot, nil)
}

Index

Constants

This section is empty.

Variables

View Source
var (
	// ClientID is issued by Github when you register an application. You
	// should register an application for your bot, and set the ID before
	// creating a client to authenticate with Github.
	ClientID string
	// ClientSecret is the secret key used to verify your registered
	// application. You should set the secret before creating a client to
	// authenticate with Github.
	ClientSecret string
	// AccessToken is an OAuth token for the user you want your Github
	// interactions to be performed as. The bot will be commenting, opening
	// issues, etc as the user who owns this token. You should set an access
	// token before creating a client to authenticate with Github.
	AccessToken string
	// RedirectURL is the URL that Github should redirect to after a successful
	// web authentication. Since the bot does not perform web-based
	// authentication, this is likely a useless field. More information can be
	// found at https://developer.github.com/v3/oauth/#redirect-urls.
	RedirectURL string
	// Scopes is the list of scopes that the OAuth token should be limited
	// to. Since the user that created the token can specify the scopes
	// available to the token when they create it, this field is probably also
	// useless.
	Scopes []string
	// SharedClient is a variable for sharing a single OAuth client among
	// various handlers. For example, when a call to OpenIssue is made, you may
	// pass in a client of your own, if you want the issue hook to be handled
	// by a different Github user. If you do not pass in a client, then the
	// various hook methods will fall back to using this shared client.
	SharedClient *github.Client
)

Functions

func Config

func Config() *oauth2.Config

Config returns an oauth config object that can be used to generate a client for communicating with Github.

func DefaultClient

func DefaultClient() *github.Client

DefaultClient constructs a Github client based on the variables set in this package (ClientID, ClientSecret, AccessToken). This can be used to quickly create a client when you don't need any customization to the underlying oauth client. It uses the NoContext context from the oauth2 package. See the Token function for the Token it will use.

func OpenIssue

func OpenIssue(bot *slack.Bot, client *github.Client)

OpenIssue registers a handler that will cause the bot to open a github issue based on the event text.

The handler is registered as a "Respond", not a "Listen" (see the docs for github.com/ajm188/slack for the difference). The pattern which will cause the handler to fire has the form 'issue me // <owner>/<repo> "<title>" ("<body>" ("<assignee>")?)?'.

The function takes as arguments the bot to which it should register the handler, and a reference to a client that can authenticate with Github. If no client is provided, then OpenIssue will fall back to using the package-wide SharedClient.

Users should note that an attempt to assign an issue to a Github user that is not a "contributor" on the repository will result in a 422 returned by the Github API. This will prevent the issue from being created.

When an issue has successfully been created, the bot will reply to the user which triggered the handler with a link to the issue.

func Token

func Token() *oauth2.Token

Token constructs a basic token, with the bare minimum amount of information necessary to authenticate with Github. It uses the package-wide AccessToken, and sets the token to never expire. "TokenType" and "RefreshToken" fields are left blank.

Types

This section is empty.

Jump to

Keyboard shortcuts

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