Skip to content

Commit

Permalink
Merge pull request #794 from suzuki-shunsuke/fix/set-config-base
Browse files Browse the repository at this point in the history
fix: set config base before getting associated prs
  • Loading branch information
suzuki-shunsuke authored Feb 14, 2023
2 parents 8bb7c3a + 83de84f commit 8d4eda2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
22 changes: 11 additions & 11 deletions pkg/api/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ type ExecController struct {
}

func (ctrl *ExecController) Exec(ctx context.Context, opts *option.ExecOptions) error { //nolint:funlen,cyclop
cfg := ctrl.Config

if cfg.Base != nil {
if opts.Org == "" {
opts.Org = cfg.Base.Org
}
if opts.Repo == "" {
opts.Repo = cfg.Base.Repo
}
}

if ctrl.Platform != nil {
if err := ctrl.Platform.ComplementExec(opts); err != nil {
return fmt.Errorf("complement opts with CI built in environment variables: %w", err)
Expand All @@ -53,17 +64,6 @@ func (ctrl *ExecController) Exec(ctx context.Context, opts *option.ExecOptions)
}
}

cfg := ctrl.Config

if cfg.Base != nil {
if opts.Org == "" {
opts.Org = cfg.Base.Org
}
if opts.Repo == "" {
opts.Repo = cfg.Base.Repo
}
}

result, execErr := ctrl.Executor.Run(ctx, &execute.Params{
Cmd: opts.Args[0],
Args: opts.Args[1:],
Expand Down
23 changes: 12 additions & 11 deletions pkg/api/hide.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ func (ctrl *HideController) Hide(ctx context.Context, opts *option.HideOptions)

func (ctrl *HideController) getParamListHiddenComments(ctx context.Context, opts *option.HideOptions) (*ParamListHiddenComments, error) { //nolint:cyclop,funlen
param := &ParamListHiddenComments{}

cfg := ctrl.Config

if cfg.Base != nil {
if opts.Org == "" {
opts.Org = cfg.Base.Org
}
if opts.Repo == "" {
opts.Repo = cfg.Base.Repo
}
}

if ctrl.Platform != nil {
if err := ctrl.Platform.ComplementHide(opts); err != nil {
return nil, fmt.Errorf("failed to complement opts with platform built in environment variables: %w", err)
Expand All @@ -70,17 +82,6 @@ func (ctrl *HideController) getParamListHiddenComments(ctx context.Context, opts
}
}

cfg := ctrl.Config

if cfg.Base != nil {
if opts.Org == "" {
opts.Org = cfg.Base.Org
}
if opts.Repo == "" {
opts.Repo = cfg.Base.Repo
}
}

if err := option.ValidateHide(opts); err != nil {
return param, fmt.Errorf("opts is invalid: %w", err)
}
Expand Down
21 changes: 10 additions & 11 deletions pkg/api/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ type Platform interface {
}

func (ctrl *PostController) getCommentParams(ctx context.Context, opts *option.PostOptions) (*github.Comment, error) { //nolint:funlen,cyclop,gocognit
cfg := ctrl.Config

if cfg.Base != nil {
if opts.Org == "" {
opts.Org = cfg.Base.Org
}
if opts.Repo == "" {
opts.Repo = cfg.Base.Repo
}
}
if ctrl.Platform != nil {
if err := ctrl.Platform.ComplementPost(opts); err != nil {
return nil, fmt.Errorf("failed to complement opts with platform built in environment variables: %w", err)
Expand Down Expand Up @@ -180,17 +190,6 @@ func (ctrl *PostController) getCommentParams(ctx context.Context, opts *option.P
opts.Template = tpl
}

cfg := ctrl.Config

if cfg.Base != nil {
if opts.Org == "" {
opts.Org = cfg.Base.Org
}
if opts.Repo == "" {
opts.Repo = cfg.Base.Repo
}
}

if err := option.ValidatePost(opts); err != nil {
return nil, fmt.Errorf("opts is invalid: %w", err)
}
Expand Down

0 comments on commit 8d4eda2

Please sign in to comment.