Skip to content

Commit

Permalink
Merge pull request #523 from suzuki-shunsuke/feat/remove-complement-2
Browse files Browse the repository at this point in the history
fix: remove the configuration complement and some template functions for security
  • Loading branch information
suzuki-shunsuke authored Sep 24, 2022
2 parents 6f9206c + 0974912 commit 64d3b0b
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 317 deletions.
5 changes: 2 additions & 3 deletions github-comment.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
post:
default: |
CIRCLE_PULL_REQUEST: {{Env "CIRCLE_PULL_REQUEST"}}
foo
hello:
# update: 'Comment.HasMeta && Comment.Meta.TemplateKey == "hello"'
template: |
$Hello: {{Env "HELLO"}} {{ "hello!" | upper | repeat 5 }}
$Hello: foo {{ "hello!" | upper | repeat 5 }}
exec:
hello:
Expand All @@ -18,7 +18,6 @@ exec:
combined output: {{.CombinedOutput}}
- when: true
template: |
$Hello: {{Env "HELLO"}}
exit code: {{.ExitCode}}
stdout: {{.Stdout}}
stderr: {{.Stderr}}
Expand Down
2 changes: 0 additions & 2 deletions pkg/api/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ func (ctrl *ExecController) Exec(ctx context.Context, opts *option.ExecOptions)
TemplateKey: opts.TemplateKey,
Template: opts.Template,
Vars: cfg.Vars,
Env: ctrl.Getenv,
}, templates); err != nil {
if !opts.Silent {
fmt.Fprintf(ctrl.Stderr, "github-comment error: %+v\n", err)
Expand All @@ -137,7 +136,6 @@ type ExecCommentParams struct {
Command string
JoinCommand string
ExitCode int
Env func(string) string
// PRNumber is the pull request number where the comment is posted
PRNumber int
// Org is the GitHub Organization or User name
Expand Down
4 changes: 1 addition & 3 deletions pkg/api/hide.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (ctrl *HideController) Hide(ctx context.Context, opts *option.HideOptions)
return err
}
nodeIDs, err := listHiddenComments(
ctx, ctrl.GitHub, ctrl.Expr, ctrl.Getenv, param, nil)
ctx, ctrl.GitHub, ctrl.Expr, param, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -139,7 +139,6 @@ type ParamListHiddenComments struct {
func listHiddenComments( //nolint:funlen
ctx context.Context,
gh GitHub, exp Expr,
getEnv func(string) string,
param *ParamListHiddenComments,
paramExpr map[string]interface{},
) ([]string, error) {
Expand Down Expand Up @@ -203,7 +202,6 @@ func listHiddenComments( //nolint:funlen
},
"HideKey": param.HideKey,
"Vars": param.Vars,
"Env": getEnv,
}
for k, v := range paramExpr {
paramMap[k] = v
Expand Down
1 change: 0 additions & 1 deletion pkg/api/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ func (ctrl *PostController) setUpdatedCommentID(ctx context.Context, cmt *github
"SHA1": cmt.SHA1,
},
"Vars": cmt.Vars,
"Env": ctrl.Getenv,
}

logrus.WithFields(logrus.Fields{
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/post_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestPostController_getCommentParams(t *testing.T) { //nolint:funlen
Repo: "github-comment",
Token: "xxx",
PRNumber: 1,
Template: `{{Env "FOO"}} {{.Org}} {{.Repo}} {{.PRNumber}}`,
Template: `{{.Org}} {{.Repo}} {{.PRNumber}}`,
},
},
exp: &github.Comment{
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (runner *Runner) execAction(c *cli.Context) error {
opts.SkipNoToken = opts.SkipNoToken || cfg.SkipNoToken
opts.Silent = opts.Silent || cfg.Silent

var pt api.Platform = platform.Get(getPlatformParam(cfg.Complement))
var pt api.Platform = platform.Get()

gh, err := getGitHub(c.Context, &opts.Options, cfg)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/hide.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (runner *Runner) hideAction(c *cli.Context) error {
}
opts.SkipNoToken = opts.SkipNoToken || cfg.SkipNoToken

var pt api.Platform = platform.Get(getPlatformParam(cfg.Complement))
var pt api.Platform = platform.Get()

gh, err := getGitHub(c.Context, &opts.Options, cfg)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (runner *Runner) postAction(c *cli.Context) error {
}
opts.SkipNoToken = opts.SkipNoToken || cfg.SkipNoToken

var pt api.Platform = platform.Get(getPlatformParam(cfg.Complement))
var pt api.Platform = platform.Get()

gh, err := getGitHub(c.Context, &opts.Options, cfg)
if err != nil {
Expand Down
19 changes: 0 additions & 19 deletions pkg/cmd/util.go

This file was deleted.

105 changes: 0 additions & 105 deletions pkg/config/complement.go

This file was deleted.

32 changes: 0 additions & 32 deletions pkg/config/complement_envsubst.go

This file was deleted.

43 changes: 0 additions & 43 deletions pkg/config/complement_template.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type Config struct {
Hide map[string]string
SkipNoToken bool `yaml:"skip_no_token"`
Silent bool
Complement *Complement
}

type Base struct {
Expand Down
Loading

0 comments on commit 64d3b0b

Please sign in to comment.