Implemented repo settings check on autoclose

Signed-off-by: Konrad <konrad@kola-entertainments.de>
This commit is contained in:
Konrad Langenberg 2017-09-09 14:09:44 +02:00 committed by Jonas Franz
parent 2dbeb63a75
commit 14b5d369c9
5 changed files with 23 additions and 13 deletions

View File

@ -473,7 +473,7 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit) err
}
// Check for dependencies, if there aren't any, close it
canbeClosed := IssueNoDependenciesLeft(issue.ID)
canbeClosed := IssueNoDependenciesLeft(issue)
if canbeClosed {
if err = issue.ChangeStatus(doer, repo, true); err != nil {

View File

@ -315,6 +315,12 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
if opts.Label != nil {
LabelID = opts.Label.ID
}
var depId int64 = 0
if opts.DependentIssue != nil {
depId = opts.DependentIssue.ID
}
comment := &Comment{
Type: opts.Type,
PosterID: opts.Doer.ID,
@ -332,16 +338,9 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
OldTitle: opts.OldTitle,
NewTitle: opts.NewTitle,
DependentIssue: opts.DependentIssue,
DependentIssueID: opts.DependentIssue.ID,
DependentIssueID: depId,
}
//fmt.Println(comment)
// TODO: WHY ISNT THIS INSERTED??????
// It seems to be inserted, but isnt. (Doesn't return an error, raw pasting
// the sql query in a database console does work). But after the function
// is called, there is no entry in the database. At least for type 12 and 13.
_, err = e.Insert(comment)
if err != nil {
return nil, err

View File

@ -154,10 +154,21 @@ func issueDepExists(e Engine, issueID int64, depID int64) (exists bool, err erro
}
// check if issue can be closed
func IssueNoDependenciesLeft(issueID int64) bool {
func IssueNoDependenciesLeft(issue *Issue) bool {
// Check if the Repo is allowed to have dependencies, if not return true (= issue can be closed)
// Otherwise check for all open dependencies
r, err := getRepositoryByID(x, issue.RepoID)
if err != nil {
return false
}
if !r.UnitEnabled(UnitTypeIssueDependencies) {
return true
}
var issueDeps []IssueDependency
err := x.Where("issue_id = ?", issueID).Find(&issueDeps)
err = x.Where("issue_id = ?", issue.ID).Find(&issueDeps)
for _, issueDep := range issueDeps {
issueDetails, _ := getIssueByID(x, issueDep.DependencyID)

View File

@ -922,7 +922,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
// Check for open dependencies
if form.Status == "close"{
canbeClosed := models.IssueNoDependenciesLeft(issue.ID)
canbeClosed := models.IssueNoDependenciesLeft(issue)
if !canbeClosed {
if issue.IsPull{

View File

@ -428,7 +428,7 @@ func MergePullRequest(ctx *context.Context) {
pr.Issue = issue
pr.Issue.Repo = ctx.Repo.Repository
canbeClosed := models.IssueNoDependenciesLeft(issue.ID)
canbeClosed := models.IssueNoDependenciesLeft(issue)
if !canbeClosed {
ctx.Flash.Error("You need to close all issues blocking this pull request before you can merge it!")