diff --git a/README.md b/README.md index aa46fe0b6..c708bf55c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language ![Demo](http://gowalker.org/public/gogs_demo.gif) -##### Current version: 0.1.7 Alpha +##### Current version: 0.1.8 Alpha #### Other language version @@ -17,7 +17,7 @@ More importantly, Gogs only needs one binary to setup your own project hosting o ## Overview - Please see [Wiki](https://github.com/gogits/gogs/wiki) for project design, develop specification, change log and road map. -- See [Trello Broad](https://trello.com/b/uxAoeLUl/gogs-go-git-service) to follow the develop team. +- See [Trello Board](https://trello.com/b/uxAoeLUl/gogs-go-git-service) to follow the develop team. - Try it before anything? Do it [online](http://try.gogits.org/Unknown/gogs) or go down to **Installation -> Install from binary** section! - Having troubles? Get help from [Troubleshooting](https://github.com/gogits/gogs/wiki/Troubleshooting). @@ -29,7 +29,7 @@ More importantly, Gogs only needs one binary to setup your own project hosting o - Create/delete/watch public repository. - User profile page. - Repository viewer. -- Gravatar support. +- Gravatar and cache support. - Mail service(register). - Administration panel. - Supports MySQL, PostgreSQL and SQLite3(binary release only). diff --git a/README_ZH.md b/README_ZH.md index 440f952f8..ee9c3b7c4 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个由 Go 语言编写的自助 Git 托管服务。 ![Demo](http://gowalker.org/public/gogs_demo.gif) -##### 当前版本:0.1.7 Alpha +##### 当前版本:0.1.8 Alpha ## 开发目的 @@ -16,7 +16,7 @@ Gogs 完全使用 Go 语言来实现对 Git 数据的操作,实现 **零** 依 ## 项目概览 - 有关项目设计、开发说明、变更日志和路线图,请通过 [Wiki](https://github.com/gogits/gogs/wiki) 查看。 -- 您可以到 [Trello Broad](https://trello.com/b/uxAoeLUl/gogs-go-git-service) 跟随开发团队的脚步。 +- 您可以到 [Trello Board](https://trello.com/b/uxAoeLUl/gogs-go-git-service) 跟随开发团队的脚步。 - 想要先睹为快?通过 [在线体验](http://try.gogits.org/Unknown/gogs) 或查看 **安装部署 -> 二进制安装** 小节。 - 使用过程中遇到问题?尝试从 [故障排查](https://github.com/gogits/gogs/wiki/Troubleshooting) 页面获取帮助。 @@ -28,7 +28,7 @@ Gogs 完全使用 Go 语言来实现对 Git 数据的操作,实现 **零** 依 - 创建/删除/关注公开仓库 - 用户个人信息页面 - 仓库浏览器 -- Gravatar 支持 +- Gravatar 以及缓存支持 - 邮件服务(注册) - 管理员面板 - 支持 MySQL、PostgreSQL 以及 SQLite3(仅限二进制版本) diff --git a/conf/app.ini b/conf/app.ini index 809ea61c0..1a96ebeab 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -1,8 +1,8 @@ ; App name that shows on every page title APP_NAME = Gogs: Go Git Service APP_LOGO = img/favicon.png -; !!MUST CHANGE TO YOUR USER NAME!! -RUN_USER = lunny +; Change it if you run locally +RUN_USER = git ; Either "dev", "prod" or "test", default is "dev" RUN_MODE = dev @@ -164,4 +164,4 @@ RECEIVERS = [log.database] LEVEL = Driver = -CONN = \ No newline at end of file +CONN = diff --git a/diff.txt b/diff.txt new file mode 100644 index 000000000..7b2522f89 --- /dev/null +++ b/diff.txt @@ -0,0 +1,137 @@ +commit c1a3d4fefbbbf332cd1cedda66e93bf40cc9713d +Author: Unknown +Date: Tue Mar 25 21:37:18 2014 -0400 + + Add mail notify for creating issue + +diff --git a/gogs.go b/gogs.go +index b62580f..f5a328a 100644 +--- a/gogs.go ++++ b/gogs.go +@@ -19,7 +19,7 @@ import ( + // Test that go1.2 tag above is included in builds. main.go refers to this definition. + const go12tag = true + +-const APP_VER = "0.1.7.0325" ++const APP_VER = "0.1.8.0325" + + func init() { + base.AppVer = APP_VER +diff --git a/models/issue.go b/models/issue.go +index 2bdd083..2de6568 100644 +--- a/models/issue.go ++++ b/models/issue.go +@@ -59,7 +59,6 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, co + Content: content, + } + _, err = orm.Insert(issue) +- // TODO: newIssueAction + return issue, err + } + +diff --git a/modules/mailer/mail.go b/modules/mailer/mail.go +index 92acd20..d0decbe 100644 +--- a/modules/mailer/mail.go ++++ b/modules/mailer/mail.go +@@ -6,6 +6,7 @@ package mailer + + import ( + "encoding/hex" ++ "errors" + "fmt" + + "github.com/gogits/gogs/models" +@@ -15,12 +16,17 @@ import ( + ) + + // Create New mail message use MailFrom and MailUser +-func NewMailMessage(To []string, subject, body string) Message { +- msg := NewHtmlMessage(To, base.MailService.User, subject, body) ++func NewMailMessageFrom(To []string, from, subject, body string) Message { ++ msg := NewHtmlMessage(To, from, subject, body) + msg.User = base.MailService.User + return msg + } + ++// Create New mail message use MailFrom and MailUser ++func NewMailMessage(To []string, subject, body string) Message { ++ return NewMailMessageFrom(To, base.MailService.User, subject, body) ++} ++ + func GetMailTmplData(user *models.User) map[interface{}]interface{} { + data := make(map[interface{}]interface{}, 10) + data["AppName"] = base.AppName +@@ -84,3 +90,33 @@ func SendActiveMail(r *middleware.Render, user *models.User) { + + SendAsync(&msg) + } ++ ++// SendNotifyMail sends mail notification of all watchers. ++func SendNotifyMail(userId, repoId int64, userName, repoName, subject, content string) error { ++ watches, err := models.GetWatches(repoId) ++ if err != nil { ++ return errors.New("mail.NotifyWatchers(get watches): " + err.Error()) ++ } ++ ++ tos := make([]string, 0, len(watches)) ++ for i := range watches { ++ uid := watches[i].UserId ++ if userId == uid { ++ continue ++ } ++ u, err := models.GetUserById(uid) ++ if err != nil { ++ return errors.New("mail.NotifyWatchers(get user): " + err.Error()) ++ } ++ tos = append(tos, u.Email) ++ } ++ ++ if len(tos) == 0 { ++ return nil ++ } ++ ++ msg := NewMailMessageFrom(tos, userName, subject, content) ++ msg.Info = fmt.Sprintf("Subject: %s, send notify emails", subject) ++ SendAsync(&msg) ++ return nil ++} +diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go +index da63e01..63861d8 100644 +--- a/modules/mailer/mailer.go ++++ b/modules/mailer/mailer.go +@@ -33,7 +33,7 @@ func (m Message) Content() string { + } + + // create mail content +- content := "From: " + m.User + "<" + m.From + ++ content := "From: " + m.From + "<" + m.User + + ">\r\nSubject: " + m.Subject + "\r\nContent-Type: " + contentType + "\r\n\r\n" + m.Body + return content + } +diff --git a/routers/repo/issue.go b/routers/repo/issue.go +index fc5bb98..242593f 100644 +--- a/routers/repo/issue.go ++++ b/routers/repo/issue.go +@@ -13,6 +13,7 @@ import ( + "github.com/gogits/gogs/modules/auth" + "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/log" ++ "github.com/gogits/gogs/modules/mailer" + "github.com/gogits/gogs/modules/middleware" + ) + +@@ -86,6 +87,14 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat + return + } + ++ // Mail watchers. ++ if base.Service.NotifyMail { ++ if err = mailer.SendNotifyMail(ctx.User.Id, ctx.Repo.Repository.Id, ctx.User.Name, ctx.Repo.Repository.Name, issue.Name, issue.Content); err != nil { ++ ctx.Handle(200, "issue.CreateIssue", err) ++ return ++ } ++ } ++ + log.Trace("%d Issue created: %d", ctx.Repo.Repository.Id, issue.Id) + ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", params["username"], params["reponame"], issue.Index)) + } diff --git a/gogs.go b/gogs.go index 93b7231b7..f5a328add 100644 --- a/gogs.go +++ b/gogs.go @@ -7,7 +7,6 @@ package main import ( "os" - // "os/user" "runtime" "github.com/codegangsta/cli" @@ -20,28 +19,14 @@ import ( // Test that go1.2 tag above is included in builds. main.go refers to this definition. const go12tag = true -const APP_VER = "0.1.7.0324" +const APP_VER = "0.1.8.0325" func init() { base.AppVer = APP_VER runtime.GOMAXPROCS(runtime.NumCPU()) } -// func checkRunUser() bool { -// u, err := user.Current() -// if err != nil { -// // TODO: log -// return false -// } -// return u.Username == base.Cfg.MustValue("", "RUN_USER") -// } - func main() { - /*if !checkRunUser() { - println("The command should be run as", base.Cfg.MustValue("", "RUN_USER")) - return - }*/ - app := cli.NewApp() app.Name = "Gogs" app.Usage = "Go Git Service" diff --git a/models/action.go b/models/action.go index 44d7aea8c..edf1bf58f 100644 --- a/models/action.go +++ b/models/action.go @@ -19,6 +19,7 @@ const ( OP_STAR_REPO OP_FOLLOW_REPO OP_COMMIT_REPO + OP_CREATE_ISSUE OP_PULL_REQUEST ) @@ -59,7 +60,7 @@ func (a Action) GetContent() string { // CommitRepoAction records action for commit repository. func CommitRepoAction(userId int64, userName string, repoId int64, repoName string, refName string, commits *base.PushCommits) error { - log.Trace("action.CommitRepoAction: %d/%s", userId, repoName) + log.Trace("action.CommitRepoAction(start): %d/%s", userId, repoName) bs, err := json.Marshal(commits) if err != nil { @@ -67,32 +68,8 @@ func CommitRepoAction(userId int64, userName string, return err } - // Add feeds for user self and all watchers. - watches, err := GetWatches(repoId) - if err != nil { - log.Error("action.CommitRepoAction(get watches): %d/%s", userId, repoName) - return err - } - 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: OP_COMMIT_REPO, - Content: string(bs), - RepoId: repoId, - RepoName: repoName, - RefName: refName, - }) - if err != nil { - log.Error("action.CommitRepoAction(notify watches): %d/%s", userId, repoName) - } + if err = NotifyWatchers(userId, repoId, OP_COMMIT_REPO, userName, repoName, refName, string(bs)); err != nil { + log.Error("action.CommitRepoAction(notify watchers): %d/%s", userId, repoName) return err } @@ -107,6 +84,8 @@ func CommitRepoAction(userId int64, userName string, log.Error("action.CommitRepoAction(UpdateRepository): %d/%s", userId, repoName) return err } + + log.Trace("action.CommitRepoAction(end): %d/%s", userId, repoName) return nil } diff --git a/models/git.go b/models/git.go new file mode 100644 index 000000000..b0b0dd2f8 --- /dev/null +++ b/models/git.go @@ -0,0 +1,274 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package models + +import ( + "container/list" + "fmt" + "path" + "strings" + + "github.com/Unknwon/com" + + "github.com/gogits/git" +) + +// RepoFile represents a file object in git repository. +type RepoFile struct { + *git.TreeEntry + Path string + Size int64 + Repo *git.Repository + Commit *git.Commit +} + +// LookupBlob returns the content of an object. +func (file *RepoFile) LookupBlob() (*git.Blob, error) { + if file.Repo == nil { + return nil, ErrRepoFileNotLoaded + } + + return file.Repo.LookupBlob(file.Id) +} + +// GetBranches returns all branches of given repository. +func GetBranches(userName, reposName string) ([]string, error) { + repo, err := git.OpenRepository(RepoPath(userName, reposName)) + if err != nil { + return nil, err + } + + refs, err := repo.AllReferences() + if err != nil { + return nil, err + } + + brs := make([]string, len(refs)) + for i, ref := range refs { + brs[i] = ref.Name + } + return brs, nil +} + +func GetTargetFile(userName, reposName, branchName, commitId, rpath string) (*RepoFile, error) { + repo, err := git.OpenRepository(RepoPath(userName, reposName)) + if err != nil { + return nil, err + } + + commit, err := repo.GetCommit(branchName, commitId) + if err != nil { + return nil, err + } + + parts := strings.Split(path.Clean(rpath), "/") + + var entry *git.TreeEntry + tree := commit.Tree + for i, part := range parts { + if i == len(parts)-1 { + entry = tree.EntryByName(part) + if entry == nil { + return nil, ErrRepoFileNotExist + } + } else { + tree, err = repo.SubTree(tree, part) + if err != nil { + return nil, err + } + } + } + + size, err := repo.ObjectSize(entry.Id) + if err != nil { + return nil, err + } + + repoFile := &RepoFile{ + entry, + rpath, + size, + repo, + commit, + } + + return repoFile, nil +} + +// GetReposFiles returns a list of file object in given directory of repository. +func GetReposFiles(userName, reposName, branchName, commitId, rpath string) ([]*RepoFile, error) { + repo, err := git.OpenRepository(RepoPath(userName, reposName)) + if err != nil { + return nil, err + } + + commit, err := repo.GetCommit(branchName, commitId) + if err != nil { + return nil, err + } + + var repodirs []*RepoFile + var repofiles []*RepoFile + commit.Tree.Walk(func(dirname string, entry *git.TreeEntry) int { + if dirname == rpath { + // TODO: size get method shoule be improved + size, err := repo.ObjectSize(entry.Id) + if err != nil { + return 0 + } + + var cm = commit + var i int + for { + i = i + 1 + //fmt.Println(".....", i, cm.Id(), cm.ParentCount()) + if cm.ParentCount() == 0 { + break + } else if cm.ParentCount() == 1 { + pt, _ := repo.SubTree(cm.Parent(0).Tree, dirname) + if pt == nil { + break + } + pEntry := pt.EntryByName(entry.Name) + if pEntry == nil || !pEntry.Id.Equal(entry.Id) { + break + } else { + cm = cm.Parent(0) + } + } else { + var emptyCnt = 0 + var sameIdcnt = 0 + var lastSameCm *git.Commit + //fmt.Println(".....", cm.ParentCount()) + for i := 0; i < cm.ParentCount(); i++ { + //fmt.Println("parent", i, cm.Parent(i).Id()) + p := cm.Parent(i) + pt, _ := repo.SubTree(p.Tree, dirname) + var pEntry *git.TreeEntry + if pt != nil { + pEntry = pt.EntryByName(entry.Name) + } + + //fmt.Println("pEntry", pEntry) + + if pEntry == nil { + emptyCnt = emptyCnt + 1 + if emptyCnt+sameIdcnt == cm.ParentCount() { + if lastSameCm == nil { + goto loop + } else { + cm = lastSameCm + break + } + } + } else { + //fmt.Println(i, "pEntry", pEntry.Id, "entry", entry.Id) + if !pEntry.Id.Equal(entry.Id) { + goto loop + } else { + lastSameCm = cm.Parent(i) + sameIdcnt = sameIdcnt + 1 + if emptyCnt+sameIdcnt == cm.ParentCount() { + // TODO: now follow the first parent commit? + cm = lastSameCm + //fmt.Println("sameId...") + break + } + } + } + } + } + } + + loop: + + rp := &RepoFile{ + entry, + path.Join(dirname, entry.Name), + size, + repo, + cm, + } + + if entry.IsFile() { + repofiles = append(repofiles, rp) + } else if entry.IsDir() { + repodirs = append(repodirs, rp) + } + } + return 0 + }) + + return append(repodirs, repofiles...), nil +} + +func GetCommit(userName, repoName, branchname, commitid string) (*git.Commit, error) { + repo, err := git.OpenRepository(RepoPath(userName, repoName)) + if err != nil { + return nil, err + } + + return repo.GetCommit(branchname, commitid) +} + +// GetCommits returns all commits of given branch of repository. +func GetCommits(userName, reposName, branchname string) (*list.List, error) { + repo, err := git.OpenRepository(RepoPath(userName, reposName)) + if err != nil { + return nil, err + } + r, err := repo.LookupReference(fmt.Sprintf("refs/heads/%s", branchname)) + if err != nil { + return nil, err + } + return r.AllCommits() +} + +type DiffFile struct { + Name string + Addition, Deletion int + Type string + Content []string +} + +type Diff struct { + NumFiles int // Number of file has been changed. + TotalAddition, TotalDeletion int + Files []*DiffFile +} + +func GetDiff(repoPath, commitid string) (*Diff, error) { + stdout, _, err := com.ExecCmdDir(repoPath, "git", "show", commitid) + if err != nil { + return nil, err + } + + // Sperate parts by file. + startIndex := strings.Index(stdout, "diff --git ") + 12 + + // First part is commit information. + // Check if it's a merge. + mergeIndex := strings.Index(stdout[:startIndex], "merge") + if mergeIndex > -1 { + mergeCommit := strings.SplitN(strings.Split(stdout[:startIndex], "\n")[1], "", 3)[2] + return GetDiff(repoPath, mergeCommit) + } + + parts := strings.Split(stdout[startIndex:], "diff --git ") + diff := &Diff{NumFiles: len(parts)} + diff.Files = make([]*DiffFile, 0, diff.NumFiles) + for _, part := range parts { + infos := strings.SplitN(part, "\n", 6) + maxIndex := len(infos) - 1 + infos[maxIndex] = strings.TrimSuffix(strings.TrimSuffix(infos[maxIndex], "\n"), "\n\\ No newline at end of file") + + file := &DiffFile{ + Name: strings.TrimPrefix(strings.Split(infos[0], " ")[0], "a/"), + Content: strings.Split(infos[maxIndex], "\n"), + } + diff.Files = append(diff.Files, file) + } + return diff, nil +} diff --git a/models/issue.go b/models/issue.go index fe43a94b5..2de656858 100644 --- a/models/issue.go +++ b/models/issue.go @@ -23,6 +23,7 @@ type Issue struct { Name string RepoId int64 `xorm:"index"` PosterId int64 + Poster *User `xorm:"-"` MilestoneId int64 AssigneeId int64 IsPull bool // Indicates whether is a pull request or not. @@ -58,7 +59,6 @@ func CreateIssue(userId, repoId, milestoneId, assigneeId int64, name, labels, co Content: content, } _, err = orm.Insert(issue) - // TODO: newIssueAction return issue, err } diff --git a/models/repo.go b/models/repo.go index 84c328388..477f9472b 100644 --- a/models/repo.go +++ b/models/repo.go @@ -5,17 +5,14 @@ package models import ( - "container/list" "errors" "fmt" "io/ioutil" "os" "os/exec" - "path" "path/filepath" "regexp" "strings" - "sync" "time" "unicode/utf8" @@ -36,8 +33,6 @@ var ( ErrRepoFileNotLoaded = fmt.Errorf("repo file not loaded") ) -var gitInitLocker = sync.Mutex{} - var ( LanguageIgns, Licenses []string ) @@ -222,33 +217,21 @@ func extractGitBareZip(repoPath string) error { } // initRepoCommit temporarily changes with work directory. -func initRepoCommit(tmpPath string, sig *git.Signature) error { - gitInitLocker.Lock() - defer gitInitLocker.Unlock() - - // Change work directory. - curPath, err := os.Getwd() - if err != nil { - return err - } else if err = os.Chdir(tmpPath); err != nil { - return err - } - defer os.Chdir(curPath) - +func initRepoCommit(tmpPath string, sig *git.Signature) (err error) { var stderr string - if _, stderr, err = com.ExecCmd("git", "add", "--all"); err != nil { + if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "add", "--all"); err != nil { return err } - log.Info("stderr(1): %s", stderr) - if _, stderr, err = com.ExecCmd("git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email), + log.Trace("stderr(1): %s", stderr) + if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email), "-m", "Init commit"); err != nil { return err } - log.Info("stderr(2): %s", stderr) - if _, stderr, err = com.ExecCmd("git", "push", "origin", "master"); err != nil { + log.Trace("stderr(2): %s", stderr) + if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "push", "origin", "master"); err != nil { return err } - log.Info("stderr(3): %s", stderr) + log.Trace("stderr(3): %s", stderr) return nil } @@ -272,18 +255,6 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep 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. fileName := map[string]string{} if initReadme { @@ -505,239 +476,43 @@ 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}) return has } -func StarReposiory(user *User, repoName string) error { - return nil -} - -func UnStarRepository() { - -} - -func WatchRepository() { - -} - -func UnWatchRepository() { - -} - func ForkRepository(reposName string, userId int64) { } - -// RepoFile represents a file object in git repository. -type RepoFile struct { - *git.TreeEntry - Path string - Size int64 - Repo *git.Repository - Commit *git.Commit -} - -// LookupBlob returns the content of an object. -func (file *RepoFile) LookupBlob() (*git.Blob, error) { - if file.Repo == nil { - return nil, ErrRepoFileNotLoaded - } - - return file.Repo.LookupBlob(file.Id) -} - -// GetBranches returns all branches of given repository. -func GetBranches(userName, reposName string) ([]string, error) { - repo, err := git.OpenRepository(RepoPath(userName, reposName)) - if err != nil { - return nil, err - } - - refs, err := repo.AllReferences() - if err != nil { - return nil, err - } - - brs := make([]string, len(refs)) - for i, ref := range refs { - brs[i] = ref.BranchName() - } - return brs, nil -} - -func GetTargetFile(userName, reposName, branchName, commitId, rpath string) (*RepoFile, error) { - repo, err := git.OpenRepository(RepoPath(userName, reposName)) - if err != nil { - return nil, err - } - - commit, err := repo.GetCommit(branchName, commitId) - if err != nil { - return nil, err - } - - parts := strings.Split(path.Clean(rpath), "/") - - var entry *git.TreeEntry - tree := commit.Tree - for i, part := range parts { - if i == len(parts)-1 { - entry = tree.EntryByName(part) - if entry == nil { - return nil, ErrRepoFileNotExist - } - } else { - tree, err = repo.SubTree(tree, part) - if err != nil { - return nil, err - } - } - } - - size, err := repo.ObjectSize(entry.Id) - if err != nil { - return nil, err - } - - repoFile := &RepoFile{ - entry, - rpath, - size, - repo, - commit, - } - - return repoFile, nil -} - -// GetReposFiles returns a list of file object in given directory of repository. -func GetReposFiles(userName, reposName, branchName, commitId, rpath string) ([]*RepoFile, error) { - repo, err := git.OpenRepository(RepoPath(userName, reposName)) - if err != nil { - return nil, err - } - - commit, err := repo.GetCommit(branchName, commitId) - if err != nil { - return nil, err - } - - var repodirs []*RepoFile - var repofiles []*RepoFile - commit.Tree.Walk(func(dirname string, entry *git.TreeEntry) int { - if dirname == rpath { - // TODO: size get method shoule be improved - size, err := repo.ObjectSize(entry.Id) - if err != nil { - return 0 - } - - var cm = commit - var i int - for { - i = i + 1 - //fmt.Println(".....", i, cm.Id(), cm.ParentCount()) - if cm.ParentCount() == 0 { - break - } else if cm.ParentCount() == 1 { - pt, _ := repo.SubTree(cm.Parent(0).Tree, dirname) - if pt == nil { - break - } - pEntry := pt.EntryByName(entry.Name) - if pEntry == nil || !pEntry.Id.Equal(entry.Id) { - break - } else { - cm = cm.Parent(0) - } - } else { - var emptyCnt = 0 - var sameIdcnt = 0 - var lastSameCm *git.Commit - //fmt.Println(".....", cm.ParentCount()) - for i := 0; i < cm.ParentCount(); i++ { - //fmt.Println("parent", i, cm.Parent(i).Id()) - p := cm.Parent(i) - pt, _ := repo.SubTree(p.Tree, dirname) - var pEntry *git.TreeEntry - if pt != nil { - pEntry = pt.EntryByName(entry.Name) - } - - //fmt.Println("pEntry", pEntry) - - if pEntry == nil { - emptyCnt = emptyCnt + 1 - if emptyCnt+sameIdcnt == cm.ParentCount() { - if lastSameCm == nil { - goto loop - } else { - cm = lastSameCm - break - } - } - } else { - //fmt.Println(i, "pEntry", pEntry.Id, "entry", entry.Id) - if !pEntry.Id.Equal(entry.Id) { - goto loop - } else { - lastSameCm = cm.Parent(i) - sameIdcnt = sameIdcnt + 1 - if emptyCnt+sameIdcnt == cm.ParentCount() { - // TODO: now follow the first parent commit? - cm = lastSameCm - //fmt.Println("sameId...") - break - } - } - } - } - } - } - - loop: - - rp := &RepoFile{ - entry, - path.Join(dirname, entry.Name), - size, - repo, - cm, - } - - if entry.IsFile() { - repofiles = append(repofiles, rp) - } else if entry.IsDir() { - repodirs = append(repodirs, rp) - } - } - return 0 - }) - - return append(repodirs, repofiles...), nil -} - -func GetCommit(userName, repoName, branchname, commitid string) (*git.Commit, error) { - repo, err := git.OpenRepository(RepoPath(userName, repoName)) - if err != nil { - return nil, err - } - - return repo.GetCommit(branchname, commitid) -} - -// GetCommits returns all commits of given branch of repository. -func GetCommits(userName, reposName, branchname string) (*list.List, error) { - repo, err := git.OpenRepository(RepoPath(userName, reposName)) - if err != nil { - return nil, err - } - r, err := repo.LookupReference(fmt.Sprintf("refs/heads/%s", branchname)) - if err != nil { - return nil, err - } - return r.AllCommits() -} diff --git a/modules/auth/issue.go b/modules/auth/issue.go index e2b1f9f2a..8bf49684c 100644 --- a/modules/auth/issue.go +++ b/modules/auth/issue.go @@ -17,9 +17,8 @@ import ( ) type CreateIssueForm struct { - IssueName string `form:"name" binding:"Required;MaxSize(50)"` - RepoId int64 `form:"repoid" binding:"Required"` - MilestoneId int64 `form:"milestoneid" binding:"Required"` + IssueName string `form:"title" binding:"Required;MaxSize(50)"` + MilestoneId int64 `form:"milestoneid"` AssigneeId int64 `form:"assigneeid"` Labels string `form:"labels"` Content string `form:"content"` @@ -27,9 +26,7 @@ type CreateIssueForm struct { func (f *CreateIssueForm) Name(field string) string { names := map[string]string{ - "IssueName": "Issue name", - "RepoId": "Repository ID", - "MilestoneId": "Milestone ID", + "IssueName": "Issue name", } return names[field] } diff --git a/modules/avatar/avatar.go b/modules/avatar/avatar.go index 0ba20294a..449c9656d 100644 --- a/modules/avatar/avatar.go +++ b/modules/avatar/avatar.go @@ -30,8 +30,9 @@ import ( "sync" "time" - "github.com/gogits/gogs/modules/log" "github.com/nfnt/resize" + + "github.com/gogits/gogs/modules/log" ) var ( @@ -251,8 +252,8 @@ var client = &http.Client{} func (this *thunderTask) fetch() error { req, _ := http.NewRequest("GET", this.Url, nil) - req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8") - req.Header.Set("Accept-Encoding", "gzip,deflate,sdch") + req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/jpeg,image/png,*/*;q=0.8") + req.Header.Set("Accept-Encoding", "deflate,sdch") req.Header.Set("Accept-Language", "zh-CN,zh;q=0.8") req.Header.Set("Cache-Control", "no-cache") req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36") diff --git a/modules/base/conf.go b/modules/base/conf.go index 90b354764..0fb1ccdcf 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -71,7 +71,7 @@ var Service struct { ResetPwdCodeLives int } -func exeDir() (string, error) { +func ExecDir() (string, error) { file, err := exec.LookPath(os.Args[0]) if err != nil { return "", err @@ -244,7 +244,7 @@ func newNotifyMailService() { func NewConfigContext() { //var err error - workDir, err := exeDir() + workDir, err := ExecDir() if err != nil { fmt.Printf("Fail to get work directory: %s\n", err) os.Exit(2) @@ -259,16 +259,11 @@ func NewConfigContext() { Cfg.BlockMode = false cfgPath = filepath.Join(workDir, "custom/conf/app.ini") - if !com.IsFile(cfgPath) { - fmt.Println("Custom configuration not found(custom/conf/app.ini)\n" + - "Please create it and make your own configuration!") - os.Exit(2) - - } - - if err = Cfg.AppendFiles(cfgPath); err != nil { - fmt.Printf("Cannot load config file '%s'\n", cfgPath) - os.Exit(2) + if com.IsFile(cfgPath) { + if err = Cfg.AppendFiles(cfgPath); err != nil { + fmt.Printf("Cannot load config file '%s'\n", cfgPath) + os.Exit(2) + } } AppName = Cfg.MustValue("", "APP_NAME", "Gogs: Go Git Service") @@ -276,7 +271,16 @@ func NewConfigContext() { AppUrl = Cfg.MustValue("server", "ROOT_URL") Domain = Cfg.MustValue("server", "DOMAIN") SecretKey = Cfg.MustValue("security", "SECRET_KEY") + RunUser = Cfg.MustValue("", "RUN_USER") + curUser := os.Getenv("USERNAME") + if len(curUser) == 0 { + curUser = os.Getenv("USER") + } + if RunUser != curUser { + fmt.Printf("Expect user(%s) but current user is: %s\n", RunUser, curUser) + os.Exit(2) + } EnableHttpsClone = Cfg.MustBool("security", "ENABLE_HTTPS_CLONE", false) diff --git a/modules/base/tool.go b/modules/base/tool.go index 4a8a124dd..8f38d492a 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -102,7 +102,10 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string // AvatarLink returns avatar link by given e-mail. func AvatarLink(email string) string { - return "/avatar/" + EncodeMd5(email) + if Service.EnableCacheAvatar { + return "/avatar/" + EncodeMd5(email) + } + return "http://1.gravatar.com/avatar/" + EncodeMd5(email) } // Seconds-based time units @@ -483,15 +486,19 @@ func ActionIcon(opType int) string { return "plus-circle" case 5: // Commit repository. return "arrow-circle-o-right" + case 6: // Create issue. + return "exclamation-circle" default: return "invalid type" } } const ( - TPL_CREATE_REPO = `%s created repository %s` - TPL_COMMIT_REPO = `%s pushed to %s at %s/%s%s` - TPL_COMMIT_REPO_LI = `
user-avatar %s %s
` + TPL_CREATE_REPO = `%s created repository %s` + TPL_COMMIT_REPO = `%s pushed to %s at %s%s` + TPL_COMMIT_REPO_LI = `
user-avatar %s %s
` + TPL_CREATE_Issue = `%s opened issue %s#%s +
user-avatar %s
` ) type PushCommits struct { @@ -504,11 +511,12 @@ type PushCommits struct { func ActionDesc(act Actioner, avatarLink string) string { actUserName := act.GetActUserName() repoName := act.GetRepoName() + repoLink := actUserName + "/" + repoName branch := act.GetBranch() content := act.GetContent() switch act.GetOpType() { case 1: // Create repository. - return fmt.Sprintf(TPL_CREATE_REPO, actUserName, actUserName, actUserName, repoName, repoName) + return fmt.Sprintf(TPL_CREATE_REPO, actUserName, actUserName, repoLink, repoName) case 5: // Commit repository. var push *PushCommits if err := json.Unmarshal([]byte(content), &push); err != nil { @@ -516,13 +524,17 @@ func ActionDesc(act Actioner, avatarLink string) string { } buf := bytes.NewBuffer([]byte("\n")) for _, commit := range push.Commits { - buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, avatarLink, actUserName, repoName, commit[0], commit[0][:7], commit[1]) + "\n") + buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, avatarLink, repoLink, commit[0], commit[0][:7], commit[1]) + "\n") } if push.Len > 3 { buf.WriteString(fmt.Sprintf(`
%d other commits >>
`, actUserName, repoName, branch, push.Len)) } - return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, actUserName, repoName, branch, branch, actUserName, repoName, actUserName, repoName, + return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink, buf.String()) + case 6: // Create issue. + infos := strings.SplitN(content, "|", 2) + return fmt.Sprintf(TPL_CREATE_Issue, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0], + avatarLink, infos[1]) default: return "invalid type" } diff --git a/modules/log/log.go b/modules/log/log.go index 0c07c7c62..e1bab8ae4 100644 --- a/modules/log/log.go +++ b/modules/log/log.go @@ -9,7 +9,10 @@ import ( "github.com/gogits/logs" ) -var logger *logs.BeeLogger +var ( + logger *logs.BeeLogger + Mode, Config string +) func init() { logger = logs.NewLogger(10000) @@ -17,6 +20,7 @@ func init() { } func NewLogger(bufLen int64, mode, config string) { + Mode, Config = mode, config logger = logs.NewLogger(bufLen) logger.SetLogger(mode, config) } diff --git a/modules/mailer/mail.go b/modules/mailer/mail.go index 92acd20ef..d0decbe06 100644 --- a/modules/mailer/mail.go +++ b/modules/mailer/mail.go @@ -6,6 +6,7 @@ package mailer import ( "encoding/hex" + "errors" "fmt" "github.com/gogits/gogs/models" @@ -15,12 +16,17 @@ import ( ) // Create New mail message use MailFrom and MailUser -func NewMailMessage(To []string, subject, body string) Message { - msg := NewHtmlMessage(To, base.MailService.User, subject, body) +func NewMailMessageFrom(To []string, from, subject, body string) Message { + msg := NewHtmlMessage(To, from, subject, body) msg.User = base.MailService.User return msg } +// Create New mail message use MailFrom and MailUser +func NewMailMessage(To []string, subject, body string) Message { + return NewMailMessageFrom(To, base.MailService.User, subject, body) +} + func GetMailTmplData(user *models.User) map[interface{}]interface{} { data := make(map[interface{}]interface{}, 10) data["AppName"] = base.AppName @@ -84,3 +90,33 @@ func SendActiveMail(r *middleware.Render, user *models.User) { SendAsync(&msg) } + +// SendNotifyMail sends mail notification of all watchers. +func SendNotifyMail(userId, repoId int64, userName, repoName, subject, content string) error { + watches, err := models.GetWatches(repoId) + if err != nil { + return errors.New("mail.NotifyWatchers(get watches): " + err.Error()) + } + + tos := make([]string, 0, len(watches)) + for i := range watches { + uid := watches[i].UserId + if userId == uid { + continue + } + u, err := models.GetUserById(uid) + if err != nil { + return errors.New("mail.NotifyWatchers(get user): " + err.Error()) + } + tos = append(tos, u.Email) + } + + if len(tos) == 0 { + return nil + } + + msg := NewMailMessageFrom(tos, userName, subject, content) + msg.Info = fmt.Sprintf("Subject: %s, send notify emails", subject) + SendAsync(&msg) + return nil +} diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go index da63e01d2..63861d870 100644 --- a/modules/mailer/mailer.go +++ b/modules/mailer/mailer.go @@ -33,7 +33,7 @@ func (m Message) Content() string { } // create mail content - content := "From: " + m.User + "<" + m.From + + content := "From: " + m.From + "<" + m.User + ">\r\nSubject: " + m.Subject + "\r\nContent-Type: " + contentType + "\r\n\r\n" + m.Body return content } diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index eea2570ca..bc90c05cc 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -73,9 +73,14 @@ func RepoAssignment(redirect bool) martini.Handler { if base.EnableHttpsClone { scheme = "https" } - ctx.Repo.CloneLink.SSH = fmt.Sprintf("git@%s:%s/%s.git", base.Domain, user.LowerName, repo.LowerName) + ctx.Repo.CloneLink.SSH = fmt.Sprintf("%s@%s:%s/%s.git", base.RunUser, base.Domain, user.LowerName, repo.LowerName) ctx.Repo.CloneLink.HTTPS = fmt.Sprintf("%s://%s/%s/%s.git", scheme, base.Domain, user.LowerName, repo.LowerName) + if len(params["branchname"]) == 0 { + params["branchname"] = "master" + } + ctx.Data["Branchname"] = params["branchname"] + ctx.Data["IsRepositoryValid"] = true ctx.Data["Repository"] = repo ctx.Data["Owner"] = user diff --git a/public/css/gogs.css b/public/css/gogs.css index 2254ef5a2..6bf698e8b 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -52,14 +52,14 @@ html, body { } /* gogits nav header */ -.gogs-masthead { +.masthead { background-color: #428bca; box-shadow: inset 0 -2px 5px rgba(0, 0, 0, .1); margin: 0; } /* gogits nav item link */ -.gogs-nav-item { +.nav-item { position: relative; display: inline-block; padding: 10px; @@ -69,39 +69,39 @@ html, body { height: 46px; } -#gogs-nav-logo { +#nav-logo { padding-left: 0; padding-right: 0; margin-right: 10px; } -.gogs-nav-item:hover, -.gogs-nav-item:focus { +.nav-item:hover, +.nav-item:focus { color: #fff; text-decoration: none; } -.gogs-nav-item.navbar-right { +.nav-item.navbar-right { margin-top: 3px; } -.gogs-nav-item.navbar-btn { +.nav-item.navbar-btn { cursor: pointer; margin-top: 8px; padding: 5px 15px; height: 30px; } -.gogs-nav-item.navbar-right .fa { +.nav-item.navbar-right .fa { margin: 0; } /* gogits nav item active status */ -.gogs-nav .active { +#masthead .nav .active { color: #fff; } -.gogs-nav .active:after { +#masthead .nav .active:after { position: absolute; bottom: -1px; left: 50%; @@ -115,29 +115,29 @@ html, body { border-left: 5px solid transparent; } -#gogs-nav-logo:after { +#nav-logo:after { bottom: -4px !important; } -#gogs-nav-avatar:after { +#nav-avatar:after { bottom: -4px !important; } -.gogs-nav .tooltip { +.nav .tooltip { border: none; } /* gogits logo */ -#gogs-nav-avatar { +#nav-avatar { margin-top: 0; } -#gogs-logo, #gogs-nav-avatar img { +#logo, #nav-avatar img { width: 28px; height: 28px; } -#gogs-nav-out { +#nav-out { margin-top: 10px; padding: 5px 0; margin-left: 10px; @@ -145,56 +145,56 @@ html, body { float: right; } -#gogs-nav-signin, #gogs-nav-signup { +#nav-signin, #nav-signup { float: right; margin-left: 1em; } -#gogs-nav-out .fa { +#nav-out .fa { vertical-align: -10%; margin: 0 .5em; } /* gogits body */ -#gogs-body { +#body { padding-bottom: 60px; margin-top: 30px; } -#gogs-body .btn-default { +#body .btn-default { background-color: #FFF; background-image: linear-gradient(to bottom, #FFF 0, #FAFAFA 100%); } -#gogs-body-nav { +#body-nav { background-color: #FFF; border-bottom: 1px solid #DDD; height: 66px } -#gogs-body-nav .nav { +#body-nav .nav { font-size: 14px; margin-top: 12px; } -#gogs-body-nav .nav-pills li a { +#body-nav .nav-pills li a { color: #444; } -#gogs-body-nav .nav-pills li.active a { +#body-nav .nav-pills li.active a { font-weight: bold; border-bottom: 2px solid #d26911; background-color: transparent; color: #444; } -#gogs-body-nav .nav-pills li:hover a { +#body-nav .nav-pills li:hover a { background-color: transparent; text-decoration: underline; } /* gogits login card */ -.gogs-card { +.card { margin: auto; padding: 30px; background: #fff; @@ -203,87 +203,87 @@ html, body { box-sizing: border-box; } -.gogs-card h3 { +.card h3 { margin-top: 0; margin-bottom: 30px; padding-bottom: 20px; border-bottom: 1px solid #ccc; } -#gogs-login-card { +#login-card { width: 600px; } -#gogs-login-card .form-control { +#login-card .form-control { padding: 6px 12px; box-sizing: content-box; } -#gogs-login-card .control-label { +#login-card .control-label { height: 44px; line-height: 30px; } -#gogs-install-card{ +#install-card { width: 800px; } -#gogs-install-card .form-group { +#install-card .form-group { margin-left: 0; margin-right: 0; } -.gogs-card .btn { +.card .btn { cursor: pointer; margin-right: 1.2em; } -#gogs-social-login { +#social-login { margin-top: 30px; padding-top: 20px; border-top: 1px solid #ccc; } -#gogs-social-login .btn { +#social-login .btn { float: none; margin: auto; } /* gogs-user-profile */ -#gogs-user-avatar { +#user-avatar { width: 200px; height: 200px; border-radius: 6px; } -#gogs-user-avatar-commit { +#user-avatar-commit { width: 16px; height: 16px; border-radius: 2px; } -#gogs-user-name { +#user-name { margin-top: 20px; font-size: 1.6em; font-weight: bold; margin-bottom: 20px; } -#gogs-user-profile .profile-info .list-group-item { +#user-profile .profile-info .list-group-item { background-color: transparent; padding-top: 18px; color: #666; } -#gogs-user-profile .profile-info .list-group-item a { +#user-profile .profile-info .list-group-item a { margin: 0; padding: 0; display: inline; color: #0093c4; } -#gogs-user-profile .profile-info .list-group { +#user-profile .profile-info .list-group { border-top: 1px solid #ccc; padding-bottom: 18px; border-bottom: 1px solid #ccc; @@ -291,50 +291,50 @@ html, body { padding-right: 18px; } -#gogs-user-activity .tab-pane { +#user-activity .tab-pane { padding: 20px; } -#gogs-user-act-tabs li.active a { +#user-act-tabs li.active a { border-bottom-color: #ddd; } /* gogits repo create */ -#gogs-repo-create { +#repo-create { width: 800px; } -#gogs-repo-create textarea[name=desc] { +#repo-create textarea[name=desc] { height: 8em; } /* gogits user setting */ -#gogs-user-setting-nav > h4, #gogs-user-setting-container > h4, #gogs-user-setting-container > div > h4, -#gogs-ssh-keys > h4, #gogs-user-delete > h4, #gogs-repo-setting-container .tab-pane > h4 { +#user-setting-nav > h4, #user-setting-container > h4, #user-setting-container > div > h4, +#ssh-keys > h4, #user-delete > h4, #repo-setting-container .tab-pane > h4 { padding-bottom: 18px; margin-bottom: 18px; border-bottom: 1px solid #CCC; } -#gogs-user-setting-nav .list-group .list-group-item a { +#user-setting-nav .list-group .list-group-item a { margin-left: 0; padding: .6em; font-size: 14px; color: #3B73AF; } -#gogs-user-setting-nav .list-group .list-group-item { +#user-setting-nav .list-group .list-group-item { background-color: transparent; } -#gogs-user-setting-nav .list-group .list-group-item-success a { +#user-setting-nav .list-group .list-group-item-success a { font-weight: bold; color: #444; } -.gogs-admin-nav { +.admin-nav { background-color: #FFF; padding-top: 10px; padding-left: 0; @@ -342,49 +342,49 @@ html, body { border: 1px solid #D8D8D8; } -.gogs-admin-nav li { +.admin-nav li { margin-bottom: 8px; border-left: 4px solid transparent; } -.gogs-admin-nav li:hover { +.admin-nav li:hover { border-left-color: #EEE; } -.gogs-admin-nav li.active:hover { +.admin-nav li.active:hover { border-left: 4px solid #DD4B39; } -#gogs-repo-setting-container .form-horizontal label { +#repo-setting-container .form-horizontal label { line-height: 30px; } /* gogits user ssh keys */ -#gogs-ssh-keys .list-group-item { +#ssh-keys .list-group-item { padding: 15px 0; border-bottom: 1px solid #DDD; } -#gogs-ssh-keys .list-group-item .delete { +#ssh-keys .list-group-item .delete { margin: -5px 50px 0; } -#gogs-ssh-keys .list-group-item:after { +#ssh-keys .list-group-item:after { clear: both; } -#gogs-ssh-keys .name { +#ssh-keys .name { font-size: 14px; font-weight: bold; } -#gogs-ssh-keys .print { +#ssh-keys .print { padding-left: 1em; color: #888; } -#gogs-ssh-add { +#ssh-add { display: inline-block; color: white; cursor: pointer; @@ -392,25 +392,25 @@ html, body { border-radius: 3px; } -#gogs-ssh-form textarea { +#ssh-form textarea { height: 16em; } -/* #gogs-feed */ +/* #feed */ -#gogs-feed-right .repo-panel .panel-heading .btn { +#feed-right .repo-panel .panel-heading .btn { margin-top: -4px; } -#gogs-feed-right .repo-panel .panel-body { +#feed-right .repo-panel .panel-body { padding: 0; } -#gogs-feed-right .repo-panel .list-group { +#feed-right .repo-panel .list-group { margin-bottom: 0; } -#gogs-feed-right .repo-panel .list-group-item a { +#feed-right .repo-panel .list-group-item a { display: block; margin-left: 0; background-color: transparent; @@ -418,11 +418,11 @@ html, body { font-weight: bold; } -#gogs-feed-right .repo-panel .list-group-item .fa { +#feed-right .repo-panel .list-group-item .fa { color: #666; } -#gogs-feed-right .repo-panel .list-group-item { +#feed-right .repo-panel .list-group-item { font-size: 14px; line-height: 32px; border-bottom: 1px solid #DDD; @@ -430,97 +430,109 @@ html, body { clear: both; } -#gogs-feed-right .repo-panel .list-group-item:last-child { +#feed-right .repo-panel .list-group-item:last-child { border-bottom: none; } -#gogs-feed-right .repo-panel .list-group-item:hover { +#feed-right .repo-panel .list-group-item:hover { background-color: #eafffd; background-color: rgba(65, 131, 196, 0.1); } -#gogs-feed-right .repo-panel span.stars { +#feed-right .repo-panel span.stars { color: #666; margin-right: 1em; } /* gogits repo single page */ -#gogs-body-nav.gogs-repo-nav { +#body-nav.repo-nav { padding-top: 16px; padding-bottom: 30px; height: auto; } -.gogs-repo-nav .name { +.repo-nav .name { margin-top: 15px; } -.gogs-repo-nav .desc { +.repo-nav .desc { color: #888; margin-bottom: 0; } -.gogs-repo-nav h3 .fa { +.repo-nav h3 .fa { color: #BBB; margin-left: 0; } -.gogs-repo-nav .actions { +.repo-nav .actions { padding-top: 20px; } -.gogs-repo-nav .btn-default { +.repo-nav .btn-default { font-family: Tahoma, Arial, sans-serif; } -#gogs-repo-watching .dropdown-menu { +#repo-watching .dropdown-menu { width: 280px; padding: 0; } -#gogs-repo-watching .dropdown-menu .dropdown-item:hover .dropdown-header, #gogs-repo-watching .dropdown-item .dropdown-header.text-primary { +#repo-watching .dropdown-menu .dropdown-item:hover .dropdown-header, #repo-watching .dropdown-item .dropdown-header.text-primary { color: rgb(65, 131, 196); cursor: pointer; } -#gogs-repo-watching .dropdown-menu .description { +#repo-watching .dropdown-menu .description { padding: 0 20px; color: #888; } -#gogs-repo-watching .dropdown-menu .dropdown-header { +#repo-watching .dropdown-menu .dropdown-header { color: #444; font-weight: bold; font-size: 14px; margin-bottom: 4px; } -#gogs-repo-toolbar { +#repo-toolbar { border-bottom: 1px solid #DDD; background-color: #FFF; height: 40px; font-size: 14px; } -#gogs-repo-toolbar .navbar-default { +#repo-toolbar .navbar-default { border: none; height: 39px; } -#gogs-repo-toolbar .nav > li > a { +#repo-toolbar .nav > li > a { height: 39px; } -#gogs-repo-toolbar .navbar-toolbar.navbar-default .navbar-nav > .active > a:after { +#repo-toolbar .nav .tmp a:hover { + text-decoration: none; +} + +#repo-toolbar .nav .tmp .btn { + margin-top: -2px; +} + +#repo-toolbar .nav .active { + color: #F6F6F6; +} + +#repo-toolbar .nav > .active > a:after { border-bottom-color: #999; } -#gogs-repo-toolbar .navbar.nav-toolbar { +#repo-toolbar .navbar.nav-toolbar { margin-bottom: 0; } -#gogs-repo-toolbar .navbar-collapse { +#repo-toolbar .navbar-collapse { padding: 0; } @@ -588,29 +600,29 @@ html, body { min-width: 200px; } -#gogs-repo-clone .dropdown-menu { +#repo-clone .dropdown-menu { width: 400px; padding: 20px; } -#gogs-repo-clone .input-group { +#repo-clone .input-group { margin-bottom: 15px; } -/* #gogs-source */ -#gogs-source { +/* #source */ +#source, #commits { margin-top: -20px; } -#gogs-source .source-toolbar:after { +#source .source-toolbar:after { clear: both; } -#gogs-source .source-toolbar .branch-switch { +#source .source-toolbar .branch-switch { display: inline-block; } -#gogs-source .source-toolbar .breadcrumb { +#source .source-toolbar .breadcrumb { margin: 0 .5em; padding: 6px 15px; font-size: 16px; @@ -619,9 +631,9 @@ html, body { background-color: transparent; } -#gogs-source .source-toolbar, -#gogs-source .info-box, -#gogs-source .file-content { +#source .source-toolbar, +#source .info-box, +#source .file-content { margin: 0 0 10px; } @@ -853,7 +865,7 @@ html, body { } .guide-box, .diff-head-box { - margin-top: 20px; + margin-top: 4px; } .diff-head-box h4 { @@ -941,7 +953,7 @@ html, body { color: #888; } -#gogs-source .file-content.diff-file-box { +#source .file-content.diff-file-box { margin-bottom: 20px; } @@ -987,6 +999,102 @@ html, body { color: #AAA; } +/* issue */ + +#issue-create-form .avatar { + width: 50px; + height: 50px; +} + +#issue-create-form .panel-body { + padding: 15px 0 0 0; +} + +#issue-create-form .panel-body.form-group, #issue-create-form .tab-pane .form-group { + margin-bottom: 0; +} + +#issue-create-form .nav-tabs { + margin-bottom: 10px; +} + +#issue-create-form .md-help { + margin-top: 6px; +} + +#issue .filter-list a { + padding: 6px 10px; + font-size: 14px; + display: block; + margin-bottom: 6px; + border-radius: 3px; + color: #444; +} + +#issue .filter-list a.sm { + font-size: 13px; +} + +#issue .filter-list hr { + border-color: #CCC; +} + +#issue .filter-list a:hover { + background-color: #DDD; + text-decoration: none; +} + +#issue .filter-list a.active { + background-color: #4183c4; + color: #FFF; +} + +#issue .filter-option { + margin-bottom: 12px; +} + +#issue .list-group .list-group-item { + background-color: #FFF; +} + +#issue .issue-item:hover { + background-color: rgba(19, 95, 215, 0.03); +} + +#issue .list-group .list-group-item.unread { + border-left: 2px solid #DD4B39; +} + +#issue .issue-item .title { + margin-bottom: 16px; + font-weight: bold; +} + +#issue .issue-item h5.title a { + color: #444; +} + +#issue .issue-item .info span { + margin-right: 12px; + color: #888; + line-height: 20px; +} + +#issue .issue-item .info a, #issue .issue-item .number { + color: #888; +} + +#issue .issue-item .number { + margin-top: 8px; +} + +#issue .issue-item .avatar { + margin-right: 8px; + width: 20px; + height: 20px; + vertical-align: top; +} + /* wrapper and footer */ #wrapper { diff --git a/public/js/app.js b/public/js/app.js index f98fd03f8..8b0e5cd62 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -111,6 +111,7 @@ var Gogits = { }; Gogits.initTabs = function () { var $tabs = $('[data-init=tabs]'); + $tabs.tab("show"); $tabs.find("li:eq(0) a").tab("show"); }; // fix dropdown inside click @@ -243,7 +244,7 @@ function initCore() { function initRegister() { $.getScript("/js/jquery.validate.min.js", function () { - Gogits.validateForm("#gogs-login-card", { + Gogits.validateForm("#login-card", { rules: { "username": { required: true, @@ -268,7 +269,7 @@ function initRegister() { } function initUserSetting() { - $('#gogs-ssh-keys .delete').confirmation({ + $('#ssh-keys .delete').confirmation({ singleton: true, onConfirm: function (e, $this) { Gogits.ajaxDelete("", {"id": $this.data("del")}, function (json) { @@ -303,7 +304,7 @@ function initRepository() { // watching script (function () { - var $watch = $('#gogs-repo-watching'), + var $watch = $('#repo-watching'), watchLink = $watch.data("watch"), unwatchLink = $watch.data("unwatch"); $watch.on('click', '.to-watch',function () { @@ -354,14 +355,14 @@ function initRepository() { (function ($) { $(function () { initCore(); - var body = $("#gogs-body"); + var body = $("#body"); if (body.data("page") == "user-signup") { initRegister(); } if (body.data("page") == "user") { initUserSetting(); } - if ($('.gogs-repo-nav').length) { + if ($('.repo-nav').length) { initRepository(); } }); diff --git a/routers/repo/branch.go b/routers/repo/branch.go index 8c953f2ed..aed77cfaa 100644 --- a/routers/repo/branch.go +++ b/routers/repo/branch.go @@ -26,11 +26,6 @@ func Branches(ctx *middleware.Context, params martini.Params) { ctx.Data["Username"] = params["username"] ctx.Data["Reponame"] = params["reponame"] - - if len(params["branchname"]) == 0 { - params["branchname"] = "master" - } - ctx.Data["Branchname"] = params["branchname"] ctx.Data["Branches"] = brs ctx.Data["IsRepoToolbarBranches"] = true diff --git a/routers/repo/commit.go b/routers/repo/commit.go index e038998f9..3d00f8d74 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -34,8 +34,24 @@ func Commits(ctx *middleware.Context, params martini.Params) { ctx.HTML(200, "repo/commits") } -func Diff(ctx *middleware.Context,params martini.Params){ - ctx.Data["Title"] = "commit-sha" +func Diff(ctx *middleware.Context, params martini.Params) { + commit, err := models.GetCommit(params["username"], params["reponame"], params["branchname"], params["commitid"]) + if err != nil { + ctx.Handle(404, "repo.Diff", err) + return + } + + diff, err := models.GetDiff(models.RepoPath(params["username"], params["reponame"]), params["commitid"]) + if err != nil { + ctx.Handle(404, "repo.Diff", err) + return + } + + shortSha := params["commitid"][:7] + ctx.Data["Title"] = commit.Message() + " · " + shortSha + ctx.Data["Commit"] = commit + ctx.Data["ShortSha"] = shortSha + ctx.Data["Diff"] = diff ctx.Data["IsRepoToolbarCommits"] = true - ctx.HTML(200,"repo/diff") + ctx.HTML(200, "repo/diff") } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index d54582a2a..242593ff2 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -13,6 +13,7 @@ import ( "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" + "github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/middleware" ) @@ -23,19 +24,34 @@ func Issues(ctx *middleware.Context, params martini.Params) { milestoneId, _ := base.StrTo(params["milestone"]).Int() page, _ := base.StrTo(params["page"]).Int() - var err error - ctx.Data["Issues"], err = models.GetIssues(0, ctx.Repo.Repository.Id, 0, + // Get issues. + issues, err := models.GetIssues(0, ctx.Repo.Repository.Id, 0, int64(milestoneId), page, params["state"] == "closed", false, params["labels"], params["sortType"]) if err != nil { ctx.Handle(200, "issue.Issues: %v", err) return } - if len(params["branchname"]) == 0 { - params["branchname"] = "master" + var closedCount int + // Get posters. + for i := range issues { + u, err := models.GetUserById(issues[i].PosterId) + if err != nil { + ctx.Handle(200, "issue.Issues(get poster): %v", err) + return + } + + if issues[i].IsClosed { + closedCount++ + } + issues[i].Poster = u } - ctx.Data["Branchname"] = params["branchname"] - ctx.HTML(200, "repo/issues") + + ctx.Data["Issues"] = issues + ctx.Data["IssueCount"] = len(issues) + ctx.Data["OpenCount"] = len(issues) - closedCount + ctx.Data["ClosedCount"] = closedCount + ctx.HTML(200, "issue/list") } func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { @@ -57,14 +73,30 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat return } - issue, err := models.CreateIssue(ctx.User.Id, form.RepoId, form.MilestoneId, form.AssigneeId, + issue, err := models.CreateIssue(ctx.User.Id, ctx.Repo.Repository.Id, form.MilestoneId, form.AssigneeId, form.IssueName, form.Labels, form.Content, false) - if err == nil { - log.Trace("%s Issue created: %d", form.RepoId, issue.Id) - ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", params["username"], params["reponame"], issue.Index)) + if err != nil { + ctx.Handle(200, "issue.CreateIssue", err) return } - ctx.Handle(200, "issue.CreateIssue", err) + + // Notify watchers. + if err = models.NotifyWatchers(ctx.User.Id, ctx.Repo.Repository.Id, models.OP_CREATE_ISSUE, + ctx.User.Name, ctx.Repo.Repository.Name, "", fmt.Sprintf("%d|%s", issue.Index, issue.Name)); err != nil { + ctx.Handle(200, "issue.CreateIssue", err) + return + } + + // Mail watchers. + if base.Service.NotifyMail { + if err = mailer.SendNotifyMail(ctx.User.Id, ctx.Repo.Repository.Id, ctx.User.Name, ctx.Repo.Repository.Name, issue.Name, issue.Content); err != nil { + ctx.Handle(200, "issue.CreateIssue", err) + return + } + } + + log.Trace("%d Issue created: %d", ctx.Repo.Repository.Id, issue.Id) + ctx.Redirect(fmt.Sprintf("/%s/%s/issues/%d", params["username"], params["reponame"], issue.Index)) } func ViewIssue(ctx *middleware.Context, params martini.Params) { diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 16c60389d..93b6a9f7c 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -12,10 +12,5 @@ import ( func Pulls(ctx *middleware.Context, params martini.Params) { ctx.Data["IsRepoToolbarPulls"] = true - if len(params["branchname"]) == 0 { - params["branchname"] = "master" - } - - ctx.Data["Branchname"] = params["branchname"] ctx.HTML(200, "repo/pulls") } diff --git a/routers/repo/repo.go b/routers/repo/repo.go index cd28d52ca..acf025a28 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -57,10 +57,6 @@ func Single(ctx *middleware.Context, params martini.Params) { return } - if len(params["branchname"]) == 0 { - params["branchname"] = "master" - } - // Get tree path treename := params["_1"] @@ -177,7 +173,6 @@ func Single(ctx *middleware.Context, params martini.Params) { ctx.Data["Username"] = params["username"] ctx.Data["Reponame"] = params["reponame"] - ctx.Data["Branchname"] = params["branchname"] var treenames []string Paths := make([]string, 0) @@ -216,10 +211,6 @@ func SingleDownload(ctx *middleware.Context, params martini.Params) { return } - if len(params["branchname"]) == 0 { - params["branchname"] = "master" - } - // Get tree path treename := params["_1"] @@ -290,11 +281,6 @@ func Setting(ctx *middleware.Context, params martini.Params) { title = t } - if len(params["branchname"]) == 0 { - params["branchname"] = "master" - } - - ctx.Data["Branchname"] = params["branchname"] ctx.Data["Title"] = title + " - settings" ctx.HTML(200, "repo/setting") } diff --git a/routers/user/user.go b/routers/user/user.go index a0321f187..d3ef96211 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -285,7 +285,8 @@ func Feeds(ctx *middleware.Context, form auth.FeedsForm) { } func Issues(ctx *middleware.Context) { - ctx.HTML(200, "user/issues") + ctx.Data["Title"] = "Your Issues" + ctx.HTML(200, "issue/user") } func Pulls(ctx *middleware.Context) { diff --git a/serve.go b/serve.go index 4af54acc0..96f03e724 100644 --- a/serve.go +++ b/serve.go @@ -9,6 +9,7 @@ import ( "fmt" "os" "os/exec" + "path" "strconv" "strings" @@ -42,11 +43,12 @@ gogs serv provide access auth for repositories`, Flags: []cli.Flag{}, } -func init() { +func newLogger(execDir string) { level := "0" - os.MkdirAll("log", os.ModePerm) - log.NewLogger(10000, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, "log/serv.log")) - log.Info("start logging...") + logPath := execDir + "/log/serv.log" + os.MkdirAll(path.Dir(logPath), os.ModePerm) + log.NewLogger(10000, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, logPath)) + log.Trace("start logging...") } func parseCmd(cmd string) (string, string) { @@ -70,6 +72,10 @@ func In(b string, sl map[string]int) bool { } func runServ(k *cli.Context) { + execDir, _ := base.ExecDir() + newLogger(execDir) + log.Trace("new serv request " + log.Mode + ":" + log.Config) + base.NewConfigContext() models.LoadModelsConfig() models.NewEngine() @@ -77,17 +83,20 @@ func runServ(k *cli.Context) { keys := strings.Split(os.Args[2], "-") if len(keys) != 2 { fmt.Println("auth file format error") + log.Error("auth file format error") return } keyId, err := strconv.ParseInt(keys[1], 10, 64) if err != nil { fmt.Println("auth file format error") + log.Error("auth file format error") return } user, err := models.GetUserByKeyId(keyId) if err != nil { fmt.Println("You have no right to access") + log.Error("You have no right to access") return } @@ -102,6 +111,7 @@ func runServ(k *cli.Context) { rr := strings.SplitN(rRepo, "/", 2) if len(rr) != 2 { println("Unavilable repository", args) + log.Error("Unavilable repository %v", args) return } repoName := rr[1] @@ -112,21 +122,22 @@ func runServ(k *cli.Context) { isWrite := In(verb, COMMANDS_WRITE) isRead := In(verb, COMMANDS_READONLY) - //repo, err := models.GetRepositoryByName(user.Id, repoName) + /*//repo, err := models.GetRepositoryByName(user.Id, repoName) //var isExist bool = true if err != nil { if err == models.ErrRepoNotExist { //isExist = false if isRead { println("Repository", user.Name+"/"+repoName, "is not exist") + log.Error("Repository " + user.Name + "/" + repoName + " is not exist") return } } else { println("Get repository error:", err) - log.Error(err.Error()) + log.Error("Get repository error: " + err.Error()) return } - } + }*/ // access check switch { @@ -139,6 +150,7 @@ func runServ(k *cli.Context) { } if !has { println("You have no right to write this repository") + log.Error("You have no right to access this repository") return } case isRead: @@ -158,10 +170,12 @@ func runServ(k *cli.Context) { } if !has { println("You have no right to access this repository") + log.Error("You have no right to access this repository") return } default: println("Unknown command") + log.Error("Unknown command") return } @@ -178,7 +192,7 @@ func runServ(k *cli.Context) { if err = gitcmd.Run(); err != nil { println("execute command error:", err.Error()) - log.Error(err.Error()) + log.Error("execute command error: " + err.Error()) return } } diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl index 1e2630460..39895aa31 100644 --- a/templates/admin/config.tmpl +++ b/templates/admin/config.tmpl @@ -1,8 +1,8 @@ {{template "base/head" .}} {{template "base/navbar" .}} -
+
{{template "admin/nav" .}} -
+
Server Configuration diff --git a/templates/admin/dashboard.tmpl b/templates/admin/dashboard.tmpl index 2a5a161e0..e0b31817a 100644 --- a/templates/admin/dashboard.tmpl +++ b/templates/admin/dashboard.tmpl @@ -1,8 +1,8 @@ {{template "base/head" .}} {{template "base/navbar" .}} -
+
{{template "admin/nav" .}} -
+
Statistic diff --git a/templates/admin/nav.tmpl b/templates/admin/nav.tmpl index 72f008acc..2ac646257 100644 --- a/templates/admin/nav.tmpl +++ b/templates/admin/nav.tmpl @@ -1,5 +1,5 @@ -
-
    +
    +
    • Dashboard
    • Users
    • Repositories
    • diff --git a/templates/admin/repos.tmpl b/templates/admin/repos.tmpl index 2c91ccc09..8cc424db6 100644 --- a/templates/admin/repos.tmpl +++ b/templates/admin/repos.tmpl @@ -1,8 +1,8 @@ {{template "base/head" .}} {{template "base/navbar" .}} -
      +
      {{template "admin/nav" .}} -
      +
      Repository Management diff --git a/templates/admin/users.tmpl b/templates/admin/users.tmpl index dec5c1895..63da45174 100644 --- a/templates/admin/users.tmpl +++ b/templates/admin/users.tmpl @@ -1,8 +1,8 @@ {{template "base/head" .}} {{template "base/navbar" .}} -
      +
      {{template "admin/nav" .}} -
      +
      User Management diff --git a/templates/admin/users/edit.tmpl b/templates/admin/users/edit.tmpl index 08f11fcb1..5db2c7a95 100644 --- a/templates/admin/users/edit.tmpl +++ b/templates/admin/users/edit.tmpl @@ -1,8 +1,8 @@ {{template "base/head" .}} {{template "base/navbar" .}} -
      +
      {{template "admin/nav" .}} -
      +
      Edit Account diff --git a/templates/admin/users/new.tmpl b/templates/admin/users/new.tmpl index 7b41ae43a..7f441f32b 100644 --- a/templates/admin/users/new.tmpl +++ b/templates/admin/users/new.tmpl @@ -1,8 +1,8 @@ {{template "base/head" .}} {{template "base/navbar" .}} -
      +
      {{template "admin/nav" .}} -
      +
      New Account diff --git a/templates/base/navbar.tmpl b/templates/base/navbar.tmpl index 90e90f296..829ecba62 100644 --- a/templates/base/navbar.tmpl +++ b/templates/base/navbar.tmpl @@ -1,25 +1,25 @@ - + +
      +
      +
      + +
      +
      +
      preview
      +
      +
      +
      +
      + + +
      +
      +
      +
      {{template "base/footer" .}} \ No newline at end of file diff --git a/templates/issue/list.tmpl b/templates/issue/list.tmpl new file mode 100644 index 000000000..0df688386 --- /dev/null +++ b/templates/issue/list.tmpl @@ -0,0 +1,39 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +{{template "repo/nav" .}} +{{template "repo/toolbar" .}} +
      +
      + +
      + +
      + {{range .Issues}} +
      + #{{.Index}} +
      {{.Name}}
      +

      + + {{.Poster.Name}} + {{TimeSince .Created}} + {{.NumComments}} +

      +
      + {{end}} +
      +
      +
      +
      +
      +{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/issue/user.tmpl b/templates/issue/user.tmpl new file mode 100644 index 000000000..2cf957130 --- /dev/null +++ b/templates/issue/user.tmpl @@ -0,0 +1,70 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +
      +
      + +

      Your Issues

      +
      +
      + +{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/repo/branches.tmpl b/templates/repo/branches.tmpl index 63e77ab92..8d2d59d7f 100644 --- a/templates/repo/branches.tmpl +++ b/templates/repo/branches.tmpl @@ -2,8 +2,8 @@ {{template "base/navbar" .}} {{template "repo/nav" .}} {{template "repo/toolbar" .}} -
      -
      +
      +

      Branches

      diff --git a/templates/repo/commits.tmpl b/templates/repo/commits.tmpl index 2e67a1200..2f308a108 100644 --- a/templates/repo/commits.tmpl +++ b/templates/repo/commits.tmpl @@ -2,8 +2,8 @@ {{template "base/navbar" .}} {{template "repo/nav" .}} {{template "repo/toolbar" .}} -
      -
      +
      +