repo_commit.go 1.6 KB

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