Beautify @JonasFranzDEV
Signed-off-by: Konrad <konrad@kola-entertainments.de>
This commit is contained in:
parent
d9c67292b8
commit
ad0fcd4dc5
|
|
@ -88,7 +88,8 @@ type Comment struct {
|
||||||
OldAssignee *User `xorm:"-"`
|
OldAssignee *User `xorm:"-"`
|
||||||
OldTitle string
|
OldTitle string
|
||||||
NewTitle string
|
NewTitle string
|
||||||
DependentIssue int64
|
DependentIssueID int64
|
||||||
|
DependentIssue *Issue `xorm:"-"`
|
||||||
|
|
||||||
CommitID int64
|
CommitID int64
|
||||||
Line int64
|
Line int64
|
||||||
|
|
@ -323,6 +324,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
|
||||||
OldTitle: opts.OldTitle,
|
OldTitle: opts.OldTitle,
|
||||||
NewTitle: opts.NewTitle,
|
NewTitle: opts.NewTitle,
|
||||||
DependentIssue: opts.DependentIssue,
|
DependentIssue: opts.DependentIssue,
|
||||||
|
DependentIssueID: opts.DependentIssue.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
//fmt.Println(comment)
|
//fmt.Println(comment)
|
||||||
|
|
@ -506,7 +508,7 @@ func createDeleteBranchComment(e *xorm.Session, doer *User, repo *Repository, is
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates issue dependency comment
|
// Creates issue dependency comment
|
||||||
func createIssueDependencyComment(e *xorm.Session, doer *User, repo *Repository, issue *Issue, dependantIssue int64, added bool) (*Comment, error) {
|
func createIssueDependencyComment(e *xorm.Session, doer *User, issue *Issue, dependantIssue *Issue, added bool) (*Comment, error) {
|
||||||
cType := CommentTypeAddedDependency
|
cType := CommentTypeAddedDependency
|
||||||
if !added {
|
if !added {
|
||||||
cType = CommentTypeRemovedDependency
|
cType = CommentTypeRemovedDependency
|
||||||
|
|
@ -515,7 +517,7 @@ func createIssueDependencyComment(e *xorm.Session, doer *User, repo *Repository,
|
||||||
return createComment(e, &CreateCommentOptions{
|
return createComment(e, &CreateCommentOptions{
|
||||||
Type: cType,
|
Type: cType,
|
||||||
Doer: doer,
|
Doer: doer,
|
||||||
Repo: repo,
|
Repo: issue.Repo,
|
||||||
Issue: issue,
|
Issue: issue,
|
||||||
DependentIssue: dependantIssue,
|
DependentIssue: dependantIssue,
|
||||||
Content: issue.Title,
|
Content: issue.Title,
|
||||||
|
|
@ -529,6 +531,7 @@ type CreateCommentOptions struct {
|
||||||
Repo *Repository
|
Repo *Repository
|
||||||
Issue *Issue
|
Issue *Issue
|
||||||
Label *Label
|
Label *Label
|
||||||
|
DependentIssue *Issue
|
||||||
|
|
||||||
OldMilestoneID int64
|
OldMilestoneID int64
|
||||||
MilestoneID int64
|
MilestoneID int64
|
||||||
|
|
@ -541,7 +544,6 @@ type CreateCommentOptions struct {
|
||||||
LineNum int64
|
LineNum int64
|
||||||
Content string
|
Content string
|
||||||
Attachments []string // UUIDs of attachments
|
Attachments []string // UUIDs of attachments
|
||||||
DependentIssue int64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateComment creates comment of issue or commit.
|
// CreateComment creates comment of issue or commit.
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,14 @@ import (
|
||||||
|
|
||||||
// IssueDependency is connection request for receiving issue notification.
|
// IssueDependency is connection request for receiving issue notification.
|
||||||
type IssueDependency struct {
|
type IssueDependency struct {
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
UserID int64 `xorm:"UNIQUE(watch) NOT NULL"`
|
UserID int64 `xorm:"UNIQUE(watch) NOT NULL"`
|
||||||
IssueID int64 `xorm:"UNIQUE(watch) NOT NULL"`
|
IssueID int64 `xorm:"UNIQUE(watch) NOT NULL"`
|
||||||
DependencyID int64 `xorm:"UNIQUE(watch) NOT NULL"`
|
DependencyID int64 `xorm:"UNIQUE(watch) NOT NULL"`
|
||||||
Created time.Time `xorm:"-"`
|
Created time.Time `xorm:"-"`
|
||||||
CreatedUnix int64 `xorm:"NOT NULL"`
|
CreatedUnix int64 `xorm:"NOT NULL"`
|
||||||
Updated time.Time `xorm:"-"`
|
Updated time.Time `xorm:"-"`
|
||||||
UpdatedUnix int64 `xorm:"NOT NULL"`
|
UpdatedUnix int64 `xorm:"NOT NULL"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// BeforeInsert is invoked from XORM before inserting an object of this type.
|
// BeforeInsert is invoked from XORM before inserting an object of this type.
|
||||||
|
|
@ -43,7 +43,7 @@ func (iw *IssueDependency) BeforeUpdate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateIssueDependency creates a new dependency for an issue
|
// CreateIssueDependency creates a new dependency for an issue
|
||||||
func CreateIssueDependency(userID, issueID int64, depID int64) (err error, exists bool, depExists bool) {
|
func CreateIssueDependency(user *User, issue, dep *Issue) (err error, exists bool, depExists bool) {
|
||||||
sess := x.NewSession()
|
sess := x.NewSession()
|
||||||
|
|
||||||
// TODO: Move this to the appropriate place
|
// TODO: Move this to the appropriate place
|
||||||
|
|
@ -53,71 +53,41 @@ func CreateIssueDependency(userID, issueID int64, depID int64) (err error, exist
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if it aleready exists
|
// Check if it aleready exists
|
||||||
exists, err = issueDepExists(x, issueID, depID)
|
exists, err = issueDepExists(x, issue.ID, dep.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, exists, false
|
return err, exists, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it not exists, create it, otherwise show an error message
|
// If it not exists, create it, otherwise show an error message
|
||||||
if !exists {
|
if !exists {
|
||||||
// Check if the other issue exists
|
newId := new(IssueDependency)
|
||||||
var issue = Issue{}
|
newId.UserID = user.ID
|
||||||
issueExists, err := x.Id(depID).Get(&issue)
|
newId.IssueID = issue.ID
|
||||||
|
newId.DependencyID = dep.ID
|
||||||
|
|
||||||
if issueExists {
|
if _, err := x.Insert(newId); err != nil {
|
||||||
newId := new(IssueDependency)
|
return err, exists, false
|
||||||
newId.UserID = userID
|
}
|
||||||
newId.IssueID = issueID
|
|
||||||
newId.DependencyID = depID
|
// Add comment referencing the new dependency
|
||||||
|
_, err = createIssueDependencyComment(sess, user, issue, dep, true)
|
||||||
if _, err := x.Insert(newId); err != nil {
|
|
||||||
return err, exists, false
|
if err != nil {
|
||||||
}
|
return err, exists, false
|
||||||
|
}
|
||||||
user, err := getUserByID(x, userID)
|
|
||||||
if err != nil {
|
// Create a new comment for the dependent issue
|
||||||
return err, exists, false
|
_, err = createIssueDependencyComment(sess, user, dep, issue, true)
|
||||||
}
|
|
||||||
|
if err != nil {
|
||||||
// Add comment referencing the new dependency
|
return err, exists, false
|
||||||
|
|
||||||
repo, err := getRepositoryByID(x, issue.RepoID)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err, exists, false
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
_, err = createIssueDependencyComment(sess, user, repo, &issue, depID, true)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err, exists, false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a new comment for the dependent issue
|
|
||||||
depIssue, err := getIssueByID(x, issueID)
|
|
||||||
if err != nil {
|
|
||||||
return err, exists, false
|
|
||||||
}
|
|
||||||
|
|
||||||
repo, err = getRepositoryByID(x, depIssue.RepoID)
|
|
||||||
if err != nil {
|
|
||||||
return err, exists, false
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = createIssueDependencyComment(sess, user, repo, depIssue, issueID, true)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err, exists, false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return err, exists, true
|
|
||||||
}
|
}
|
||||||
return nil, exists, false
|
return nil, exists, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removes a dependency from an issue
|
// Removes a dependency from an issue
|
||||||
func RemoveIssueDependency(userID, issueID int64, depID int64, depType int64) (err error) {
|
func RemoveIssueDependency(user *User, issue *Issue, dep *Issue, depType int64) (err error) {
|
||||||
sess := x.NewSession()
|
sess := x.NewSession()
|
||||||
|
|
||||||
// TODO: Same as above
|
// TODO: Same as above
|
||||||
|
|
@ -127,7 +97,7 @@ func RemoveIssueDependency(userID, issueID int64, depID int64, depType int64) (e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if it exists
|
// Check if it exists
|
||||||
exists, err := issueDepExists(x, issueID, depID)
|
exists, err := issueDepExists(x, issue.ID, dep.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -135,47 +105,29 @@ func RemoveIssueDependency(userID, issueID int64, depID int64, depType int64) (e
|
||||||
// If it exists, remove it, otherwise show an error message
|
// If it exists, remove it, otherwise show an error message
|
||||||
if exists {
|
if exists {
|
||||||
|
|
||||||
if depType == 1{
|
if depType == 1 {
|
||||||
_, err := x.Delete(&IssueDependency{IssueID: issueID, DependencyID: depID})
|
_, err := x.Delete(&IssueDependency{IssueID: issue.ID, DependencyID: dep.ID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if depType == 2{
|
if depType == 2 {
|
||||||
_, err := x.Delete(&IssueDependency{IssueID: depID, DependencyID: issueID})
|
_, err := x.Delete(&IssueDependency{IssueID: dep.ID, DependencyID: issue.ID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add comment referencing the removed dependency
|
// Add comment referencing the removed dependency
|
||||||
issue, err := getIssueByID(x, depID)
|
_, err = createIssueDependencyComment(sess, user, issue, dep, false)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
user, _ := getUserByID(x, userID)
|
|
||||||
|
|
||||||
repo, _ := getRepositoryByID(x, issue.RepoID)
|
|
||||||
|
|
||||||
_, err = createIssueDependencyComment(sess, user, repo, issue, depID, false)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new comment for the dependent issue
|
// Create a new comment for the dependent issue
|
||||||
depIssue, err := getIssueByID(x, issueID)
|
_, err = createIssueDependencyComment(sess, user, dep, issue, false)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
repo, _ = getRepositoryByID(x, depIssue.RepoID)
|
|
||||||
|
|
||||||
_, err = createIssueDependencyComment(sess, user, repo, depIssue, issueID, false)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -202,12 +154,12 @@ func issueDepExists(e Engine, issueID int64, depID int64) (exists bool, err erro
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if issue can be closed
|
// check if issue can be closed
|
||||||
func IssueNoDependenciesLeft(issueID int64) bool{
|
func IssueNoDependenciesLeft(issueID int64) bool {
|
||||||
|
|
||||||
var issueDeps []IssueDependency
|
var issueDeps []IssueDependency
|
||||||
err := x.Where("issue_id = ?", issueID).Find(&issueDeps)
|
err := x.Where("issue_id = ?", issueID).Find(&issueDeps)
|
||||||
|
|
||||||
for _, issueDep := range issueDeps{
|
for _, issueDep := range issueDeps {
|
||||||
issueDetails, _ := getIssueByID(x, issueDep.DependencyID)
|
issueDetails, _ := getIssueByID(x, issueDep.DependencyID)
|
||||||
if !issueDetails.IsClosed {
|
if !issueDetails.IsClosed {
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
|
|
||||||
// Adds new dependencies
|
// Adds new dependencies
|
||||||
func AddDependency(c *context.Context) {
|
func AddDependency(c *context.Context) {
|
||||||
dep, err := strconv.ParseInt(c.Req.PostForm.Get("newDependency"), 10, 64)
|
depID, err := strconv.ParseInt(c.Req.PostForm.Get("newDependency"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Handle(http.StatusBadRequest, "issue ID is not int", err)
|
c.Handle(http.StatusBadRequest, "issue ID is not int", err)
|
||||||
return
|
return
|
||||||
|
|
@ -28,12 +28,19 @@ func AddDependency(c *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dependency
|
||||||
|
dep, err := models.GetIssueByID(depID)
|
||||||
|
if err != nil {
|
||||||
|
c.Handle(http.StatusInternalServerError, "GetIssueByID", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Check if issue and dependency is the same
|
// Check if issue and dependency is the same
|
||||||
if dep == issueIndex{
|
if dep.Index == issueIndex{
|
||||||
c.Flash.Error("You cannot make an issue depend on itself!")
|
c.Flash.Error("You cannot make an issue depend on itself!")
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
err, exists, depExists := models.CreateIssueDependency(c.User.ID, issue.ID, dep)
|
err, exists, depExists := models.CreateIssueDependency(c.User, issue, dep)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueDependency", err)
|
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueDependency", err)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
|
|
||||||
// IssueWatch sets issue watching
|
// IssueWatch sets issue watching
|
||||||
func RemoveDependency(c *context.Context) {
|
func RemoveDependency(c *context.Context) {
|
||||||
dep, err := strconv.ParseInt(c.Req.PostForm.Get("removeDependencyID"), 10, 64)
|
depID, err := strconv.ParseInt(c.Req.PostForm.Get("removeDependencyID"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Handle(http.StatusBadRequest, "issue ID is not int", err)
|
c.Handle(http.StatusBadRequest, "issue ID is not int", err)
|
||||||
return
|
return
|
||||||
|
|
@ -41,9 +41,15 @@ func RemoveDependency(c *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = models.RemoveIssueDependency(c.User.ID, issue.ID, dep, depType)
|
// Dependency
|
||||||
|
dep, err := models.GetIssueByID(depID)
|
||||||
|
if err != nil {
|
||||||
|
c.Handle(http.StatusInternalServerError, "GetIssueByID", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = models.RemoveIssueDependency(c.User, issue, dep, depType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
|
||||||
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueDependency", err)
|
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueDependency", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,10 @@
|
||||||
<div class="detail">
|
<div class="detail">
|
||||||
<span class="text grey">
|
<span class="text grey">
|
||||||
<i class="octicon octicon-plus"></i>
|
<i class="octicon octicon-plus"></i>
|
||||||
<a href="{{$.RepoLink}}/issues/{{.DependentIssue}}">#{{.DependentIssue}} {{.Content}}</a>
|
|
||||||
|
<!-- TODO: Use issue index instead of id -->
|
||||||
|
|
||||||
|
<a href="{{$.RepoLink}}/issues/{{.DependentIssueID}}">#{{.DependentIssueID}} {{.Content}}</a>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -168,7 +171,7 @@
|
||||||
<div class="detail">
|
<div class="detail">
|
||||||
<span class="text grey">
|
<span class="text grey">
|
||||||
<i class="octicon octicon-trashcan"></i>
|
<i class="octicon octicon-trashcan"></i>
|
||||||
<a href="{{$.RepoLink}}/issues/{{.DependentIssue}}">#{{.DependentIssue}} {{.Content}}</a>
|
<a href="{{$.RepoLink}}/issues/{{.DependentIssueID}}">#{{.DependentIssueID}} {{.Content}}</a>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user