Пример #1
0
func publish(apihost, user, apikey, subject, repository, pkg, version string, isVerbose bool) error {
	resp, err := httpc.DoHttp("POST", apihost+"/content/"+subject+"/"+repository+"/"+pkg+"/"+version+"/publish", subject, user, apikey, "", nil, 0, isVerbose)
	if err == nil {
		log.Printf("Version published. %v", resp)
	}
	return err
}
Пример #2
0
func ghGetReleaseForTag(apihost, owner, apikey, repo, tagName string, isVerbose bool) (string, string, error) {
	r, err := httpc.DoHttp("GET", apihost+"/repos/"+owner+"/"+repo+"/releases/tags/"+tagName, "", owner, apikey, "", nil, 0, isVerbose)
	if err != nil {
		return "", "", err
	}
	i, err := httpc.ParseMap(r, isVerbose)
	if err != nil {
		return "", "", err
	}
	var id string
	idI, ok := i["id"]
	if !ok {
		return "", "", fmt.Errorf("Id not provided")
	}
	switch i := idI.(type) {
	case float64:
		id = fmt.Sprintf("%0.f", i)
	default:
		return "", "", fmt.Errorf("ID not a float")
	}

	uploadURLi, ok := i["upload_url"]
	if !ok {
		return "", "", fmt.Errorf("Upload URL not provided")
	}
	uploadURL := uploadURLi.(string)
	uploadURL = strings.Split(uploadURL, "{")[0]
	return id, uploadURL, err
}
Пример #3
0
Файл: http.go Проект: yl10/goxc
func httpDeleteFile(config *httpTaskConfig, url string) error {
	res, err := httpc.DoHttp("DELETE", url, "", config.username, config.password, "", nil, 0, true)
	if err != nil {
		return err
	}
	if res.StatusCode/100 != 2 {
		return fmt.Errorf("Unable to delete %v: %v", url, res.Status)
	}
	return nil
}
Пример #4
0
Файл: http.go Проект: yl10/goxc
func httpExistsFile(config *httpTaskConfig, url string) (bool, error) {
	res, err := httpc.DoHttp("HEAD", url, "", config.username, config.password, "", nil, 0, true)
	if err != nil {
		return false, err
	}
	switch res.StatusCode {
	case 200:
		return true, nil
	case 404:
		return false, nil
	default:
		return false, fmt.Errorf("Unexpected status code %v when testing for existence of %v", res.StatusCode, url)
	}
}
Пример #5
0
//NOTE: not necessary.
//POST /packages/:subject/:repo/:package/versions
func createVersion(apihost, user, apikey, subject, repository, pkg, version string, isVerbose bool) error {
	req := map[string]interface{}{"name": version, "release_notes": "built by goxc", "release_url": "http://x.x.x/x/x"}
	requestData, err := json.Marshal(req)
	if err != nil {
		return err
	}
	requestLength := len(requestData)
	reader := bytes.NewReader(requestData)
	resp, err := httpc.DoHttp("POST", apihost+"/packages/"+subject+"/"+repository+"/"+pkg+"/versions", subject, user, apikey, "", reader, int64(requestLength), isVerbose)
	if err == nil {
		if isVerbose {
			log.Printf("Created new version. %v", resp)
		}
	}
	return err
}
Пример #6
0
Файл: http.go Проект: yl10/goxc
func httpUploadFile(config *httpTaskConfig, fullPath string, fi os.FileInfo, tp TaskParams) error {
	var urlb bytes.Buffer
	err := config.urlTemplate.Execute(&urlb, httpURLTemplateContext(tp, fi))
	if err != nil {
		return err
	}
	var url = urlb.String()
	exists, err := httpExistsFile(config, url)
	if err != nil {
		return err
	}
	if exists {
		switch config.exists {
		case "replace":
			if !tp.Settings.IsQuiet() {
				log.Printf("Deleting existent file %v at %v", fi.Name(), url)
			}
			if err := httpDeleteFile(config, url); err != nil {
				return err
			}
		case "omit":
			if !tp.Settings.IsQuiet() {
				log.Printf("Omitting existent file %v at %v", fi.Name(), url)
			}
			return nil
		case "fail":
			return fmt.Errorf("Failing http publish of %v because it already exists at %v", fi.Name(), url)
		}
	}
	if !tp.Settings.IsQuiet() {
		log.Printf("Putting %s to %s", fi.Name(), url)
	}
	b, err := os.Open(fullPath)
	if err != nil {
		return err
	}
	res, err := httpc.DoHttp("PUT", url, "", config.username, config.password, "application/octet-stream", b, fi.Size(), true)
	if err != nil {
		return err
	}
	if res.StatusCode/100 != 2 {
		return fmt.Errorf("Unexpected response: %v", res.Status)
	}
	return nil
}
Пример #7
0
func TestGetReleases(t *testing.T) {
	if *apikey == "" {
		t.Skip("api-key is required to run this integration test")
	}
	r, err := httpc.DoHttp("GET", apihost+"/repos/"+owner+"/"+repo+"/releases", "", owner, *apikey, "", nil, 0, isVerbose)
	if err != nil {
		t.Errorf("Error getting release %v", err)
	}
	a, err := httpc.ParseSlice(r, isVerbose)
	if err != nil {
		t.Errorf("Error getting release %v", err)
	}
	for _, i := range a {
		id := i["id"]
		name := i["name"]
		t.Logf("ID: %0.f  Name: %s", id, name)
		//		for k, v := range i {
		//			t.Logf("Entry: %s %+v", k, v)
		//		}
	}
	//t.Logf("Response data: %v", a)
}
Пример #8
0
//POST /repos/:owner/:repo/releases
func createRelease(apihost, owner, apikey, repo, tagName, version, body string, preRelease, isVerbose bool) error {
	req := map[string]interface{}{"tag_name": tagName, "name": version, "body": body, "prerelease": preRelease}
	requestData, err := json.Marshal(req)
	if err != nil {
		return err
	}
	requestLength := len(requestData)
	reader := bytes.NewReader(requestData)
	resp, err := httpc.DoHttp("POST", apihost+"/repos/"+owner+"/"+repo+"/releases", owner, owner, apikey, "", reader, int64(requestLength), isVerbose)
	if err == nil {
		if isVerbose {
			log.Printf("Created new version. %v", resp)
			i, err := httpc.ParseMap(resp, isVerbose)
			if err != nil {
				log.Printf("Error parsing response as map: %v", err)
				return err
			}
			log.Printf("Created new version: %+v", i)

		}
	}
	return err
}