module.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2020 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 gitutil
  5. import (
  6. "github.com/gogs/git-module"
  7. )
  8. // Moduler is the interface for Git operations.
  9. //
  10. // NOTE: All methods are sorted in alphabetically.
  11. type Moduler interface {
  12. // AddRemote adds a new remote to the repository in given path.
  13. RepoAddRemote(repoPath, name, url string, opts ...git.AddRemoteOptions) error
  14. // RepoDiffNameOnly returns a list of changed files between base and head revisions
  15. // of the repository in given path.
  16. RepoDiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error)
  17. // RepoLog returns a list of commits in the state of given revision of the repository
  18. // in given path. The returned list is in reverse chronological order.
  19. RepoLog(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error)
  20. // RepoMergeBase returns merge base between base and head revisions of the repository
  21. // in given path.
  22. RepoMergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error)
  23. // RepoRemoveRemote removes a remote from the repository in given path.
  24. RepoRemoveRemote(repoPath, name string, opts ...git.RemoveRemoteOptions) error
  25. // RepoTags returns a list of tags of the repository in given path.
  26. RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error)
  27. Utiler
  28. }
  29. // Utiler is the interface for utility helpers implemented in this package.
  30. //
  31. // NOTE: All methods are sorted in alphabetically.
  32. type Utiler interface {
  33. // GetPullRequestMeta gathers pull request metadata based on given head and base information.
  34. PullRequestMeta(headPath, basePath, headBranch, baseBranch string) (*PullRequestMeta, error)
  35. // ListTagsAfter returns a list of tags "after" (exlusive) given tag.
  36. ListTagsAfter(repoPath, after string, limit int) (*TagsPage, error)
  37. }
  38. // moduler is holds real implementation.
  39. type moduler struct{}
  40. func (moduler) RepoAddRemote(repoPath, name, url string, opts ...git.AddRemoteOptions) error {
  41. if MockModule.RepoAddRemote != nil {
  42. return MockModule.RepoAddRemote(repoPath, name, url, opts...)
  43. }
  44. return git.RepoAddRemote(repoPath, name, url, opts...)
  45. }
  46. func (moduler) RepoDiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error) {
  47. if MockModule.RepoDiffNameOnly != nil {
  48. return MockModule.RepoDiffNameOnly(repoPath, base, head, opts...)
  49. }
  50. return git.RepoDiffNameOnly(repoPath, base, head, opts...)
  51. }
  52. func (moduler) RepoLog(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error) {
  53. if MockModule.RepoLog != nil {
  54. return MockModule.RepoLog(repoPath, rev, opts...)
  55. }
  56. return git.RepoLog(repoPath, rev, opts...)
  57. }
  58. func (moduler) RepoMergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error) {
  59. if MockModule.RepoMergeBase != nil {
  60. return MockModule.RepoMergeBase(repoPath, base, head, opts...)
  61. }
  62. return git.RepoMergeBase(repoPath, base, head, opts...)
  63. }
  64. func (moduler) RepoRemoveRemote(repoPath, name string, opts ...git.RemoveRemoteOptions) error {
  65. if MockModule.RepoRemoveRemote != nil {
  66. return MockModule.RepoRemoveRemote(repoPath, name, opts...)
  67. }
  68. return git.RepoRemoveRemote(repoPath, name, opts...)
  69. }
  70. func (moduler) RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error) {
  71. if MockModule.RepoTags != nil {
  72. return MockModule.RepoTags(repoPath, opts...)
  73. }
  74. return git.RepoTags(repoPath, opts...)
  75. }
  76. // Module is a mockable interface for Git operations.
  77. var Module Moduler = moduler{}