Skip to content

Commit

Permalink
Merge pull request #23 from dtchanpura/max_args-flag
Browse files Browse the repository at this point in the history
Maximum Arguments Flag at Project level
  • Loading branch information
dtchanpura authored Aug 10, 2020
2 parents 3205946 + d244618 commit 0a503ff
Show file tree
Hide file tree
Showing 7 changed files with 305 additions and 38 deletions.
9 changes: 2 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
language: go
go:
- "1.11.x"
- "1.x"

install: true

# Don't email me the results of the test runs.
notifications:
email: false
email: false

before_script:
- GO111MODULE=on make bootstrap
- GO_FILES=$(find . -iname '*.go' -type f | grep -v /vendor/) # All the .go files, excluding vendor/

script:
- GO111MODULE=on make test
# - test -z $(gofmt -s -l $GO_FILES) # Fail if a .go file hasn't been formatted with gofmt
# - go vet ./... # go vet is the official Go static analyzer
# - megacheck ./... # "go vet on steroids" + linter
# - gocyclo -over 19 $GO_FILES # forbid code with huge functions
# - golint -set_exit_status $(go list ./...) # one last linter

before_deploy:
- GO111MODULE=on make VERSION=${TRAVIS_TAG} clean release -j2
Expand Down
3 changes: 3 additions & 0 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

var (
name string
maxargs int
hooks []string
preHook string
postHook string
Expand All @@ -45,6 +46,7 @@ var addCmd = &cobra.Command{
// // project.Tokens = []Token{}
project := config.NewProject(cidr...)
project.Name = name
project.MaxArgs = maxargs
project.Hooks = config.NewHooks(hooks...)
project.PreHook = preHook
project.PostHook = postHook
Expand Down Expand Up @@ -82,6 +84,7 @@ func init() {
os.Exit(1)
}
addCmd.Flags().StringVar(&name, "name", "", "Name of project.")
addCmd.Flags().IntVar(&maxargs, "max-args", 0, "Maximum arguments limit for each of the hooks in the project.")
addCmd.Flags().StringArrayVar(&hooks, "hook", []string{}, "Path to script to be executed on webhook call.")
addCmd.Flags().StringVar(&preHook, "pre-hook", "", "Path to script to be executed before the event.")
addCmd.Flags().StringVar(&postHook, "post-hook", "", "Path to script to be executed after the event.")
Expand Down
10 changes: 8 additions & 2 deletions config/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ func DecodeProjectConfiguration(settingsMap map[string]interface{}) error {
projectStruct.UUID = value.(string)
case "secret":
projectStruct.Secret = value.(string)
case "max_args":
projectStruct.MaxArgs = value.(int)
case "hooks":
projectStruct.Hooks = []Hook{}
for _, v := range value.([]interface{}) {
Expand Down Expand Up @@ -258,9 +260,13 @@ func (project *Project) ExecuteHooks(args ...string) {
// Following is the replacement for above code.
if len(project.Hooks) > 0 {
for _, hook := range project.Hooks {
allowedMaxArgs := project.MaxArgs
if hook.MaxArgs != 0 {
allowedMaxArgs = hook.MaxArgs
}
maxArgs := len(args)
if hook.MaxArgs != -1 {
maxArgs = hook.MaxArgs
if allowedMaxArgs != -1 {
maxArgs = allowedMaxArgs
}
if hook.FilePath != "" {
// TODO: Change this project.WorkDir
Expand Down
1 change: 1 addition & 0 deletions config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Project struct {
Secret string `yaml:"secret" json:"secret"`
Tokens []TokenDetail `yaml:"tokens" json:"tokens"`
Hooks []Hook `yaml:"hooks,omitempty" json:"hooks,omitempty"`
MaxArgs int `yaml:"max_args,omitempty" json:"max_args,omitempty"`
// Following part has been removed as we will be adding all related things in PreHook or PostHook
// RemotePath string `yaml:"remote_path" json:"remote_path"` // For downloading
}
Expand Down
22 changes: 17 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ module github.com/dtchanpura/deployment-agent
go 1.12

require (
github.com/fsnotify/fsnotify v1.4.7
github.com/gin-gonic/gin v1.4.0
github.com/fsnotify/fsnotify v1.4.9
github.com/gin-gonic/gin v1.6.3
github.com/go-playground/validator/v10 v10.3.0 // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/google/uuid v1.1.1
github.com/json-iterator/go v1.1.10 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v0.0.5
github.com/spf13/viper v1.4.0
gopkg.in/yaml.v2 v2.2.2
github.com/mitchellh/mapstructure v1.3.3 // indirect
github.com/pelletier/go-toml v1.8.0 // indirect
github.com/spf13/afero v1.3.4 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.7.1
golang.org/x/sys v0.0.0-20200808120158-1030fc2bf1d9 // indirect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/ini.v1 v1.57.0 // indirect
gopkg.in/yaml.v2 v2.3.0
)
Loading

0 comments on commit 0a503ff

Please sign in to comment.