Skip to content

Commit

Permalink
fix(upload): Fix upload report link and API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
elldritch committed May 30, 2018
1 parent eb2d07d commit 9c77639
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
5 changes: 4 additions & 1 deletion api/fossa/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var (

// func UploadCustomProject(project, revision, title string, data []SourceUnit) {}

func Upload(fetcher, project, revision, title string, data []SourceUnit) (Locator, error) {
func Upload(fetcher, project, revision, title, branch string, data []SourceUnit) (Locator, error) {
// Check preconditions
if fetcher != "custom" && revision == "" {
log.Logger.Fatalf("Could not infer revision name from `git` remote named `origin`. To submit a custom project, set Fetcher to `custom` in `.fossa.yml`")
Expand All @@ -50,6 +50,9 @@ func Upload(fetcher, project, revision, title string, data []SourceUnit) (Locato
if fetcher == "custom" {
endpoint += fmt.Sprintf("&managedBuild=true&title=%s", url.PathEscape(title))
}
if branch != "" {
endpoint += fmt.Sprintf("&branch=%s", url.PathEscape(branch))
}
log.Logger.Debugf("Sending build data to %#v", endpoint)

res, statusCode, err := Post(endpoint, payload)
Expand Down
1 change: 1 addition & 0 deletions builders/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ func getGoImportsRecurse(builder *GoBuilder, m module.Module, memo map[string]st
stdout, ok := memo[pkg]
if !ok {
var err error
// TODO: error case for build tag exclusions -- we need to pass architecture flag
stdout, _, err = runLogged(m.Dir, builder.GoCmd, "list", "-f", "{{ join .Imports \"\\n\" }}", pkg)
if err != nil {
return nil, fmt.Errorf("could not trace imports: %s", err.Error())
Expand Down
8 changes: 6 additions & 2 deletions cmd/fossa/cmd/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ func Run(ctx *cli.Context) {
log.Logger.Fatalf("Upload failed: %s", err.Error())
}
baseURL, err := url.Parse(c.Endpoint)
reportURL, err := url.Parse("/projects/" + url.QueryEscape(locator.Fetcher+"+"+locator.Project) + "/refs/branch/" + c.Branch + "/" + url.QueryEscape(locator.Revision) + "/browse/dependencies")
reportBranch := c.Branch
if reportBranch == "" {
reportBranch = "master"
}
reportURL, err := url.Parse("/projects/" + url.QueryEscape(locator.Fetcher+"+"+locator.Project) + "/refs/branch/" + reportBranch + "/" + url.QueryEscape(locator.Revision) + "/browse/dependencies")
log.Printf(`
============================================================
Expand All @@ -128,5 +132,5 @@ func Do(c config.CLIConfig, data []fossa.SourceUnit) (fossa.Locator, error) {
title = c.Project
}

return fossa.Upload(c.Fetcher, c.Project, c.Revision, title, data)
return fossa.Upload(c.Fetcher, c.Project, c.Revision, title, c.Branch, data)
}
18 changes: 11 additions & 7 deletions cmd/fossa/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net/http"
"net/url"
"path/filepath"
"strings"

"github.com/urfave/cli"
Expand Down Expand Up @@ -152,13 +151,14 @@ func doUpload(conf config.CLIConfig, results []normalizedModule) (string, error)
log.Logger.Debugf("Uploading build data from (%#v) modules: %#v", len(results), string(buildData))

fossaEndpoint := "/api/builds/custom?locator=" + url.QueryEscape(module.Locator{Fetcher: conf.Fetcher, Project: conf.Project, Revision: conf.Revision}.String()) + "&v=" + version.ShortString()
// TODO: warn when using not-custom fetcher + specified branch
if conf.Fetcher == "custom" {
defaultProjectTitle := results[0].Name
cwd, _ := filepath.Abs(".")
if cwd != "" {
defaultProjectTitle = filepath.Base(cwd)
// TODO: make title configurable
title := results[0].Name
if title == "" {
title = conf.Project
}
fossaEndpoint += fmt.Sprintf("&managedBuild=true&title=%s", url.PathEscape(defaultProjectTitle))
fossaEndpoint += fmt.Sprintf("&managedBuild=true&title=%s&branch=%s", url.PathEscape(title), url.PathEscape(conf.Branch))
}

postRef, _ := url.Parse(fossaEndpoint)
Expand All @@ -184,7 +184,11 @@ func doUpload(conf config.CLIConfig, results []normalizedModule) (string, error)
return "", fmt.Errorf("invalid response, but build was uploaded")
}
locParts := strings.Split(jsonResponse["locator"].(string), "$")
getRef, _ := url.Parse("/projects/" + url.QueryEscape(locParts[0]) + "/refs/branch/" + conf.Branch + "/" + url.QueryEscape(locParts[1]) + "/browse/dependencies")
reportBranch := conf.Branch
if reportBranch == "" {
reportBranch = "master"
}
getRef, _ := url.Parse("/projects/" + url.QueryEscape(locParts[0]) + "/refs/branch/" + reportBranch + "/" + url.QueryEscape(locParts[1]) + "/browse/dependencies")
return fmt.Sprint(`
============================================================
Expand Down

0 comments on commit 9c77639

Please sign in to comment.