(message, treeSha string)
| 825 | } |
| 826 | |
| 827 | func (d *Github) commit(message, treeSha string) error { |
| 828 | oldCommit, err := d.getBranchHead() |
| 829 | body := map[string]interface{}{ |
| 830 | "message": message, |
| 831 | "tree": treeSha, |
| 832 | "parents": []string{oldCommit}, |
| 833 | } |
| 834 | d.addCommitterAndAuthor(&body) |
| 835 | if d.pgpEntity != nil { |
| 836 | signature, e := signCommit(&body, d.pgpEntity) |
| 837 | if e != nil { |
| 838 | return e |
| 839 | } |
| 840 | body["signature"] = signature |
| 841 | } |
| 842 | res, err := d.client.R().SetBody(body).Post(fmt.Sprintf("https://api.github.com/repos/%s/%s/git/commits", d.Owner, d.Repo)) |
| 843 | if err != nil { |
| 844 | return err |
| 845 | } |
| 846 | if res.StatusCode() != 201 { |
| 847 | return toErr(res) |
| 848 | } |
| 849 | var resp CommitResp |
| 850 | if err = utils.Json.Unmarshal(res.Body(), &resp); err != nil { |
| 851 | return err |
| 852 | } |
| 853 | |
| 854 | // update branch head |
| 855 | res, err = d.client.R(). |
| 856 | SetBody(&UpdateRefReq{ |
| 857 | Sha: resp.Sha, |
| 858 | Force: false, |
| 859 | }). |
| 860 | Patch(fmt.Sprintf("https://api.github.com/repos/%s/%s/git/refs/heads/%s", d.Owner, d.Repo, d.Ref)) |
| 861 | if err != nil { |
| 862 | return err |
| 863 | } |
| 864 | if res.StatusCode() != 200 { |
| 865 | return toErr(res) |
| 866 | } |
| 867 | return nil |
| 868 | } |
| 869 | |
| 870 | func (d *Github) getBranchHead() (string, error) { |
| 871 | res, err := d.client.R().Get(fmt.Sprintf("https://api.github.com/repos/%s/%s/branches/%s", d.Owner, d.Repo, d.Ref)) |
no test coverage detected