Browse Source

IP: RC Code Review

pull/40/head
Unknown 11 years ago
parent
commit
f470c241d6
  1. 2
      README.md
  2. 2
      README_ZH.md
  3. 2
      gogs.go
  4. 4
      models/access.go
  5. 10
      models/action.go
  6. 21
      models/repo.go
  7. 7
      routers/repo/issue.go
  8. 4
      templates/issue/view.tmpl
  9. 8
      web.go

2
README.md

@ -27,7 +27,7 @@ More importantly, Gogs only needs one binary to setup your own project hosting o
## Features ## Features
- Activity timeline - Activity timeline
- SSH/HTTPS protocol support. - SSH/HTTPS(Clone only) protocol support.
- Register/delete account. - Register/delete account.
- Create/delete/watch public repository. - Create/delete/watch public repository.
- User profile page. - User profile page.

2
README_ZH.md

@ -23,7 +23,7 @@ Gogs 完全使用 Go 语言来实现对 Git 数据的操作,实现 **零** 依
## 功能特性 ## 功能特性
- 活动时间线 - 活动时间线
- SSH/HTTPS 协议支持 - SSH/HTTPS(仅限 Clone) 协议支持
- 注册/删除用户 - 注册/删除用户
- 创建/删除/关注公开仓库 - 创建/删除/关注公开仓库
- 用户个人信息页面 - 用户个人信息页面

2
gogs.go

@ -19,7 +19,7 @@ import (
// Test that go1.2 tag above is included in builds. main.go refers to this definition. // Test that go1.2 tag above is included in builds. main.go refers to this definition.
const go12tag = true const go12tag = true
const APP_VER = "0.1.8.0326 Alpha" const APP_VER = "0.1.8.0327 Alpha"
func init() { func init() {
base.AppVer = APP_VER base.AppVer = APP_VER

4
models/access.go

@ -15,7 +15,7 @@ const (
AU_WRITABLE AU_WRITABLE
) )
// Access represents the accessibility of user and repository. // Access represents the accessibility of user to repository.
type Access struct { type Access struct {
Id int64 Id int64
UserName string `xorm:"unique(s)"` UserName string `xorm:"unique(s)"`
@ -30,7 +30,7 @@ func AddAccess(access *Access) error {
return err return err
} }
// HasAccess returns true if someone can read or write given repository. // HasAccess returns true if someone can read or write to given repository.
func HasAccess(userName, repoName string, mode int) (bool, error) { func HasAccess(userName, repoName string, mode int) (bool, error) {
return orm.Get(&Access{ return orm.Get(&Access{
Id: 0, Id: 0,

10
models/action.go

@ -23,7 +23,8 @@ const (
OP_PULL_REQUEST OP_PULL_REQUEST
) )
// Action represents user operation type and information to the repository. // Action represents user operation type and other information to repository.,
// it implemented interface base.Actioner so that can be used in template render.
type Action struct { type Action struct {
Id int64 Id int64
UserId int64 // Receiver user id. UserId int64 // Receiver user id.
@ -57,7 +58,7 @@ func (a Action) GetContent() string {
return a.Content return a.Content
} }
// CommitRepoAction records action for commit repository. // CommitRepoAction adds new action for committing repository.
func CommitRepoAction(userId int64, userName string, func CommitRepoAction(userId int64, userName string,
repoId int64, repoName string, refName string, commits *base.PushCommits) error { repoId int64, repoName string, refName string, commits *base.PushCommits) error {
log.Trace("action.CommitRepoAction(start): %d/%s", userId, repoName) log.Trace("action.CommitRepoAction(start): %d/%s", userId, repoName)
@ -68,12 +69,13 @@ func CommitRepoAction(userId int64, userName string,
return err return err
} }
if err = NotifyWatchers(userId, repoId, OP_COMMIT_REPO, userName, repoName, refName, string(bs)); err != nil { if err = NotifyWatchers(&Action{ActUserId: userId, ActUserName: userName, OpType: OP_COMMIT_REPO,
Content: string(bs), RepoId: repoId, RepoName: repoName, RefName: refName}); err != nil {
log.Error("action.CommitRepoAction(notify watchers): %d/%s", userId, repoName) log.Error("action.CommitRepoAction(notify watchers): %d/%s", userId, repoName)
return err return err
} }
// Update repository last update time. // Change repository bare status and update last updated time.
repo, err := GetRepositoryByName(userId, repoName) repo, err := GetRepositoryByName(userId, repoName)
if err != nil { if err != nil {
log.Error("action.CommitRepoAction(GetRepositoryByName): %d/%s", userId, repoName) log.Error("action.CommitRepoAction(GetRepositoryByName): %d/%s", userId, repoName)

21
models/repo.go

@ -485,30 +485,21 @@ func GetWatches(repoId int64) ([]Watch, error) {
} }
// NotifyWatchers creates batch of actions for every watcher. // NotifyWatchers creates batch of actions for every watcher.
func NotifyWatchers(userId, repoId int64, opType int, userName, repoName, refName, content string) error { func NotifyWatchers(act *Action) error {
// Add feeds for user self and all watchers. // Add feeds for user self and all watchers.
watches, err := GetWatches(repoId) watches, err := GetWatches(act.RepoId)
if err != nil { if err != nil {
return errors.New("repo.NotifyWatchers(get watches): " + err.Error()) return errors.New("repo.NotifyWatchers(get watches): " + err.Error())
} }
watches = append(watches, Watch{UserId: userId}) watches = append(watches, Watch{UserId: act.ActUserId})
for i := range watches { for i := range watches {
if userId == watches[i].UserId && i > 0 { if act.ActUserId == watches[i].UserId && i > 0 {
continue // Do not add twice in case author watches his/her repository. continue // Do not add twice in case author watches his/her repository.
} }
_, err = orm.InsertOne(&Action{ act.UserId = watches[i].UserId
UserId: watches[i].UserId, if _, err = orm.InsertOne(act); err != nil {
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 errors.New("repo.NotifyWatchers(create action): " + err.Error())
} }
} }

7
routers/repo/issue.go

@ -78,8 +78,9 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat
} }
// Notify watchers. // Notify watchers.
if err = models.NotifyWatchers(ctx.User.Id, ctx.Repo.Repository.Id, models.OP_CREATE_ISSUE, if err = models.NotifyWatchers(&models.Action{ActUserId: ctx.User.Id, ActUserName: ctx.User.Name,
ctx.User.Name, ctx.Repo.Repository.Name, "", fmt.Sprintf("%d|%s", issue.Index, issue.Name)); err != nil { OpType: models.OP_CREATE_ISSUE, Content: fmt.Sprintf("%d|%s", issue.Index, issue.Name),
RepoId: ctx.Repo.Repository.Id, RepoName: ctx.Repo.Repository.Name, RefName: ""}); err != nil {
ctx.Handle(200, "issue.CreateIssue", err) ctx.Handle(200, "issue.CreateIssue", err)
return return
} }
@ -120,6 +121,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) {
return return
} }
issue.Poster = u issue.Poster = u
issue.Content = string(base.RenderMarkdown([]byte(issue.Content), ""))
// Get comments. // Get comments.
comments, err := models.GetIssueComments(issue.Id) comments, err := models.GetIssueComments(issue.Id)
@ -136,6 +138,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) {
return return
} }
comments[i].Poster = u comments[i].Poster = u
comments[i].Content = string(base.RenderMarkdown([]byte(comments[i].Content), ""))
} }
ctx.Data["Title"] = issue.Name ctx.Data["Title"] = issue.Name

4
templates/issue/view.tmpl

@ -18,7 +18,7 @@
<div class="issue-main"> <div class="issue-main">
<div class="panel panel-default issue-content"> <div class="panel panel-default issue-content">
<div class="panel-body markdown"> <div class="panel-body markdown">
<p>{{.Issue.Content}}</p> {{str2html .Issue.Content}}
</div> </div>
</div> </div>
{{range .Comments}} {{range .Comments}}
@ -29,7 +29,7 @@
<a href="/user/{{.Poster.Name}}" class="user">{{.Poster.Name}}</a> commented <span class="time">{{TimeSince .Created}}</span> <a href="/user/{{.Poster.Name}}" class="user">{{.Poster.Name}}</a> commented <span class="time">{{TimeSince .Created}}</span>
</div> </div>
<div class="panel-body markdown"> <div class="panel-body markdown">
<p>{{.Content}}</p> {{str2html .Content}}
</div> </div>
</div> </div>
</div> </div>

8
web.go

@ -138,6 +138,10 @@ func runWeb(*cli.Context) {
r.Any("/:userid/delete", admin.DeleteUser) r.Any("/:userid/delete", admin.DeleteUser)
}, adminReq) }, adminReq)
if martini.Env == martini.Dev {
m.Get("/template/**", dev.TemplatePreview)
}
m.Group("/:username/:reponame", func(r martini.Router) { m.Group("/:username/:reponame", func(r martini.Router) {
r.Post("/settings", repo.SettingPost) r.Post("/settings", repo.SettingPost)
r.Get("/settings", repo.Setting) r.Get("/settings", repo.Setting)
@ -168,10 +172,6 @@ func runWeb(*cli.Context) {
r.Any("/:reponame/**", repo.Http) r.Any("/:reponame/**", repo.Http)
}, ignSignIn) }, ignSignIn)
if martini.Env == martini.Dev {
m.Get("/template/**", dev.TemplatePreview)
}
// Not found handler. // Not found handler.
m.NotFound(routers.NotFound) m.NotFound(routers.NotFound)

Loading…
Cancel
Save