githubrun

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

go-githubrun

go-githubrun is a Go library for parsing the event payload and default environment variables available to the Github workflow run instance.

Usage

import (
    "github.com/covertbyte/go-githubrun"
    "github.com/google/go-github/v32/github"
    "github.com/sethvargo/go-githubactions"
)

func main() {
    run, err := githubrun.ParseRun()
    if err != nil {
        githubactions.Fatalf("%w", err)
    }

    ctx := context.Background()
	ts := oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: run.Env.GithubToken},
	)
	tc := oauth2.NewClient(ctx, ts)
	client := github.NewClient(tc)

    pullRequest := run.Payload.(*github.PullRequestEvent).GetPullRequest()

    githubactions.DebugF("%s", pullRequest.GetBody())

    githubactions.DebugF("%s", run.Env.GithubEventName)
}

For API documentation see the Go docs.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Env

type Env struct {
	CI               bool
	Home             string
	GithubWorkflow   string
	GithubRunID      int64
	GithubRunNumber  int64
	GithubAction     string
	GithubActions    bool
	GithubActor      string
	GithubRepository string
	GithubEventName  string
	GithubEventPath  string
	GithubWorkspace  string
	GithubSHA        string
	GithubRef        string
	GithubHeadRef    string
	GithubBaseRef    string
	GithubToken      string
}

Env contains the default environment variables.

https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token

type Run

type Run struct {
	Env        Env
	Payload    interface{}
	Owner      string
	Repository string
}

Run represents a Github run.

https://help.github.com/en/actions/reference/events-that-trigger-workflows

func ParseRun

func ParseRun() (Run, error)

ParseRun parses the event payload and default environment variables. A struct containing the env variables, and payload of the corresponding struct type will be returned.

Jump to

Keyboard shortcuts

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