repo_commit.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package gitote
  2. import (
  3. "fmt"
  4. "net/http"
  5. )
  6. // CommitMeta contains meta information of a commit in terms of API.
  7. type CommitMeta struct {
  8. URL string `json:"url"`
  9. SHA string `json:"sha"`
  10. }
  11. // CommitUser contains information of a user in the context of a commit.
  12. type CommitUser struct {
  13. Name string `json:"name"`
  14. Email string `json:"email"`
  15. Date string `json:"date"`
  16. }
  17. // RepoCommit contains information of a commit in the context of a repository.
  18. type RepoCommit struct {
  19. URL string `json:"url"`
  20. Author *CommitUser `json:"author"`
  21. Committer *CommitUser `json:"committer"`
  22. Message string `json:"message"`
  23. Tree *CommitMeta `json:"tree"`
  24. }
  25. // Commit contains information generated from a Git commit.
  26. type Commit struct {
  27. *CommitMeta
  28. HTMLURL string `json:"html_url"`
  29. RepoCommit *RepoCommit `json:"commit"`
  30. Author *User `json:"author"`
  31. Committer *User `json:"committer"`
  32. Parents []*CommitMeta `json:"parents"`
  33. }
  34. func (c *Client) GetSingleCommit(user, repo, commitID string) (*Commit, error) {
  35. commit := new(Commit)
  36. return commit, c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s", user, repo, commitID), nil, nil, &commit)
  37. }
  38. func (c *Client) GetReferenceSHA(user, repo, ref string) (string, error) {
  39. data, err := c.getResponse("GET", fmt.Sprintf("/repos/%s/%s/commits/%s", user, repo, ref),
  40. http.Header{"Accept": []string{MediaApplicationSHA}}, nil)
  41. return string(data), err
  42. }