updater

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommitInput

type CommitInput struct {
	Repo               string        // e.g. my-org/my-repo
	Filename           string        // relative path to the file in the repository
	Branch             string        // e.g. main
	BranchGenerateName string        // e.g. gitops-
	DisablePRCreation  bool          // Whether to disable PR creation
	CreateMissing      bool          // Whether to create the target file if it's missing
	RemoveFile         bool          // Whether to remove the target file
	CommitMessage      string        // This is used for the commit when updating the file
	Signature          scm.Signature // This identifies a git commit creator
}

CommitInput is used to configure the commit and pull request.

type ContentUpdater

type ContentUpdater func([]byte) ([]byte, error)

ContentUpdater takes an existing body, it should transform it, and return the updated body.

func RemoveYAMLKey

func RemoveYAMLKey(key string) ContentUpdater

RemoveYAMLKey is a ContentUpdater that removes the target key from a YAML file value, the key can be a dotted path.

RemoveYAMLKey("test.value")

func ReplaceContents

func ReplaceContents(b []byte) ContentUpdater

ReplaceContents is a ContentUpdater that replaces the content of file with the provided body.

func UpdateYAML

func UpdateYAML(key string, newValue interface{}) ContentUpdater

UpdateYAML is a ContentUpdater that updates a YAML file using a key and new value, the key can be a dotted path.

UpdateYAML("test.value", []string{"test", "value"})

type GitUpdater

type GitUpdater interface {
	ApplyUpdateToFile(ctx context.Context, input CommitInput, f ContentUpdater) (string, error)
	CreatePR(ctx context.Context, input PullRequestInput) (*scm.PullRequest, error)
}

GitUpdater defines the way to apply changes to files in Git.

type PullRequestInput

type PullRequestInput struct {
	SourceBranch string // e.g. 'main'
	NewBranch    string
	Repo         string // e.g. my-org/my-repo
	Title        string
	Body         string
}

PullRequestInput provides configuration for the PullRequest to be opened.

type Updater

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

Updater can update a Git repo with an updated version of a file.

func New

func New(l logr.Logger, c client.GitClient, opts ...UpdaterFunc) *Updater

New creates and returns a new Updater.

func (*Updater) ApplyUpdateToFile

func (u *Updater) ApplyUpdateToFile(ctx context.Context, input CommitInput, f ContentUpdater) (string, error)

ApplyUpdateToFile does the job of fetching a file, passing it to a user-provided function if not deleting it, and optionally creating a PR.

func (*Updater) CreatePR

func (u *Updater) CreatePR(ctx context.Context, input PullRequestInput) (*scm.PullRequest, error)

type UpdaterFunc

type UpdaterFunc func(u *Updater)

UpdaterFunc is an option for for creating new Updaters.

func NameGenerator

func NameGenerator(g names.Generator) UpdaterFunc

NameGenerator is an option func for the Updater creation function.

Jump to

Keyboard shortcuts

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