diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-25 14:04:57 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-25 14:04:57 -0400 |
commit | d3b8e9daa1a22501c03564f2739f9fa8198fbdf1 (patch) | |
tree | 2e56cf4863b883984f760256b1898dd52bd593fd /models/repo.go | |
parent | c5ff58272bcec72520f59a94445cd78d3e2dbf34 (diff) | |
download | gitea-d3b8e9daa1a22501c03564f2739f9fa8198fbdf1.tar.gz gitea-d3b8e9daa1a22501c03564f2739f9fa8198fbdf1.zip |
Add notify watcher action
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 71 |
1 files changed, 51 insertions, 20 deletions
diff --git a/models/repo.go b/models/repo.go index d5f9be72ac..824d5ba0ca 100644 --- a/models/repo.go +++ b/models/repo.go @@ -262,27 +262,27 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep } /* - // hook/post-update - pu, err := os.OpenFile(filepath.Join(repoPath, "hooks", "post-update"), os.O_CREATE|os.O_WRONLY, 0777) - if err != nil { - return err - } - defer pu.Close() - // TODO: Windows .bat - if _, err = pu.WriteString(fmt.Sprintf("#!/usr/bin/env bash\n%s update\n", appPath)); err != nil { - return err - } + // hook/post-update + pu, err := os.OpenFile(filepath.Join(repoPath, "hooks", "post-update"), os.O_CREATE|os.O_WRONLY, 0777) + if err != nil { + return err + } + defer pu.Close() + // TODO: Windows .bat + if _, err = pu.WriteString(fmt.Sprintf("#!/usr/bin/env bash\n%s update\n", appPath)); err != nil { + return err + } - // hook/post-update - pu2, err := os.OpenFile(filepath.Join(repoPath, "hooks", "post-receive"), os.O_CREATE|os.O_WRONLY, 0777) - if err != nil { - return err - } - defer pu2.Close() - // TODO: Windows .bat - if _, err = pu2.WriteString("#!/usr/bin/env bash\ngit update-server-info\n"); err != nil { - return err - } + // hook/post-update + pu2, err := os.OpenFile(filepath.Join(repoPath, "hooks", "post-receive"), os.O_CREATE|os.O_WRONLY, 0777) + if err != nil { + return err + } + defer pu2.Close() + // TODO: Windows .bat + if _, err = pu2.WriteString("#!/usr/bin/env bash\ngit update-server-info\n"); err != nil { + return err + } */ // Initialize repository according to user's choice. @@ -506,6 +506,37 @@ func GetWatches(repoId int64) ([]Watch, error) { return watches, err } +// NotifyWatchers creates batch of actions for every watcher. +func NotifyWatchers(userId, repoId int64, opType int, userName, repoName, refName, content string) error { + // Add feeds for user self and all watchers. + watches, err := GetWatches(repoId) + if err != nil { + return errors.New("repo.NotifyWatchers(get watches): " + err.Error()) + } + watches = append(watches, Watch{UserId: userId}) + + for i := range watches { + if userId == watches[i].UserId && i > 0 { + continue // Do not add twice in case author watches his/her repository. + } + + _, err = orm.InsertOne(&Action{ + UserId: watches[i].UserId, + ActUserId: userId, + ActUserName: userName, + OpType: opType, + Content: content, + RepoId: repoId, + RepoName: repoName, + RefName: refName, + }) + if err != nil { + return errors.New("repo.NotifyWatchers(create action): " + err.Error()) + } + } + return nil +} + // IsWatching checks if user has watched given repository. func IsWatching(userId, repoId int64) bool { has, _ := orm.Get(&Watch{0, repoId, userId}) |