Browse Source

Code fix for PR #3547

pull/3740/merge
Unknwon 8 years ago
parent
commit
d04b19545d
No known key found for this signature in database
GPG Key ID: FB9F411CDD69BEC1
  1. 2
      README.md
  2. 2
      gogs.go
  3. 74
      models/pull.go
  4. 10
      routers/repo/pull.go
  5. 2
      templates/.VERSION

2
README.md

@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
##### Current tip version: 0.9.105 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions ~~or submit a task on [alpha stage automated binary building system](https://build.gogs.io/)~~) ##### Current tip version: 0.9.106 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions ~~or submit a task on [alpha stage automated binary building system](https://build.gogs.io/)~~)
| Web | UI | Preview | | Web | UI | Preview |
|:-------------:|:-------:|:-------:| |:-------------:|:-------:|:-------:|

2
gogs.go

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.9.105.1221" const APP_VER = "0.9.106.1222"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

74
models/pull.go

@ -85,6 +85,20 @@ func (pr *PullRequest) AfterSet(colName string, _ xorm.Cell) {
// Note: don't try to get Issue because will end up recursive querying. // Note: don't try to get Issue because will end up recursive querying.
func (pr *PullRequest) loadAttributes(e Engine) (err error) { func (pr *PullRequest) loadAttributes(e Engine) (err error) {
if pr.HeadRepo == nil {
pr.HeadRepo, err = getRepositoryByID(e, pr.HeadRepoID)
if err != nil && !IsErrRepoNotExist(err) {
return fmt.Errorf("getRepositoryByID.(HeadRepo) [%d]: %v", pr.HeadRepoID, err)
}
}
if pr.BaseRepo == nil {
pr.BaseRepo, err = getRepositoryByID(e, pr.BaseRepoID)
if err != nil {
return fmt.Errorf("getRepositoryByID.(BaseRepo) [%d]: %v", pr.BaseRepoID, err)
}
}
if pr.HasMerged && pr.Merger == nil { if pr.HasMerged && pr.Merger == nil {
pr.Merger, err = getUserByID(e, pr.MergerID) pr.Merger, err = getUserByID(e, pr.MergerID)
if IsErrUserNotExist(err) { if IsErrUserNotExist(err) {
@ -112,11 +126,19 @@ func (pr *PullRequest) LoadIssue() (err error) {
} }
// This method assumes following fields have been assigned with valid values: // This method assumes following fields have been assigned with valid values:
// Required - Issue // Required - Issue, BaseRepo
// Required - HeadRepo // Optional - HeadRepo, Merger
// Required - BaseRepo
// Optional - Merger
func (pr *PullRequest) APIFormat() *api.PullRequest { func (pr *PullRequest) APIFormat() *api.PullRequest {
// In case of head repo has been deleted.
var apiHeadRepo *api.Repository
if pr.HeadRepo == nil {
apiHeadRepo = &api.Repository{
Name: "deleted",
}
} else {
apiHeadRepo = pr.HeadRepo.APIFormat(nil)
}
apiIssue := pr.Issue.APIFormat() apiIssue := pr.Issue.APIFormat()
apiPullRequest := &api.PullRequest{ apiPullRequest := &api.PullRequest{
ID: pr.ID, ID: pr.ID,
@ -130,7 +152,7 @@ func (pr *PullRequest) APIFormat() *api.PullRequest {
State: apiIssue.State, State: apiIssue.State,
Comments: apiIssue.Comments, Comments: apiIssue.Comments,
HeadBranch: pr.HeadBranch, HeadBranch: pr.HeadBranch,
HeadRepo: pr.HeadRepo.APIFormat(nil), HeadRepo: apiHeadRepo,
BaseBranch: pr.BaseBranch, BaseBranch: pr.BaseBranch,
BaseRepo: pr.BaseRepo.APIFormat(nil), BaseRepo: pr.BaseRepo.APIFormat(nil),
HTMLURL: pr.Issue.HTMLURL(), HTMLURL: pr.Issue.HTMLURL(),
@ -150,30 +172,6 @@ func (pr *PullRequest) APIFormat() *api.PullRequest {
return apiPullRequest return apiPullRequest
} }
func (pr *PullRequest) getHeadRepo(e Engine) (err error) {
pr.HeadRepo, err = getRepositoryByID(e, pr.HeadRepoID)
if err != nil && !IsErrRepoNotExist(err) {
return fmt.Errorf("getRepositoryByID(head): %v", err)
}
return nil
}
func (pr *PullRequest) GetHeadRepo() error {
return pr.getHeadRepo(x)
}
func (pr *PullRequest) GetBaseRepo() (err error) {
if pr.BaseRepo != nil {
return nil
}
pr.BaseRepo, err = GetRepositoryByID(pr.BaseRepoID)
if err != nil {
return fmt.Errorf("GetRepositoryByID(base): %v", err)
}
return nil
}
// IsChecking returns true if this pull request is still checking conflict. // IsChecking returns true if this pull request is still checking conflict.
func (pr *PullRequest) IsChecking() bool { func (pr *PullRequest) IsChecking() bool {
return pr.Status == PULL_REQUEST_STATUS_CHECKING return pr.Status == PULL_REQUEST_STATUS_CHECKING
@ -187,12 +185,6 @@ func (pr *PullRequest) CanAutoMerge() bool {
// Merge merges pull request to base repository. // Merge merges pull request to base repository.
// FIXME: add repoWorkingPull make sure two merges does not happen at same time. // FIXME: add repoWorkingPull make sure two merges does not happen at same time.
func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error) { func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error) {
if err = pr.GetHeadRepo(); err != nil {
return fmt.Errorf("GetHeadRepo: %v", err)
} else if err = pr.GetBaseRepo(); err != nil {
return fmt.Errorf("GetBaseRepo: %v", err)
}
defer func() { defer func() {
go HookQueue.Add(pr.BaseRepo.ID) go HookQueue.Add(pr.BaseRepo.ID)
go AddTestPullRequestTask(doer, pr.BaseRepo.ID, pr.BaseBranch, false) go AddTestPullRequestTask(doer, pr.BaseRepo.ID, pr.BaseBranch, false)
@ -548,17 +540,11 @@ func (pr *PullRequest) UpdateCols(cols ...string) error {
// UpdatePatch generates and saves a new patch. // UpdatePatch generates and saves a new patch.
func (pr *PullRequest) UpdatePatch() (err error) { func (pr *PullRequest) UpdatePatch() (err error) {
if err = pr.GetHeadRepo(); err != nil { if pr.HeadRepo == nil {
return fmt.Errorf("GetHeadRepo: %v", err)
} else if pr.HeadRepo == nil {
log.Trace("PullRequest[%d].UpdatePatch: ignored cruppted data", pr.ID) log.Trace("PullRequest[%d].UpdatePatch: ignored cruppted data", pr.ID)
return nil return nil
} }
if err = pr.GetBaseRepo(); err != nil {
return fmt.Errorf("GetBaseRepo: %v", err)
}
headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath()) headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath())
if err != nil { if err != nil {
return fmt.Errorf("OpenRepository: %v", err) return fmt.Errorf("OpenRepository: %v", err)
@ -763,8 +749,8 @@ func TestPullRequests() {
func(idx int, bean interface{}) error { func(idx int, bean interface{}) error {
pr := bean.(*PullRequest) pr := bean.(*PullRequest)
if err := pr.GetBaseRepo(); err != nil { if err := pr.LoadAttributes(); err != nil {
log.Error(3, "GetBaseRepo: %v", err) log.Error(3, "LoadAttributes: %v", err)
return nil return nil
} }

10
routers/repo/pull.go

@ -156,11 +156,6 @@ func checkPullInfo(ctx *context.Context) *models.Issue {
return nil return nil
} }
if err = issue.PullRequest.GetHeadRepo(); err != nil {
ctx.Handle(500, "GetHeadRepo", err)
return nil
}
if ctx.IsSigned { if ctx.IsSigned {
// Update issue-user. // Update issue-user.
if err = issue.ReadBy(ctx.User.ID); err != nil { if err = issue.ReadBy(ctx.User.ID); err != nil {
@ -203,11 +198,6 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.PullReq
err error err error
) )
if err = pull.GetHeadRepo(); err != nil {
ctx.Handle(500, "GetHeadRepo", err)
return nil
}
if pull.HeadRepo != nil { if pull.HeadRepo != nil {
headGitRepo, err = git.OpenRepository(pull.HeadRepo.RepoPath()) headGitRepo, err = git.OpenRepository(pull.HeadRepo.RepoPath())
if err != nil { if err != nil {

2
templates/.VERSION

@ -1 +1 @@
0.9.105.1221 0.9.106.1222
Loading…
Cancel
Save