start scan
This commit is contained in:
parent
61f6398711
commit
662e15dd9a
1
go.mod
1
go.mod
@ -5,6 +5,7 @@ go 1.12
|
|||||||
require (
|
require (
|
||||||
github.com/bmatcuk/doublestar v1.1.1
|
github.com/bmatcuk/doublestar v1.1.1
|
||||||
github.com/davecgh/go-spew v1.1.1
|
github.com/davecgh/go-spew v1.1.1
|
||||||
|
github.com/ddliu/go-httpclient v0.5.1
|
||||||
github.com/fatih/color v1.7.0 // indirect
|
github.com/fatih/color v1.7.0 // indirect
|
||||||
github.com/mattn/go-colorable v0.1.1 // indirect
|
github.com/mattn/go-colorable v0.1.1 // indirect
|
||||||
github.com/mattn/go-isatty v0.0.7 // indirect
|
github.com/mattn/go-isatty v0.0.7 // indirect
|
||||||
|
2
go.sum
2
go.sum
@ -3,6 +3,8 @@ github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvF
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/ddliu/go-httpclient v0.5.1 h1:ys4KozrhBaGdI1yuWIFwNNILqhnMU9ozTvRNfCTorvs=
|
||||||
|
github.com/ddliu/go-httpclient v0.5.1/go.mod h1:8QVbjq00YK2f2MQyiKuWMdaKOFRcoD9VuubkNCNOuZo=
|
||||||
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
||||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||||
github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg=
|
github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg=
|
||||||
|
9
main.go
9
main.go
@ -75,7 +75,7 @@ func scan(directory string) error {
|
|||||||
return cli.NewExitError("no .tidelift.yml at supplied directory path", 6)
|
return cli.NewExitError("no .tidelift.yml at supplied directory path", 6)
|
||||||
}
|
}
|
||||||
fmt.Println(strings.Join(getListOfManifestFilenames(directory), ", "))
|
fmt.Println(strings.Join(getListOfManifestFilenames(directory), ", "))
|
||||||
|
upload(directory)
|
||||||
// TODO, actually upload scan, don't just print names
|
// TODO, actually upload scan, don't just print names
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -98,3 +98,10 @@ func verify(directory string) error {
|
|||||||
fmt.Println("Your team-name, repo-name and TIDELIFT_API_KEY are all set! Feel free to use `scan`")
|
fmt.Println("Your team-name, repo-name and TIDELIFT_API_KEY are all set! Feel free to use `scan`")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check error and panic if so
|
||||||
|
func check(e error) {
|
||||||
|
if e != nil {
|
||||||
|
panic(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
34
scan.go
Normal file
34
scan.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/ddliu/go-httpclient"
|
||||||
|
)
|
||||||
|
|
||||||
|
func upload(directory string) {
|
||||||
|
tideliftYML := getKeysFromYaml(readTideliftYamlFile(directory))
|
||||||
|
fileNames := getListOfManifestFilenames(directory)
|
||||||
|
auth := fmt.Sprintf("Bearer %s", os.Getenv("TIDELIFT_API_KEY"))
|
||||||
|
// url := fmt.Sprintf("https://api.tidelift.com/subscriber/%s/%s/manifest/upload", team, repository)
|
||||||
|
url := fmt.Sprintf("http://127.0.0.1:8000/subscriber/%s/%s/manifest/upload", string(tideliftYML.TeamName), string(tideliftYML.RepositoryName))
|
||||||
|
// TODO: Add revision
|
||||||
|
|
||||||
|
var body = map[string]string{
|
||||||
|
"@files[]": fileNames[0],
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := httpclient.WithHeaders(map[string]string{
|
||||||
|
"Authorization": auth,
|
||||||
|
}).Post(url, body)
|
||||||
|
check(err)
|
||||||
|
|
||||||
|
fmt.Println(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
func openFile(f string) *os.File {
|
||||||
|
handle, err := os.Open(f)
|
||||||
|
check(err)
|
||||||
|
return handle
|
||||||
|
}
|
10
scan_test.go
Normal file
10
scan_test.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestUpload(t *testing.T) {
|
||||||
|
//assert getManifestMatches gets all requirements.txt
|
||||||
|
upload("test/good_config")
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
// lock file
|
@ -60,12 +60,6 @@ func passesMinimumRequirements(yamlText []byte) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func check(e error) {
|
|
||||||
if e != nil {
|
|
||||||
panic(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func fileExists(filename string) bool {
|
func fileExists(filename string) bool {
|
||||||
|
|
||||||
info, err := os.Stat(filename)
|
info, err := os.Stat(filename)
|
||||||
|
Loading…
Reference in New Issue
Block a user