summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-03-04 15:43:01 -0500
committerUnknwon <u@gogs.io>2016-03-04 15:43:01 -0500
commit2d2d85bba4dd5131e72db533c31aab423f86232e (patch)
treee53c3c263021efc846dee43249651142a49e76f3 /modules
parent9df6ce48c538e0458b6798f0819db8afce43e5c7 (diff)
downloadgitea-2d2d85bba4dd5131e72db533c31aab423f86232e.tar.gz
gitea-2d2d85bba4dd5131e72db533c31aab423f86232e.zip
#1597 support pull requests in same repository
Diffstat (limited to 'modules')
-rw-r--r--modules/log/database.go68
-rw-r--r--modules/middleware/repo.go51
2 files changed, 25 insertions, 94 deletions
diff --git a/modules/log/database.go b/modules/log/database.go
deleted file mode 100644
index 5857cb6d66..0000000000
--- a/modules/log/database.go
+++ /dev/null
@@ -1,68 +0,0 @@
-// 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 log
-
-import (
- "encoding/json"
-
- "github.com/go-xorm/xorm"
-)
-
-type Log struct {
- Id int64
- Level int
- Msg string `xorm:"TEXT"`
-}
-
-// DatabaseWriter implements LoggerInterface and is used to log into database.
-type DatabaseWriter struct {
- Driver string `json:"driver"`
- Conn string `json:"conn"`
- Level int `json:"level"`
- x *xorm.Engine
-}
-
-func NewDatabase() LoggerInterface {
- return &DatabaseWriter{Level: TRACE}
-}
-
-// init database writer with json config.
-// config like:
-// {
-// "driver": "mysql"
-// "conn":"root:root@tcp(127.0.0.1:3306)/gogs?charset=utf8",
-// "level": 0
-// }
-// connection string is based on xorm.
-func (d *DatabaseWriter) Init(jsonconfig string) (err error) {
- if err = json.Unmarshal([]byte(jsonconfig), d); err != nil {
- return err
- }
- d.x, err = xorm.NewEngine(d.Driver, d.Conn)
- if err != nil {
- return err
- }
- return d.x.Sync(new(Log))
-}
-
-// write message in database writer.
-func (d *DatabaseWriter) WriteMsg(msg string, skip, level int) error {
- if level < d.Level {
- return nil
- }
-
- _, err := d.x.Insert(&Log{Level: level, Msg: msg})
- return err
-}
-
-func (_ *DatabaseWriter) Flush() {
-}
-
-func (_ *DatabaseWriter) Destroy() {
-}
-
-func init() {
- Register("database", NewDatabase)
-}
diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go
index 002982656d..7c99d2d0c1 100644
--- a/modules/middleware/repo.go
+++ b/modules/middleware/repo.go
@@ -32,25 +32,6 @@ func RetrieveBaseRepo(ctx *Context, repo *models.Repository) {
ctx.Handle(500, "BaseRepo.GetOwner", err)
return
}
-
- bsaeRepo := repo.BaseRepo
- baseGitRepo, err := git.OpenRepository(models.RepoPath(bsaeRepo.Owner.Name, bsaeRepo.Name))
- if err != nil {
- ctx.Handle(500, "OpenRepository", err)
- return
- }
- if len(bsaeRepo.DefaultBranch) > 0 && baseGitRepo.IsBranchExist(bsaeRepo.DefaultBranch) {
- ctx.Data["BaseDefaultBranch"] = bsaeRepo.DefaultBranch
- } else {
- baseBranches, err := baseGitRepo.GetBranches()
- if err != nil {
- ctx.Handle(500, "GetBranches", err)
- return
- }
- if len(baseBranches) > 0 {
- ctx.Data["BaseDefaultBranch"] = baseBranches[0]
- }
- }
}
func RepoAssignment(args ...bool) macaron.Handler {
@@ -154,6 +135,13 @@ func RepoAssignment(args ...bool) macaron.Handler {
ctx.Data["Tags"] = tags
ctx.Repo.Repository.NumTags = len(tags)
+ ctx.Data["Title"] = owner.Name + "/" + repo.Name
+ ctx.Data["Repository"] = repo
+ ctx.Data["Owner"] = ctx.Repo.Repository.Owner
+ ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner()
+ ctx.Data["IsRepositoryAdmin"] = ctx.Repo.IsAdmin()
+ ctx.Data["IsRepositoryPusher"] = ctx.Repo.IsPusher()
+
if repo.IsFork {
RetrieveBaseRepo(ctx, repo)
if ctx.Written() {
@@ -161,13 +149,24 @@ func RepoAssignment(args ...bool) macaron.Handler {
}
}
- ctx.Data["Title"] = owner.Name + "/" + repo.Name
- ctx.Data["Repository"] = repo
- ctx.Data["Owner"] = ctx.Repo.Repository.Owner
- ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner()
- ctx.Data["IsRepositoryAdmin"] = ctx.Repo.IsAdmin()
- ctx.Data["IsRepositoryPusher"] = ctx.Repo.IsPusher()
- ctx.Data["CanPullRequest"] = ctx.Repo.IsAdmin() && repo.BaseRepo != nil && repo.BaseRepo.AllowsPulls()
+ // People who have push access and propose a new pull request.
+ if ctx.Repo.IsPusher() {
+ // Pull request is allowed if this is a fork repository
+ // and base repository accepts pull requests.
+ if repo.BaseRepo != nil {
+ if repo.BaseRepo.AllowsPulls() {
+ ctx.Data["CanPullRequest"] = true
+ ctx.Data["BaseRepo"] = repo.BaseRepo
+ }
+ } else {
+ // Or, this is repository accepts pull requests between branches.
+ if repo.AllowsPulls() {
+ ctx.Data["CanPullRequest"] = true
+ ctx.Data["BaseRepo"] = repo
+ ctx.Data["IsBetweenBranches"] = true
+ }
+ }
+ }
ctx.Data["DisableSSH"] = setting.SSH.Disabled
ctx.Data["CloneLink"] = repo.CloneLink()