Skip to content

Commit

Permalink
upload the policy paramater if a user adds it (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
zlav committed Mar 20, 2020
1 parent 7458683 commit 6dee5c6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions api/fossa/upload.go
Expand Up @@ -30,6 +30,7 @@ type UploadOptions struct {
JIRAProjectKey string
Link string
Team string
Policy string
}

// Upload uploads a project's analysis.
Expand Down Expand Up @@ -77,6 +78,9 @@ func Upload(title string, locator Locator, options UploadOptions, data []SourceU
if options.Team != "" {
q.Add("team", options.Team)
}
if options.Policy != "" {
q.Add("policy", options.Policy)
}

endpoint, err := url.Parse("/api/builds/custom?" + q.Encode())
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/fossa/cmd/analyze/analyze.go
Expand Up @@ -165,6 +165,7 @@ func uploadAnalysis(normalized []fossa.SourceUnit) error {
JIRAProjectKey: config.JIRAProjectKey(),
Link: config.Link(),
Team: config.Team(),
Policy: config.Policy(),
},
normalized)
display.ClearProgress()
Expand Down
4 changes: 3 additions & 1 deletion cmd/fossa/flags/flags.go
Expand Up @@ -45,7 +45,7 @@ func WithAPIFlags(f []cli.Flag) []cli.Flag {
}

var (
API = []cli.Flag{EndpointF, TitleF, FetcherF, ProjectF, RevisionF, BranchF, ProjectURLF, JIRAProjectKeyF, LinkF, TeamF}
API = []cli.Flag{EndpointF, TitleF, FetcherF, ProjectF, RevisionF, BranchF, ProjectURLF, JIRAProjectKeyF, LinkF, TeamF, PolicyF}
Endpoint = "endpoint"
EndpointF = cli.StringFlag{Name: Short(Endpoint), Usage: "the FOSSA server endpoint (default: 'https://app.fossa.com')"}
Title = "title"
Expand All @@ -66,6 +66,8 @@ var (
LinkF = cli.StringFlag{Name: ShortUpper(Link), Usage: "a link to attach to the current build"}
Team = "team"
TeamF = cli.StringFlag{Name: ShortUpper(Team), Usage: "this repository's team inside your organization"}
Policy = "policy"
PolicyF = cli.StringFlag{Name: Policy, Usage: "the policy to assign to this project in FOSSA"}
)

func WithGlobalFlags(f []cli.Flag) []cli.Flag {
Expand Down
5 changes: 5 additions & 0 deletions config/file.go
Expand Up @@ -33,6 +33,7 @@ type File interface {
JIRAProjectKey() string
Link() string
Team() string
Policy() string

Modules() []module.Module
}
Expand Down Expand Up @@ -83,6 +84,10 @@ func (_ NoFile) Team() string {
return ""
}

func (_ NoFile) Policy() string {
return ""
}

func (_ NoFile) Revision() string {
return ""
}
Expand Down
7 changes: 6 additions & 1 deletion config/file.v1/file.go
Expand Up @@ -32,6 +32,7 @@ type CLIProperties struct {
JIRAProjectKey string `yaml:"jira_project_key,omitempty"` // Only used with custom fetcher
Link string `yaml:"link,omitempty"`
Team string `yaml:"team,omitempty"`
Policy string `yaml:"policy,omitempty"`
}

type AnalyzeProperties struct {
Expand Down Expand Up @@ -140,7 +141,11 @@ func (file File) Link() string {
}

func (file File) Team() string {
return file.CLI.Link
return file.CLI.Team
}

func (file File) Policy() string {
return file.CLI.Policy
}

func (file File) Revision() string {
Expand Down
4 changes: 4 additions & 0 deletions config/keys.go
Expand Up @@ -115,6 +115,10 @@ func Team() string {
return TryStrings(StringFlag(flags.Team), file.Team(), "")
}

func Policy() string {
return TryStrings(StringFlag(flags.Policy), file.Policy(), "")
}

/**** Analysis configuration keys ****/

func Options() (map[string]interface{}, error) {
Expand Down

0 comments on commit 6dee5c6

Please sign in to comment.