diff options
author | Martin Hartkorn <github@hartkorn.net> | 2016-02-04 19:00:42 +0100 |
---|---|---|
committer | Martin Hartkorn <github@hartkorn.net> | 2016-02-04 19:00:42 +0100 |
commit | d91004ee711c1db77ec3d5fd3aa823aab8c494f6 (patch) | |
tree | e4a5af4b22374b90fc68ec71be85bd7669b55c8e /models | |
parent | 20403f75fbf043747eb0c9e571a8ff7c4594ad2a (diff) | |
download | gitea-d91004ee711c1db77ec3d5fd3aa823aab8c494f6.tar.gz gitea-d91004ee711c1db77ec3d5fd3aa823aab8c494f6.zip |
Removed dependency on post-receive hook and use TriggerTask instead
Diffstat (limited to 'models')
-rw-r--r-- | models/pull.go | 38 | ||||
-rw-r--r-- | models/repo.go | 19 |
2 files changed, 38 insertions, 19 deletions
diff --git a/models/pull.go b/models/pull.go index 3935c13010..a6c15c1322 100644 --- a/models/pull.go +++ b/models/pull.go @@ -21,6 +21,7 @@ import ( "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/process" "github.com/gogits/gogs/modules/setting" + "strconv" ) type PullRequestType int @@ -520,6 +521,40 @@ func (pr *PullRequest) UpdatePatch() (err error) { return nil } +func (pr *PullRequest) PushToBaseRepo() (err error) { + log.Trace("PushToBase[%d]: pushing commits to base repo refs/pull/%d/head", pr.ID, pr.ID) + + branch := pr.HeadBranch + + if err = pr.BaseRepo.GetOwner(); err != nil { + return fmt.Errorf("Could not get base repo owner data: %v", err) + } else if err = pr.HeadRepo.GetOwner(); err != nil { + return fmt.Errorf("Could not get head repo owner data: %v", err) + } + + headRepoPath := RepoPath(pr.HeadRepo.Owner.Name, pr.HeadRepo.Name) + + prIdStr := strconv.FormatInt(pr.ID, 10) + tmpRemoteName := "tmp-pull-" + branch + "-" + prIdStr + repo, err := git.OpenRepository(headRepoPath) + if err != nil { + return fmt.Errorf("Unable to open head repository: %v", err) + } + + if err = repo.AddRemote(tmpRemoteName, RepoPath(pr.BaseRepo.Owner.Name, pr.BaseRepo.Name), false); err != nil { + return fmt.Errorf("Unable to add remote to head repository: %v", err) + } + // Make sure to remove the remote even if the push fails + defer repo.RemoveRemote(tmpRemoteName) + + pushRef := branch+":"+"refs/pull/"+prIdStr+"/head" + if err = git.Push(headRepoPath, tmpRemoteName, pushRef); err != nil { + return fmt.Errorf("Error pushing: %v", err) + } + + return nil +} + // AddToTaskQueue adds itself to pull request test task queue. func (pr *PullRequest) AddToTaskQueue() { go PullRequestQueue.AddFunc(pr.ID, func() { @@ -536,6 +571,9 @@ func addHeadRepoTasks(prs []*PullRequest) { if err := pr.UpdatePatch(); err != nil { log.Error(4, "UpdatePatch: %v", err) continue + } else if err := pr.PushToBaseRepo(); err != nil { + log.Error(4, "PushToBaseRepo: %v", err) + continue } pr.AddToTaskQueue() diff --git a/models/repo.go b/models/repo.go index 4d45b744ff..8ce1f7190c 100644 --- a/models/repo.go +++ b/models/repo.go @@ -39,7 +39,6 @@ import ( const ( _TPL_UPDATE_HOOK = "#!/usr/bin/env %s\n%s update $1 $2 $3 --config='%s'\n" - _TPL_POST_RECEIVE_HOOK = "#!/usr/bin/env %s\n%s pull --path \"$(pwd)\"\n" ) var ( @@ -597,11 +596,6 @@ func createUpdateHook(repoPath string) error { fmt.Sprintf(_TPL_UPDATE_HOOK, setting.ScriptType, "\""+setting.AppPath+"\"", setting.CustomConf)) } -func createPostReceiveHook(repoPath string) error { - return git.SetPostReceiveHook(repoPath, - fmt.Sprintf(_TPL_POST_RECEIVE_HOOK, setting.ScriptType, "\""+setting.AppPath+"\"")) -} - type MigrateRepoOptions struct { Name string Description string @@ -824,8 +818,6 @@ func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts C return fmt.Errorf("InitRepository: %v", err) } else if err = createUpdateHook(repoPath); err != nil { return fmt.Errorf("createUpdateHook: %v", err) - } else if err = createPostReceiveHook(repoPath); err != nil { - return fmt.Errorf("createPostReceiveHook: %v", err) } tmpDir := filepath.Join(os.TempDir(), "gogs-"+repo.Name+"-"+com.ToStr(time.Now().Nanosecond())) @@ -1506,15 +1498,6 @@ func RewriteRepositoryUpdateHook() error { }) } -// RewriteRepositoryPostReceiveHook rewrites all repositories' update hook. -func RewriteRepositoryPostReceiveHook() error { - return x.Where("id > 0").Iterate(new(Repository), - func(idx int, bean interface{}) error { - repo := bean.(*Repository) - return createPostReceiveHook(repo.RepoPath()) - }) -} - // statusPool represents a pool of status with true/false. type statusPool struct { lock sync.RWMutex @@ -2062,8 +2045,6 @@ func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Reposit if err = createUpdateHook(repoPath); err != nil { return nil, fmt.Errorf("createUpdateHook: %v", err) - } else if err = createPostReceiveHook(repoPath); err != nil { - return nil, fmt.Errorf("createPostReceiveHook: %v", err) } return repo, sess.Commit() |