2019-05-16 03:54:57 +00:00
|
|
|
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{
|
2019-05-16 03:55:49 +00:00
|
|
|
// maybe use httpclient.addFormFile and do everything manually...
|
|
|
|
// https://github.com/ddliu/go-httpclient/blob/master/httpclient.go#L676
|
|
|
|
"@files[]": fileNames[0], // TODO: Add multiple files
|
2019-05-16 03:54:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, 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
|
|
|
|
}
|