Created
March 9, 2015 11:16
-
-
Save mmirolim/342553c800fa0c796990 to your computer and use it in GitHub Desktop.
gitlab post issue in Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func main() { | |
| // private token for authentications | |
| token := "5p94RchB-9pXWRE71Hv2" | |
| ts := Issue{} | |
| ts.PID = "root%2Fhrkb" | |
| ts.Title = "Auto Issue" | |
| ts.Desc = "Description should be added" | |
| ts.Labels = "UI" | |
| // url of gitlab issues | |
| url := "http://office.newmax.uz:7775/api/v3/projects/" + ts.PID + "/issues" | |
| fmt.Println("URL", url) | |
| data, err := json.Marshal(&ts) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| req, err := http.NewRequest("POST", url, bytes.NewBuffer(data)) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| req.Header.Set("PRIVATE-TOKEN", token) | |
| req.Header.Set("Content-Type", "application/json") | |
| // make request | |
| client := &http.Client{} | |
| res, err := client.Do(req) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| defer res.Body.Close() | |
| fmt.Println("Status", res.Status) | |
| fmt.Println("Headers", res.Header) | |
| body, err := ioutil.ReadAll(res.Body) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| fmt.Println("Body", string(body)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment