mod: bump github.com/gogs/git-module from 1.2.0 to 1.4.0 (#6866)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Joe Chen <jc@unknwon.io>
pull/6526/merge
dependabot[bot] 2022-03-22 00:55:36 +08:00 committed by GitHub
parent d66fe583d5
commit 3c49a6173d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 83 additions and 81 deletions

2
go.mod
View File

@ -18,7 +18,7 @@ require (
github.com/go-macaron/toolbox v0.0.0-20190813233741-94defb8383c6 github.com/go-macaron/toolbox v0.0.0-20190813233741-94defb8383c6
github.com/gogs/chardet v0.0.0-20150115103509-2404f7772561 github.com/gogs/chardet v0.0.0-20150115103509-2404f7772561
github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14 github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14
github.com/gogs/git-module v1.2.0 github.com/gogs/git-module v1.4.0
github.com/gogs/go-gogs-client v0.0.0-20200128182646-c69cb7680fd4 github.com/gogs/go-gogs-client v0.0.0-20200128182646-c69cb7680fd4
github.com/gogs/go-libravatar v0.0.0-20191106065024-33a75213d0a0 github.com/gogs/go-libravatar v0.0.0-20191106065024-33a75213d0a0
github.com/gogs/minwinsvc v0.0.0-20170301035411-95be6356811a github.com/gogs/minwinsvc v0.0.0-20170301035411-95be6356811a

4
go.sum
View File

@ -149,8 +149,8 @@ github.com/gogs/chardet v0.0.0-20150115103509-2404f7772561 h1:aBzukfDxQlCTVS0NBU
github.com/gogs/chardet v0.0.0-20150115103509-2404f7772561/go.mod h1:Pcatq5tYkCW2Q6yrR2VRHlbHpZ/R4/7qyL1TCF7vl14= github.com/gogs/chardet v0.0.0-20150115103509-2404f7772561/go.mod h1:Pcatq5tYkCW2Q6yrR2VRHlbHpZ/R4/7qyL1TCF7vl14=
github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14 h1:yXtpJr/LV6PFu4nTLgfjQdcMdzjbqqXMEnHfq0Or6p8= github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14 h1:yXtpJr/LV6PFu4nTLgfjQdcMdzjbqqXMEnHfq0Or6p8=
github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14/go.mod h1:jPoNZLWDAqA5N3G5amEoiNbhVrmM+ZQEcnQvNQ2KaZk= github.com/gogs/cron v0.0.0-20171120032916-9f6c956d3e14/go.mod h1:jPoNZLWDAqA5N3G5amEoiNbhVrmM+ZQEcnQvNQ2KaZk=
github.com/gogs/git-module v1.2.0 h1:eetCyhSSFUkIWqES91Se9ue26fEWiRZi+eI2D13syJk= github.com/gogs/git-module v1.4.0 h1:+0zcvzp3wxEMXVar2KnKmhI6JKlcAwjNUc6b5aTxs5M=
github.com/gogs/git-module v1.2.0/go.mod h1:oN37FFStFjdnTJXsSbhIHKJXh2YeDsEcXPATVz/oeuQ= github.com/gogs/git-module v1.4.0/go.mod h1:oN37FFStFjdnTJXsSbhIHKJXh2YeDsEcXPATVz/oeuQ=
github.com/gogs/go-gogs-client v0.0.0-20200128182646-c69cb7680fd4 h1:C7NryI/RQhsIWwC2bHN601P1wJKeuQ6U/UCOYTn3Cic= github.com/gogs/go-gogs-client v0.0.0-20200128182646-c69cb7680fd4 h1:C7NryI/RQhsIWwC2bHN601P1wJKeuQ6U/UCOYTn3Cic=
github.com/gogs/go-gogs-client v0.0.0-20200128182646-c69cb7680fd4/go.mod h1:fR6z1Ie6rtF7kl/vBYMfgD5/G5B1blui7z426/sj2DU= github.com/gogs/go-gogs-client v0.0.0-20200128182646-c69cb7680fd4/go.mod h1:fR6z1Ie6rtF7kl/vBYMfgD5/G5B1blui7z426/sj2DU=
github.com/gogs/go-libravatar v0.0.0-20191106065024-33a75213d0a0 h1:K02vod+sn3M1OOkdqi2tPxN2+xESK4qyITVQ3JkGEv4= github.com/gogs/go-libravatar v0.0.0-20191106065024-33a75213d0a0 h1:K02vod+sn3M1OOkdqi2tPxN2+xESK4qyITVQ3JkGEv4=

View File

@ -267,7 +267,7 @@ func (pc *PushCommits) ToApiPayloadCommits(repoPath, repoURL string) ([]*api.Pay
return nil, fmt.Errorf("get user by email: %v", err) return nil, fmt.Errorf("get user by email: %v", err)
} }
nameStatus, err := git.RepoShowNameStatus(repoPath, commit.Sha1) nameStatus, err := git.ShowNameStatus(repoPath, commit.Sha1)
if err != nil { if err != nil {
return nil, fmt.Errorf("show name status [commit_sha1: %s]: %v", commit.Sha1, err) return nil, fmt.Errorf("show name status [commit_sha1: %s]: %v", commit.Sha1, err)
} }

View File

@ -128,7 +128,7 @@ func (m *Mirror) RawAddress() string {
func (m *Mirror) SaveAddress(addr string) error { func (m *Mirror) SaveAddress(addr string) error {
repoPath := m.Repo.RepoPath() repoPath := m.Repo.RepoPath()
err := git.RepoRemoveRemote(repoPath, "origin") err := git.RemoteRemove(repoPath, "origin")
if err != nil { if err != nil {
return fmt.Errorf("remove remote 'origin': %v", err) return fmt.Errorf("remove remote 'origin': %v", err)
} }
@ -138,7 +138,7 @@ func (m *Mirror) SaveAddress(addr string) error {
return err return err
} }
err = git.RepoAddRemote(repoPath, "origin", addrURL.String(), git.AddRemoteOptions{MirrorFetch: true}) err = git.RemoteAdd(repoPath, "origin", addrURL.String(), git.RemoteAddOptions{MirrorFetch: true})
if err != nil { if err != nil {
return fmt.Errorf("add remote 'origin': %v", err) return fmt.Errorf("add remote 'origin': %v", err)
} }

View File

@ -634,12 +634,12 @@ func (pr *PullRequest) UpdatePatch() (err error) {
// Add a temporary remote. // Add a temporary remote.
tmpRemote := com.ToStr(time.Now().UnixNano()) tmpRemote := com.ToStr(time.Now().UnixNano())
baseRepoPath := RepoPath(pr.BaseRepo.MustOwner().Name, pr.BaseRepo.Name) baseRepoPath := RepoPath(pr.BaseRepo.MustOwner().Name, pr.BaseRepo.Name)
err = headGitRepo.AddRemote(tmpRemote, baseRepoPath, git.AddRemoteOptions{Fetch: true}) err = headGitRepo.RemoteAdd(tmpRemote, baseRepoPath, git.RemoteAddOptions{Fetch: true})
if err != nil { if err != nil {
return fmt.Errorf("add remote %q [repo_id: %d]: %v", tmpRemote, pr.HeadRepoID, err) return fmt.Errorf("add remote %q [repo_id: %d]: %v", tmpRemote, pr.HeadRepoID, err)
} }
defer func() { defer func() {
if err := headGitRepo.RemoveRemote(tmpRemote); err != nil { if err := headGitRepo.RemoteRemove(tmpRemote); err != nil {
log.Error("Failed to remove remote %q [repo_id: %d]: %v", tmpRemote, pr.HeadRepoID, err) log.Error("Failed to remove remote %q [repo_id: %d]: %v", tmpRemote, pr.HeadRepoID, err)
} }
}() }()
@ -678,13 +678,13 @@ func (pr *PullRequest) PushToBaseRepo() (err error) {
} }
tmpRemote := fmt.Sprintf("tmp-pull-%d", pr.ID) tmpRemote := fmt.Sprintf("tmp-pull-%d", pr.ID)
if err = headGitRepo.AddRemote(tmpRemote, pr.BaseRepo.RepoPath()); err != nil { if err = headGitRepo.RemoteAdd(tmpRemote, pr.BaseRepo.RepoPath()); err != nil {
return fmt.Errorf("add remote %q [repo_id: %d]: %v", tmpRemote, pr.HeadRepoID, err) return fmt.Errorf("add remote %q [repo_id: %d]: %v", tmpRemote, pr.HeadRepoID, err)
} }
// Make sure to remove the remote even if the push fails // Make sure to remove the remote even if the push fails
defer func() { defer func() {
if err := headGitRepo.RemoveRemote(tmpRemote); err != nil { if err := headGitRepo.RemoteRemove(tmpRemote); err != nil {
log.Error("Failed to remove remote %q [repo_id: %d]: %v", tmpRemote, pr.HeadRepoID, err) log.Error("Failed to remove remote %q [repo_id: %d]: %v", tmpRemote, pr.HeadRepoID, err)
} }
}() }()

View File

@ -419,7 +419,7 @@ func (repo *Repository) mustOwner(e Engine) *User {
} }
func (repo *Repository) UpdateSize() error { func (repo *Repository) UpdateSize() error {
countObject, err := git.RepoCountObjects(repo.RepoPath()) countObject, err := git.CountObjects(repo.RepoPath())
if err != nil { if err != nil {
return fmt.Errorf("count repository objects: %v", err) return fmt.Errorf("count repository objects: %v", err)
} }
@ -1979,7 +1979,7 @@ func GitFsck() {
func(idx int, bean interface{}) error { func(idx int, bean interface{}) error {
repo := bean.(*Repository) repo := bean.(*Repository)
repoPath := repo.RepoPath() repoPath := repo.RepoPath()
err := git.RepoFsck(repoPath, git.FsckOptions{ err := git.Fsck(repoPath, git.FsckOptions{
Args: conf.Cron.RepoHealthCheck.Args, Args: conf.Cron.RepoHealthCheck.Args,
Timeout: conf.Cron.RepoHealthCheck.Timeout, Timeout: conf.Cron.RepoHealthCheck.Timeout,
}) })
@ -2511,7 +2511,7 @@ func (repo *Repository) CreateNewBranch(oldBranch, newBranch string) (err error)
return fmt.Errorf("create new branch [base: %s, new: %s]: %v", oldBranch, newBranch, err) return fmt.Errorf("create new branch [base: %s, new: %s]: %v", oldBranch, newBranch, err)
} }
if err = git.RepoPush(localPath, "origin", newBranch); err != nil { if err = git.Push(localPath, "origin", newBranch); err != nil {
return fmt.Errorf("push [branch: %s]: %v", newBranch, err) return fmt.Errorf("push [branch: %s]: %v", newBranch, err)
} }

View File

@ -87,7 +87,7 @@ func discardLocalRepoBranchChanges(localPath, branch string) error {
} }
rev := "origin/" + branch rev := "origin/" + branch
if err := git.RepoReset(localPath, rev, git.ResetOptions{Hard: true}); err != nil { if err := git.Reset(localPath, rev, git.ResetOptions{Hard: true}); err != nil {
return fmt.Errorf("reset [revision: %s]: %v", rev, err) return fmt.Errorf("reset [revision: %s]: %v", rev, err)
} }
return nil return nil
@ -99,7 +99,7 @@ func (repo *Repository) DiscardLocalRepoBranchChanges(branch string) error {
// CheckoutNewBranch checks out to a new branch from the a branch name. // CheckoutNewBranch checks out to a new branch from the a branch name.
func (repo *Repository) CheckoutNewBranch(oldBranch, newBranch string) error { func (repo *Repository) CheckoutNewBranch(oldBranch, newBranch string) error {
if err := git.RepoCheckout(repo.LocalCopyPath(), newBranch, git.CheckoutOptions{ if err := git.Checkout(repo.LocalCopyPath(), newBranch, git.CheckoutOptions{
BaseBranch: oldBranch, BaseBranch: oldBranch,
Timeout: time.Duration(conf.Git.Timeout.Pull) * time.Second, Timeout: time.Duration(conf.Git.Timeout.Pull) * time.Second,
}); err != nil { }); err != nil {
@ -141,7 +141,7 @@ func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) (
// Otherwise, delete branch from local copy in case out of sync // Otherwise, delete branch from local copy in case out of sync
if git.RepoHasBranch(localPath, opts.NewBranch) { if git.RepoHasBranch(localPath, opts.NewBranch) {
if err = git.RepoDeleteBranch(localPath, opts.NewBranch, git.DeleteBranchOptions{ if err = git.DeleteBranch(localPath, opts.NewBranch, git.DeleteBranchOptions{
Force: true, Force: true,
}); err != nil { }); err != nil {
return fmt.Errorf("delete branch %q: %v", opts.NewBranch, err) return fmt.Errorf("delete branch %q: %v", opts.NewBranch, err)
@ -169,7 +169,7 @@ func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) (
// Ignore move step if it's a new file under a directory. // Ignore move step if it's a new file under a directory.
// Otherwise, move the file when name changed. // Otherwise, move the file when name changed.
if osutil.IsFile(oldFilePath) && opts.OldTreeName != opts.NewTreeName { if osutil.IsFile(oldFilePath) && opts.OldTreeName != opts.NewTreeName {
if err = git.RepoMove(localPath, opts.OldTreeName, opts.NewTreeName); err != nil { if err = git.Move(localPath, opts.OldTreeName, opts.NewTreeName); err != nil {
return fmt.Errorf("git mv %q %q: %v", opts.OldTreeName, opts.NewTreeName, err) return fmt.Errorf("git mv %q %q: %v", opts.OldTreeName, opts.NewTreeName, err)
} }
} }
@ -178,9 +178,9 @@ func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) (
return fmt.Errorf("write file: %v", err) return fmt.Errorf("write file: %v", err)
} }
if err = git.RepoAdd(localPath, git.AddOptions{All: true}); err != nil { if err = git.Add(localPath, git.AddOptions{All: true}); err != nil {
return fmt.Errorf("git add --all: %v", err) return fmt.Errorf("git add --all: %v", err)
} else if err = git.RepoCommit(localPath, doer.NewGitSig(), opts.Message); err != nil { } else if err = git.CreateCommit(localPath, doer.NewGitSig(), opts.Message); err != nil {
return fmt.Errorf("commit changes on %q: %v", localPath, err) return fmt.Errorf("commit changes on %q: %v", localPath, err)
} }
@ -192,7 +192,7 @@ func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) (
RepoName: repo.Name, RepoName: repo.Name,
RepoPath: repo.RepoPath(), RepoPath: repo.RepoPath(),
}) })
if err = git.RepoPush(localPath, "origin", opts.NewBranch, git.PushOptions{Envs: envs}); err != nil { if err = git.Push(localPath, "origin", opts.NewBranch, git.PushOptions{Envs: envs}); err != nil {
return fmt.Errorf("git push origin %s: %v", opts.NewBranch, err) return fmt.Errorf("git push origin %s: %v", opts.NewBranch, err)
} }
return nil return nil
@ -283,9 +283,9 @@ func (repo *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (
return fmt.Errorf("remove file %q: %v", opts.TreePath, err) return fmt.Errorf("remove file %q: %v", opts.TreePath, err)
} }
if err = git.RepoAdd(localPath, git.AddOptions{All: true}); err != nil { if err = git.Add(localPath, git.AddOptions{All: true}); err != nil {
return fmt.Errorf("git add --all: %v", err) return fmt.Errorf("git add --all: %v", err)
} else if err = git.RepoCommit(localPath, doer.NewGitSig(), opts.Message); err != nil { } else if err = git.CreateCommit(localPath, doer.NewGitSig(), opts.Message); err != nil {
return fmt.Errorf("commit changes to %q: %v", localPath, err) return fmt.Errorf("commit changes to %q: %v", localPath, err)
} }
@ -297,7 +297,7 @@ func (repo *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (
RepoName: repo.Name, RepoName: repo.Name,
RepoPath: repo.RepoPath(), RepoPath: repo.RepoPath(),
}) })
if err = git.RepoPush(localPath, "origin", opts.NewBranch, git.PushOptions{Envs: envs}); err != nil { if err = git.Push(localPath, "origin", opts.NewBranch, git.PushOptions{Envs: envs}); err != nil {
return fmt.Errorf("git push origin %s: %v", opts.NewBranch, err) return fmt.Errorf("git push origin %s: %v", opts.NewBranch, err)
} }
return nil return nil
@ -507,9 +507,9 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions)
} }
} }
if err = git.RepoAdd(localPath, git.AddOptions{All: true}); err != nil { if err = git.Add(localPath, git.AddOptions{All: true}); err != nil {
return fmt.Errorf("git add --all: %v", err) return fmt.Errorf("git add --all: %v", err)
} else if err = git.RepoCommit(localPath, doer.NewGitSig(), opts.Message); err != nil { } else if err = git.CreateCommit(localPath, doer.NewGitSig(), opts.Message); err != nil {
return fmt.Errorf("commit changes on %q: %v", localPath, err) return fmt.Errorf("commit changes on %q: %v", localPath, err)
} }
@ -521,7 +521,7 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions)
RepoName: repo.Name, RepoName: repo.Name,
RepoPath: repo.RepoPath(), RepoPath: repo.RepoPath(),
}) })
if err = git.RepoPush(localPath, "origin", opts.NewBranch, git.PushOptions{Envs: envs}); err != nil { if err = git.Push(localPath, "origin", opts.NewBranch, git.PushOptions{Envs: envs}); err != nil {
return fmt.Errorf("git push origin %s: %v", opts.NewBranch, err) return fmt.Errorf("git push origin %s: %v", opts.NewBranch, err)
} }

View File

@ -125,11 +125,11 @@ func (repo *Repository) updateWikiPage(doer *User, oldTitle, title, content, mes
if message == "" { if message == "" {
message = "Update page '" + title + "'" message = "Update page '" + title + "'"
} }
if err = git.RepoAdd(localPath, git.AddOptions{All: true}); err != nil { if err = git.Add(localPath, git.AddOptions{All: true}); err != nil {
return fmt.Errorf("add all changes: %v", err) return fmt.Errorf("add all changes: %v", err)
} else if err = git.RepoCommit(localPath, doer.NewGitSig(), message); err != nil { } else if err = git.CreateCommit(localPath, doer.NewGitSig(), message); err != nil {
return fmt.Errorf("commit changes: %v", err) return fmt.Errorf("commit changes: %v", err)
} else if err = git.RepoPush(localPath, "origin", "master"); err != nil { } else if err = git.Push(localPath, "origin", "master"); err != nil {
return fmt.Errorf("push: %v", err) return fmt.Errorf("push: %v", err)
} }
@ -161,11 +161,11 @@ func (repo *Repository) DeleteWikiPage(doer *User, title string) (err error) {
message := "Delete page '" + title + "'" message := "Delete page '" + title + "'"
if err = git.RepoAdd(localPath, git.AddOptions{All: true}); err != nil { if err = git.Add(localPath, git.AddOptions{All: true}); err != nil {
return fmt.Errorf("add all changes: %v", err) return fmt.Errorf("add all changes: %v", err)
} else if err = git.RepoCommit(localPath, doer.NewGitSig(), message); err != nil { } else if err = git.CreateCommit(localPath, doer.NewGitSig(), message); err != nil {
return fmt.Errorf("commit changes: %v", err) return fmt.Errorf("commit changes: %v", err)
} else if err = git.RepoPush(localPath, "origin", "master"); err != nil { } else if err = git.Push(localPath, "origin", "master"); err != nil {
return fmt.Errorf("push: %v", err) return fmt.Errorf("push: %v", err)
} }

View File

@ -13,35 +13,35 @@ import (
var _ ModuleStore = (*MockModuleStore)(nil) var _ ModuleStore = (*MockModuleStore)(nil)
type MockModuleStore struct { type MockModuleStore struct {
repoAddRemote func(repoPath, name, url string, opts ...git.AddRemoteOptions) error remoteAdd func(repoPath, name, url string, opts ...git.RemoteAddOptions) error
repoDiffNameOnly func(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error) diffNameOnly func(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error)
repoLog func(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error) log func(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error)
repoMergeBase func(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error) mergeBase func(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error)
repoRemoveRemote func(repoPath, name string, opts ...git.RemoveRemoteOptions) error remoteRemove func(repoPath, name string, opts ...git.RemoteRemoveOptions) error
repoTags func(repoPath string, opts ...git.TagsOptions) ([]string, error) repoTags func(repoPath string, opts ...git.TagsOptions) ([]string, error)
pullRequestMeta func(headPath, basePath, headBranch, baseBranch string) (*PullRequestMeta, error) pullRequestMeta func(headPath, basePath, headBranch, baseBranch string) (*PullRequestMeta, error)
listTagsAfter func(repoPath, after string, limit int) (*TagsPage, error) listTagsAfter func(repoPath, after string, limit int) (*TagsPage, error)
} }
func (m *MockModuleStore) RepoAddRemote(repoPath, name, url string, opts ...git.AddRemoteOptions) error { func (m *MockModuleStore) RemoteAdd(repoPath, name, url string, opts ...git.RemoteAddOptions) error {
return m.repoAddRemote(repoPath, name, url, opts...) return m.remoteAdd(repoPath, name, url, opts...)
} }
func (m *MockModuleStore) RepoDiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error) { func (m *MockModuleStore) DiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error) {
return m.repoDiffNameOnly(repoPath, base, head, opts...) return m.diffNameOnly(repoPath, base, head, opts...)
} }
func (m *MockModuleStore) RepoLog(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error) { func (m *MockModuleStore) Log(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error) {
return m.repoLog(repoPath, rev, opts...) return m.log(repoPath, rev, opts...)
} }
func (m *MockModuleStore) RepoMergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error) { func (m *MockModuleStore) MergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error) {
return m.repoMergeBase(repoPath, base, head, opts...) return m.mergeBase(repoPath, base, head, opts...)
} }
func (m *MockModuleStore) RepoRemoveRemote(repoPath, name string, opts ...git.RemoveRemoteOptions) error { func (m *MockModuleStore) RemoteRemove(repoPath, name string, opts ...git.RemoteRemoveOptions) error {
return m.repoRemoveRemote(repoPath, name, opts...) return m.remoteRemove(repoPath, name, opts...)
} }
func (m *MockModuleStore) RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error) { func (m *MockModuleStore) RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error) {

View File

@ -12,23 +12,25 @@ import (
// //
// NOTE: All methods are sorted in alphabetical order. // NOTE: All methods are sorted in alphabetical order.
type ModuleStore interface { type ModuleStore interface {
// AddRemote adds a new remote to the repository in given path. // RemoteAdd adds a new remote to the repository in given path.
RepoAddRemote(repoPath, name, url string, opts ...git.AddRemoteOptions) error RemoteAdd(repoPath, name, url string, opts ...git.RemoteAddOptions) error
// RepoDiffNameOnly returns a list of changed files between base and head revisions // DiffNameOnly returns a list of changed files between base and head revisions
// of the repository in given path. // of the repository in given path.
RepoDiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error) DiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error)
// RepoLog returns a list of commits in the state of given revision of the repository // Log returns a list of commits in the state of given revision of the
// in given path. The returned list is in reverse chronological order. // repository in given path. The returned list is in reverse chronological
RepoLog(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error) // order.
// RepoMergeBase returns merge base between base and head revisions of the repository Log(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error)
// in given path. // MergeBase returns merge base between base and head revisions of the
RepoMergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error) // repository in given path.
// RepoRemoveRemote removes a remote from the repository in given path. MergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error)
RepoRemoveRemote(repoPath, name string, opts ...git.RemoveRemoteOptions) error // RemoteRemove removes a remote from the repository in given path.
RemoteRemove(repoPath, name string, opts ...git.RemoteRemoveOptions) error
// RepoTags returns a list of tags of the repository in given path. // RepoTags returns a list of tags of the repository in given path.
RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error) RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error)
// GetPullRequestMeta gathers pull request metadata based on given head and base information. // PullRequestMeta gathers pull request metadata based on given head and base
// information.
PullRequestMeta(headPath, basePath, headBranch, baseBranch string) (*PullRequestMeta, error) PullRequestMeta(headPath, basePath, headBranch, baseBranch string) (*PullRequestMeta, error)
// ListTagsAfter returns a list of tags "after" (exclusive) given tag. // ListTagsAfter returns a list of tags "after" (exclusive) given tag.
ListTagsAfter(repoPath, after string, limit int) (*TagsPage, error) ListTagsAfter(repoPath, after string, limit int) (*TagsPage, error)
@ -37,24 +39,24 @@ type ModuleStore interface {
// module holds the real implementation. // module holds the real implementation.
type module struct{} type module struct{}
func (module) RepoAddRemote(repoPath, name, url string, opts ...git.AddRemoteOptions) error { func (module) RemoteAdd(repoPath, name, url string, opts ...git.RemoteAddOptions) error {
return git.RepoAddRemote(repoPath, name, url, opts...) return git.RemoteAdd(repoPath, name, url, opts...)
} }
func (module) RepoDiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error) { func (module) DiffNameOnly(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error) {
return git.RepoDiffNameOnly(repoPath, base, head, opts...) return git.DiffNameOnly(repoPath, base, head, opts...)
} }
func (module) RepoLog(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error) { func (module) Log(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error) {
return git.RepoLog(repoPath, rev, opts...) return git.Log(repoPath, rev, opts...)
} }
func (module) RepoMergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error) { func (module) MergeBase(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error) {
return git.RepoMergeBase(repoPath, base, head, opts...) return git.MergeBase(repoPath, base, head, opts...)
} }
func (module) RepoRemoveRemote(repoPath, name string, opts ...git.RemoveRemoteOptions) error { func (module) RemoteRemove(repoPath, name string, opts ...git.RemoteRemoveOptions) error {
return git.RepoRemoveRemote(repoPath, name, opts...) return git.RemoteRemove(repoPath, name, opts...)
} }
func (module) RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error) { func (module) RepoTags(repoPath string, opts ...git.TagsOptions) ([]string, error) {

View File

@ -30,12 +30,12 @@ func (module) PullRequestMeta(headPath, basePath, headBranch, baseBranch string)
// We need to create a temporary remote when the pull request is sent from a forked repository. // We need to create a temporary remote when the pull request is sent from a forked repository.
if headPath != basePath { if headPath != basePath {
tmpRemote := strconv.FormatInt(time.Now().UnixNano(), 10) tmpRemote := strconv.FormatInt(time.Now().UnixNano(), 10)
err := Module.RepoAddRemote(headPath, tmpRemote, basePath, git.AddRemoteOptions{Fetch: true}) err := Module.RemoteAdd(headPath, tmpRemote, basePath, git.RemoteAddOptions{Fetch: true})
if err != nil { if err != nil {
return nil, fmt.Errorf("add remote: %v", err) return nil, fmt.Errorf("add remote: %v", err)
} }
defer func() { defer func() {
err := Module.RepoRemoveRemote(headPath, tmpRemote) err := Module.RemoteRemove(headPath, tmpRemote)
if err != nil { if err != nil {
log.Error("Failed to remove remote %q [path: %s]: %v", tmpRemote, headPath, err) log.Error("Failed to remove remote %q [path: %s]: %v", tmpRemote, headPath, err)
return return
@ -45,18 +45,18 @@ func (module) PullRequestMeta(headPath, basePath, headBranch, baseBranch string)
tmpRemoteBranch = "remotes/" + tmpRemote + "/" + baseBranch tmpRemoteBranch = "remotes/" + tmpRemote + "/" + baseBranch
} }
mergeBase, err := Module.RepoMergeBase(headPath, tmpRemoteBranch, headBranch) mergeBase, err := Module.MergeBase(headPath, tmpRemoteBranch, headBranch)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "get merge base") return nil, errors.Wrap(err, "get merge base")
} }
commits, err := Module.RepoLog(headPath, mergeBase+"..."+headBranch) commits, err := Module.Log(headPath, mergeBase+"..."+headBranch)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "get commits") return nil, errors.Wrap(err, "get commits")
} }
// Count number of changed files // Count number of changed files
names, err := Module.RepoDiffNameOnly(headPath, tmpRemoteBranch, headBranch, git.DiffNameOnlyOptions{NeedsMergeBase: true}) names, err := Module.DiffNameOnly(headPath, tmpRemoteBranch, headBranch, git.DiffNameOnlyOptions{NeedsMergeBase: true})
if err != nil { if err != nil {
return nil, errors.Wrap(err, "get changed files") return nil, errors.Wrap(err, "get changed files")
} }

View File

@ -25,7 +25,7 @@ func TestModuler_PullRequestMeta(t *testing.T) {
} }
SetMockModuleStore(t, &MockModuleStore{ SetMockModuleStore(t, &MockModuleStore{
repoAddRemote: func(repoPath, name, url string, opts ...git.AddRemoteOptions) error { remoteAdd: func(repoPath, name, url string, opts ...git.RemoteAddOptions) error {
if repoPath != headPath { if repoPath != headPath {
return fmt.Errorf("repoPath: want %q but got %q", headPath, repoPath) return fmt.Errorf("repoPath: want %q but got %q", headPath, repoPath)
} else if name == "" { } else if name == "" {
@ -42,7 +42,7 @@ func TestModuler_PullRequestMeta(t *testing.T) {
return nil return nil
}, },
repoMergeBase: func(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error) { mergeBase: func(repoPath, base, head string, opts ...git.MergeBaseOptions) (string, error) {
if repoPath != headPath { if repoPath != headPath {
return "", fmt.Errorf("repoPath: want %q but got %q", headPath, repoPath) return "", fmt.Errorf("repoPath: want %q but got %q", headPath, repoPath)
} else if base == "" { } else if base == "" {
@ -53,7 +53,7 @@ func TestModuler_PullRequestMeta(t *testing.T) {
return mergeBase, nil return mergeBase, nil
}, },
repoLog: func(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error) { log: func(repoPath, rev string, opts ...git.LogOptions) ([]*git.Commit, error) {
if repoPath != headPath { if repoPath != headPath {
return nil, fmt.Errorf("repoPath: want %q but got %q", headPath, repoPath) return nil, fmt.Errorf("repoPath: want %q but got %q", headPath, repoPath)
} }
@ -65,7 +65,7 @@ func TestModuler_PullRequestMeta(t *testing.T) {
return commits, nil return commits, nil
}, },
repoDiffNameOnly: func(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error) { diffNameOnly: func(repoPath, base, head string, opts ...git.DiffNameOnlyOptions) ([]string, error) {
if repoPath != headPath { if repoPath != headPath {
return nil, fmt.Errorf("repoPath: want %q but got %q", headPath, repoPath) return nil, fmt.Errorf("repoPath: want %q but got %q", headPath, repoPath)
} else if base == "" { } else if base == "" {
@ -82,7 +82,7 @@ func TestModuler_PullRequestMeta(t *testing.T) {
return changedFiles, nil return changedFiles, nil
}, },
repoRemoveRemote: func(repoPath, name string, opts ...git.RemoveRemoteOptions) error { remoteRemove: func(repoPath, name string, opts ...git.RemoteRemoveOptions) error {
if repoPath != headPath { if repoPath != headPath {
return fmt.Errorf("repoPath: want %q but got %q", headPath, repoPath) return fmt.Errorf("repoPath: want %q but got %q", headPath, repoPath)
} else if name == "" { } else if name == "" {