aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/issue.go')
-rw-r--r--models/issue.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/models/issue.go b/models/issue.go
index d97266b4ed..c89ffa7d0f 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -649,6 +649,20 @@ func (issue *Issue) changeStatus(e *xorm.Session, doer *User, repo *Repository,
if issue.IsClosed == isClosed {
return nil
}
+
+ // Check for open dependencies
+ if isClosed && issue.Repo.IsDependenciesEnabled() {
+ // only check if dependencies are enabled and we're about to close an issue, otherwise reopening an issue would fail when there are unsatisfied dependencies
+ noDeps, err := IssueNoDependenciesLeft(issue)
+ if err != nil {
+ return err
+ }
+
+ if !noDeps {
+ return ErrDependenciesLeft{issue.ID}
+ }
+ }
+
issue.IsClosed = isClosed
if isClosed {
issue.ClosedUnix = util.TimeStampNow()
@@ -1598,3 +1612,33 @@ func UpdateIssueDeadline(issue *Issue, deadlineUnix util.TimeStamp, doer *User)
return sess.Commit()
}
+
+// Get Blocked By Dependencies, aka all issues this issue is blocked by.
+func (issue *Issue) getBlockedByDependencies(e Engine) (issueDeps []*Issue, err error) {
+ return issueDeps, e.
+ Table("issue_dependency").
+ Select("issue.*").
+ Join("INNER", "issue", "issue.id = issue_dependency.dependency_id").
+ Where("issue_id = ?", issue.ID).
+ Find(&issueDeps)
+}
+
+// Get Blocking Dependencies, aka all issues this issue blocks.
+func (issue *Issue) getBlockingDependencies(e Engine) (issueDeps []*Issue, err error) {
+ return issueDeps, e.
+ Table("issue_dependency").
+ Select("issue.*").
+ Join("INNER", "issue", "issue.id = issue_dependency.issue_id").
+ Where("dependency_id = ?", issue.ID).
+ Find(&issueDeps)
+}
+
+// BlockedByDependencies finds all Dependencies an issue is blocked by
+func (issue *Issue) BlockedByDependencies() ([]*Issue, error) {
+ return issue.getBlockedByDependencies(x)
+}
+
+// BlockingDependencies returns all blocking dependencies, aka all other issues a given issue blocks
+func (issue *Issue) BlockingDependencies() ([]*Issue, error) {
+ return issue.getBlockingDependencies(x)
+}