github

package
v0.35.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const PULLREQUESTBODY = `
# {{ .Title }}

{{ if .Introduction }}
{{ .Introduction }}
{{ end }}


## Report

{{ .Report }}

## Changelog

<details><summary>Click to expand</summary>

` + "````\n{{ .Description }}\n````" + `

</details>

## Remark

This pull request was automatically created using [Updatecli](https://www.updatecli.io).

Please report any issues with this tool [here](https://github.com/updatecli/updatecli/issues/)

`

PULLREQUESTBODY is the pull request template used as pull request description Please note that triple backticks are concatenated with the literals, as they cannot be escaped

Variables

View Source
var (
	ErrAutomergeNotAllowOnRepository = errors.New("automerge is not allowed on repository")
	ErrBadMergeMethod                = errors.New("wrong merge method defined, accepting one of 'squash', 'merge', 'rebase', or ''")
)

Functions

This section is empty.

Types

type Changelog

type Changelog struct {
	Title       string
	Description string
	Report      string
}

Changelog contains various information used to describe target changes

type GitHubClient

type GitHubClient interface {
	Query(ctx context.Context, q interface{}, variables map[string]interface{}) error
	Mutate(ctx context.Context, m interface{}, input githubv4.Input, variables map[string]interface{}) error
}

GitHubClient must be implemented by any GitHub query client (v4 API)

type Github

type Github struct {
	// Spec contains inputs coming from updatecli configuration
	Spec Spec
	// HeadBranch is used when creating a temporary branch before opening a PR
	HeadBranch string
	// contains filtered or unexported fields
}

Github contains settings to interact with Github

func New

func New(s Spec, pipelineID string) (*Github, error)

New returns a new valid Github object.

func (*Github) Add

func (g *Github) Add(files []string) error

Add run `git add`.

func (*Github) Changelog

func (g *Github) Changelog(version version.Version) (string, error)

Changelog returns a changelog description based on a release name

func (*Github) Checkout

func (g *Github) Checkout() error

Checkout create and then uses a temporary git branch.

func (*Github) Clean

func (g *Github) Clean() error

Clean deletes github working directory.

func (*Github) Clone

func (g *Github) Clone() (string, error)

Clone run `git clone`.

func (*Github) Commit

func (g *Github) Commit(message string) error

Commit run `git commit`.

func (*Github) GetChangedFiles

func (g *Github) GetChangedFiles(workingDir string) ([]string, error)

func (*Github) GetDirectory

func (g *Github) GetDirectory() (directory string)

GetDirectory returns the local git repository path.

func (*Github) Push

func (g *Github) Push() error

Push run `git push` then open a pull request on Github if not already created.

func (*Github) PushTag

func (g *Github) PushTag(tag string) error

PushTag push tags

func (*Github) SearchReleases

func (g *Github) SearchReleases() (releases []string, err error)

SearchReleases return every releases from the github api ordered by reverse order of created time. Draft and pre-releases are filtered out.

func (*Github) SearchTags

func (g *Github) SearchTags() (tags []string, err error)

SearchTags return every tags from the github api return in reverse order of commit tags.

type GithubHandler

type GithubHandler interface {
	SearchReleases() (releases []string, err error)
	SearchTags() (tags []string, err error)
	Changelog(version.Version) (string, error)
}

GithubHandler must be implemented by any GitHub module

type MockGitHubClient

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

func (*MockGitHubClient) Mutate

func (mock *MockGitHubClient) Mutate(ctx context.Context, m interface{}, input githubv4.Input, variables map[string]interface{}) error

func (*MockGitHubClient) Query

func (mock *MockGitHubClient) Query(ctx context.Context, q interface{}, variables map[string]interface{}) error

type PageInfo

type PageInfo struct {
	HasNextPage     bool
	HasPreviousPage bool
	EndCursor       string
	StartCursor     string
}

PageInfo is used for Graphql queries to iterate over pagination

type PullRequest

type PullRequest struct {
	Description string
	Report      string
	Title       string
	// contains filtered or unexported fields
}

func NewPullRequest

func NewPullRequest(spec PullRequestSpec, gh *Github) (PullRequest, error)

func (*PullRequest) CreatePullRequest

func (p *PullRequest) CreatePullRequest(title, changelog, pipelineReport string) error

func (*PullRequest) EnablePullRequestAutoMerge

func (p *PullRequest) EnablePullRequestAutoMerge() error

EnablePullRequestAutoMerge updates an existing pullrequest with the flag automerge

func (*PullRequest) GetPullRequestLabelsInformation

func (p *PullRequest) GetPullRequestLabelsInformation() ([]repositoryLabelApi, error)

getPullRequestLabelsInformation queries GitHub Api to retrieve every labels assigned to a pullRequest

func (*PullRequest) OpenPullRequest

func (p *PullRequest) OpenPullRequest() error

OpenPullRequest creates a new pull request on Github.

type PullRequestApi

type PullRequestApi struct {
	BaseRefName string
	Body        string
	HeadRefName string
	ID          string
	State       string
	Title       string
	Url         string
	Number      int
}

PullRequest contains multiple fields mapped to Github V4 api

type PullRequestSpec

type PullRequestSpec struct {
	// Specifies if automerge is enabled for the new pullrequest
	AutoMerge bool `yaml:",omitempty"`
	// Specifies pull request title
	Title string `yaml:",omitempty"`
	// Specifies user input description used during pull body creation
	Description string `yaml:",omitempty"`
	// Specifies repository labels used for pull request. !! Labels must already exist on the repository
	Labels []string `yaml:",omitempty"`
	// Specifies if a pull request is set to draft, default false
	Draft bool `yaml:",omitempty"`
	// Specifies if maintainer can modify pullRequest
	MaintainerCannotModify bool `yaml:",omitempty"`
	// Specifies which merge method is used to incorporate the pull request. Accept "merge", "squash", "rebase", or ""
	MergeMethod string `yaml:",omitempty"`
	// Specifies to use pull request title when using auto merge, only works for "squash" or "rebase"
	UseTitleForAutoMerge bool `yaml:",omitempty"`
}

PullRequestSpec is a specific struct containing pullrequest settings provided by an updatecli configuration

func (*PullRequestSpec) Validate

func (s *PullRequestSpec) Validate() error

Validate ensure that a pullrequest spec contains validate fields

type RateLimit

type RateLimit struct {
	Cost      int
	Remaining int
	ResetAt   string
}

RateLimit is a struct that contains Github Api limit information

func (*RateLimit) Show

func (a *RateLimit) Show()

Show display Github Api limit usage

type Spec

type Spec struct {
	// Branch specifies which github branch to work on
	Branch string `yaml:",omitempty"`
	// Directory specifies where the github repository is cloned on the local disk
	Directory string `yaml:",omitempty"`
	// Email specifies which emails to use when creating commits
	Email string `yaml:",omitempty"`
	// Owner specifies repository owner
	Owner string `yaml:",omitempty" jsonschema:"required"`
	// Repository specifies the name of a repository for a specific owner
	Repository string `yaml:",omitempty" jsonschema:"required"`
	// Token specifies the credential used to authenticate with
	Token string `yaml:",omitempty" jsonschema:"required"`
	// URL specifies the default github url in case of GitHub enterprise
	URL string `yaml:",omitempty"`
	// Username specifies the username used to authenticate with Github API
	Username string `yaml:",omitempty" jsonschema:"required"`
	// User specifies the user of the git commit messages
	User string `yaml:",omitempty"`
	// Deprecated since https://github.com/updatecli/updatecli/issues/260, must be clean up
	PullRequest PullRequestSpec `yaml:",omitempty"`
	// GPG key and passphrased used for commit signing
	GPG sign.GPGSpec `yaml:",omitempty"`
	// Force is used during the git push phase to run `git push --force`.
	Force bool `yaml:",omitempty"`
	// CommitMessage represents conventional commit metadata as type or scope, used to generate the final commit message.
	CommitMessage commit.Commit `yaml:",omitempty"`
}

Spec represents the configuration input

func (*Spec) Merge added in v0.28.0

func (gs *Spec) Merge(child interface{}) error

Merge returns nil if it successfully merges the child Spec into target receiver. Please note that child attributes always overrides receiver's

func (*Spec) MergeFromEnv added in v0.28.0

func (gs *Spec) MergeFromEnv(envPrefix string)

MergeFromEnv updates the target receiver with the "non zero-ed" environment variables

func (*Spec) SpecToPullRequestSpec

func (s *Spec) SpecToPullRequestSpec() interface{}

SpecToPullRequestSpec is a function that export the pullRequest spec from a GithubSpec to a PullRequest.Spec. It's temporary function until we totally remove the old scm configuration introduced by this https://github.com/updatecli/updatecli/pull/388

func (*Spec) Validate

func (s *Spec) Validate() (errs []error)

Validate verifies if mandatory Github parameters are provided and return false if not.

Jump to

Keyboard shortcuts

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