************************************/ ********* Check Runs API ***********/ ************************************/ CreateCheckRun Creates a check run (https://developer.github.com/v3/checks/runs/#create-a-check-run)
(CheckRun sender.CheckRun)
| 807 | |
| 808 | // CreateCheckRun Creates a check run (https://developer.github.com/v3/checks/runs/#create-a-check-run) |
| 809 | func (e *API) CreateCheckRun(CheckRun sender.CheckRun) (response.CheckRun, error) { |
| 810 | |
| 811 | var checkRun response.CheckRun |
| 812 | |
| 813 | jsonBody, err := CheckRun.ConvertToJSON() |
| 814 | fmt.Println(jsonBody) |
| 815 | if err != nil { |
| 816 | return checkRun, err |
| 817 | } |
| 818 | |
| 819 | client := &http.Client{} |
| 820 | |
| 821 | req, err := http.NewRequest( |
| 822 | "POST", |
| 823 | fmt.Sprintf("%s/repos/%s/%s/check-runs", GithubURL, e.Author, e.Repository), |
| 824 | bytes.NewBufferString(jsonBody), |
| 825 | ) |
| 826 | |
| 827 | if err != nil { |
| 828 | return checkRun, err |
| 829 | } |
| 830 | |
| 831 | req.Header.Add("Authorization", fmt.Sprintf("token %s", e.Token)) |
| 832 | req.Header.Add("Content-Type", "application/json") |
| 833 | req.Header.Add("Accept", "application/vnd.github.antiope-preview+json") |
| 834 | |
| 835 | resp, err := client.Do(req) |
| 836 | |
| 837 | if err != nil { |
| 838 | return checkRun, err |
| 839 | } |
| 840 | |
| 841 | defer resp.Body.Close() |
| 842 | |
| 843 | bodyByte, err := ioutil.ReadAll(resp.Body) |
| 844 | |
| 845 | if err != nil { |
| 846 | return checkRun, err |
| 847 | } |
| 848 | |
| 849 | if resp.StatusCode == 400 { |
| 850 | return checkRun, fmt.Errorf("Oops: %s", string(bodyByte)) |
| 851 | } |
| 852 | |
| 853 | ok, _ := checkRun.LoadFromJSON(bodyByte) |
| 854 | |
| 855 | if ok && resp.StatusCode == 201 { |
| 856 | return checkRun, nil |
| 857 | } |
| 858 | |
| 859 | return checkRun, fmt.Errorf("Error: %s", string(bodyByte)) |
| 860 | } |
| 861 | |
| 862 | // UpdateCheckRun Updates a check run (https://developer.github.com/v3/checks/runs/#update-a-check-run) |
| 863 | func (e *API) UpdateCheckRun(ID int, CheckRun sender.CheckRun) (response.CheckRun, error) { |
nothing calls this directly
no test coverage detected