Пример #1
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
}
Пример #2
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
}