Skip to content

Commit

Permalink
feat(api): Add normalized imports
Browse files Browse the repository at this point in the history
  • Loading branch information
elldritch committed Jun 11, 2018
1 parent 1a88076 commit d90cc8a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions api/fossa/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ type Build struct {
Succeeded bool
Error error `json:",omitempty"`

Imports []string
Dependencies []Dependency
}

type Dependency struct {
// Location
Locator string `json:"locator"`
Imports []string

// Metadata
Data *json.RawMessage `json:"data,omitempty"`
Expand Down Expand Up @@ -60,8 +62,14 @@ func Normalize(modules []module.Module) ([]SourceUnit, error) {
return nil, errors.Wrap(err, "could not marshal analyzed dependency")
}

var imports []string
for _, i := range dep.Imports {
imports = append(imports, LocatorOf(i.Resolved).String())
}

deps = append(deps, Dependency{
Locator: LocatorOf(dep.ID).String(),
Imports: imports,
Data: (*json.RawMessage)(&data),
})
}
Expand All @@ -71,6 +79,10 @@ func Normalize(modules []module.Module) ([]SourceUnit, error) {
return nil, errors.Wrap(err, "could not normalize analyzed module type")
}

var imports []string
for _, i := range analyzed.Imports {
imports = append(imports, LocatorOf(i).String())
}
normalized = append(normalized, SourceUnit{
Name: analyzed.Name,
Type: normalizedType,
Expand All @@ -79,6 +91,7 @@ func Normalize(modules []module.Module) ([]SourceUnit, error) {
Artifact: "default",
Succeeded: true,
Dependencies: deps,
Imports: imports,
},
})
}
Expand Down

0 comments on commit d90cc8a

Please sign in to comment.