func CreateBug()

in entryMaker/bugs/bugs.go [77:113]


func CreateBug(bug Bug, conf *config.OneCRLConfig) (int, error) {
	// POST the bug
	bugNum := -1
	url := conf.BugzillaBase + "/rest/bug"
	marshalled, err := json.Marshal(bug)
	if "yes" == conf.OneCRLVerbose {
		fmt.Printf("POSTing %s to %s\n", marshalled, url)
	}
	req, err := http.NewRequest("POST", url, bytes.NewBuffer(marshalled))
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("User-Agent", userAgent)

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		return bugNum, err
	}
	if "yes" == conf.OneCRLVerbose {
		fmt.Printf("status code is %d\n", resp.StatusCode)
	}
	dec := json.NewDecoder(resp.Body)
	var response BugResponse
	err = dec.Decode(&response)
	if err != nil {
		return bugNum, err
	} else {
		bugNum = response.Id

		fmt.Printf("%s\n", err)
		if "yes" == conf.OneCRLVerbose {
			fmt.Printf("%v\n", response.Id)
		}
	}
	defer resp.Body.Close()

	return bugNum, nil
}