github.com/bitrise-io/bitrise-step-update-gitops-repository@v0.0.0-20240426081835-1466be593380/pkg/gitops/config.go (about)

     1  package gitops
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/bitrise-io/go-steputils/stepconf"
     7  	"gopkg.in/yaml.v3"
     8  )
     9  
    10  type config struct {
    11  	// DeployRepositoryURL is the URL of the deployment (GitOps) repository.
    12  	DeployRepositoryURL string `env:"deploy_repository_url,required"`
    13  	// DeployFolder is the folder to render templates to in the deploy repository.
    14  	DeployFolder string `env:"deploy_path,required"`
    15  	// DeployBranch is the branch to render templates to in the deploy repository.
    16  	DeployBranch string `env:"deploy_branch,required"`
    17  	// PullRequest won't push to the branch. It will open a PR only instead.
    18  	PullRequest bool `env:"pull_request"`
    19  	// PullRequestTitle is the title of the opened pull request.
    20  	PullRequestTitle string `env:"pull_request_title"`
    21  	// PullRequestBody is the body of the opened pull request.
    22  	PullRequestBody string `env:"pull_request_body"`
    23  	// RawValues are unparsed version of `Values` field (to-be-parsed manually).
    24  	RawValues string `env:"values"`
    25  	// Values are values applied to the template files.
    26  	Values map[string]string
    27  	// TemplatesFolder is the path to the deployment templates folder.
    28  	TemplatesFolder string `env:"templates_folder_path,dir"`
    29  	// DeployToken is the Personal Access Token to interact with Github API.
    30  	DeployToken stepconf.Secret `env:"deploy_token,required"`
    31  	// DeployUser is the username associated with the Personal Access Token.
    32  	DeployUser string `env:"deploy_user"`
    33  	// CommitMessage is the created commit's message.
    34  	CommitMessage string `env:"commit_message,required"`
    35  }
    36  
    37  // NewConfig returns a new configuration initialized from environment variables.
    38  func NewConfig() (config, error) {
    39  	var cfg config
    40  	if err := stepconf.Parse(&cfg); err != nil {
    41  		return config{}, fmt.Errorf("parse step config: %w", err)
    42  	}
    43  
    44  	return cfg, yaml.Unmarshal([]byte(cfg.RawValues), &cfg.Values)
    45  }