This repository has been archived by the owner on Oct 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from rebuy-de/jsonnet-importer
add Jsonnet importer
- Loading branch information
Showing
13 changed files
with
280 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,4 +68,4 @@ | |
|
||
[[constraint]] | ||
name = "github.com/google/go-jsonnet" | ||
version = "^0.10.0" | ||
version = "^0.11.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package gh | ||
|
||
import ( | ||
"path" | ||
"path/filepath" | ||
"strings" | ||
|
||
jsonnet "github.com/google/go-jsonnet" | ||
) | ||
|
||
type jsonnetImporter struct { | ||
client Interface | ||
} | ||
|
||
func NewJsonnetImporter(client Interface) jsonnet.Importer { | ||
return &jsonnetImporter{ | ||
client: client, | ||
} | ||
} | ||
|
||
func (i *jsonnetImporter) Import(importedFrom, importedPath string) (contents jsonnet.Contents, foundAt string, err error) { | ||
fromLocation, err := NewLocation(importedFrom) | ||
if err != nil { | ||
return jsonnet.MakeContents(""), "", err | ||
} | ||
|
||
var location *Location | ||
if strings.HasPrefix(importedPath, "github.com/") { | ||
// location constrution for absolute paths | ||
location, err = NewLocation(importedPath) | ||
if err != nil { | ||
return jsonnet.MakeContents(""), "", err | ||
} | ||
} else { | ||
// location constrution for relative paths | ||
fromDir := filepath.Dir(fromLocation.String()) | ||
absolute := path.Clean(path.Join(fromDir, importedPath)) | ||
|
||
location, err = NewLocation(absolute) | ||
if err != nil { | ||
return jsonnet.MakeContents(""), "", err | ||
} | ||
} | ||
|
||
// having no ref means same ref, if inside same repo and "master" if it is in another repo | ||
if location.Ref == "" { | ||
if location.Owner == fromLocation.Owner && location.Repo == fromLocation.Repo { | ||
location.Ref = fromLocation.Ref | ||
} else { | ||
location.Ref = "master" | ||
} | ||
|
||
} | ||
|
||
file, err := i.client.GetFile(location) | ||
if err != nil { | ||
return jsonnet.MakeContents(""), "", err | ||
} | ||
|
||
return jsonnet.MakeContents(file.Content), location.String(), nil | ||
} |
Oops, something went wrong.