MCPcopy
hub / github.com/OpenListTeam/OpenList / commit

Method commit

drivers/github/driver.go:827–868  ·  view source on GitHub ↗
(message, treeSha string)

Source from the content-addressed store, hash-verified

825}
826
827func (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
870func (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))

Callers 6

MakeDirMethod · 0.95
MoveMethod · 0.95
RenameMethod · 0.95
CopyMethod · 0.95
RemoveMethod · 0.95
PutMethod · 0.95

Calls 7

getBranchHeadMethod · 0.95
addCommitterAndAuthorMethod · 0.95
signCommitFunction · 0.85
toErrFunction · 0.85
PostMethod · 0.80
PatchMethod · 0.80
UnmarshalMethod · 0.45

Tested by

no test coverage detected