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:"-"`
|
||||
OldTitle string
|
||||
NewTitle string
|
||||
DependentIssue int64
|
||||
DependentIssueID int64
|
||||
DependentIssue *Issue `xorm:"-"`
|
||||
|
||||
CommitID int64
|
||||
Line int64
|
||||
|
|
@ -323,6 +324,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
|
|||
OldTitle: opts.OldTitle,
|
||||
NewTitle: opts.NewTitle,
|
||||
DependentIssue: opts.DependentIssue,
|
||||
DependentIssueID: opts.DependentIssue.ID,
|
||||
}
|
||||
|
||||
//fmt.Println(comment)
|
||||
|
|
@ -506,7 +508,7 @@ func createDeleteBranchComment(e *xorm.Session, doer *User, repo *Repository, is
|
|||
}
|
||||
|
||||
// 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
|
||||
if !added {
|
||||
cType = CommentTypeRemovedDependency
|
||||
|
|
@ -515,7 +517,7 @@ func createIssueDependencyComment(e *xorm.Session, doer *User, repo *Repository,
|
|||
return createComment(e, &CreateCommentOptions{
|
||||
Type: cType,
|
||||
Doer: doer,
|
||||
Repo: repo,
|
||||
Repo: issue.Repo,
|
||||
Issue: issue,
|
||||
DependentIssue: dependantIssue,
|
||||
Content: issue.Title,
|
||||
|
|
@ -529,6 +531,7 @@ type CreateCommentOptions struct {
|
|||
Repo *Repository
|
||||
Issue *Issue
|
||||
Label *Label
|
||||
DependentIssue *Issue
|
||||
|
||||
OldMilestoneID int64
|
||||
MilestoneID int64
|
||||
|
|
@ -541,7 +544,6 @@ type CreateCommentOptions struct {
|
|||
LineNum int64
|
||||
Content string
|
||||
Attachments []string // UUIDs of attachments
|
||||
DependentIssue int64
|
||||
}
|
||||
|
||||
// CreateComment creates comment of issue or commit.
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@ import (
|
|||
|
||||
// IssueDependency is connection request for receiving issue notification.
|
||||
type IssueDependency struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
UserID int64 `xorm:"UNIQUE(watch) NOT NULL"`
|
||||
IssueID int64 `xorm:"UNIQUE(watch) NOT NULL"`
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
UserID int64 `xorm:"UNIQUE(watch) NOT NULL"`
|
||||
IssueID int64 `xorm:"UNIQUE(watch) NOT NULL"`
|
||||
DependencyID int64 `xorm:"UNIQUE(watch) NOT NULL"`
|
||||
Created time.Time `xorm:"-"`
|
||||
CreatedUnix int64 `xorm:"NOT NULL"`
|
||||
Updated time.Time `xorm:"-"`
|
||||
UpdatedUnix int64 `xorm:"NOT NULL"`
|
||||
Created time.Time `xorm:"-"`
|
||||
CreatedUnix int64 `xorm:"NOT NULL"`
|
||||
Updated time.Time `xorm:"-"`
|
||||
UpdatedUnix int64 `xorm:"NOT NULL"`
|
||||
}
|
||||
|
||||
// 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
|
||||
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()
|
||||
|
||||
// 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
|
||||
exists, err = issueDepExists(x, issueID, depID)
|
||||
exists, err = issueDepExists(x, issue.ID, dep.ID)
|
||||
if err != nil {
|
||||
return err, exists, false
|
||||
}
|
||||
|
||||
// If it not exists, create it, otherwise show an error message
|
||||
if !exists {
|
||||
// Check if the other issue exists
|
||||
var issue = Issue{}
|
||||
issueExists, err := x.Id(depID).Get(&issue)
|
||||
newId := new(IssueDependency)
|
||||
newId.UserID = user.ID
|
||||
newId.IssueID = issue.ID
|
||||
newId.DependencyID = dep.ID
|
||||
|
||||
if issueExists {
|
||||
newId := new(IssueDependency)
|
||||
newId.UserID = userID
|
||||
newId.IssueID = issueID
|
||||
newId.DependencyID = depID
|
||||
|
||||
if _, err := x.Insert(newId); err != nil {
|
||||
return err, exists, false
|
||||
}
|
||||
|
||||
user, err := getUserByID(x, userID)
|
||||
if err != nil {
|
||||
return err, exists, false
|
||||
}
|
||||
|
||||
// Add comment referencing the new dependency
|
||||
|
||||
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
|
||||
}
|
||||
if _, err := x.Insert(newId); err != nil {
|
||||
return err, exists, false
|
||||
}
|
||||
|
||||
// Add comment referencing the new dependency
|
||||
_, err = createIssueDependencyComment(sess, user, issue, dep, true)
|
||||
|
||||
if err != nil {
|
||||
return err, exists, false
|
||||
}
|
||||
|
||||
// Create a new comment for the dependent issue
|
||||
_, err = createIssueDependencyComment(sess, user, dep, issue, true)
|
||||
|
||||
if err != nil {
|
||||
return err, exists, false
|
||||
}
|
||||
return err, exists, true
|
||||
}
|
||||
return nil, exists, false
|
||||
}
|
||||
|
||||
// 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()
|
||||
|
||||
// TODO: Same as above
|
||||
|
|
@ -127,7 +97,7 @@ func RemoveIssueDependency(userID, issueID int64, depID int64, depType int64) (e
|
|||
}
|
||||
|
||||
// Check if it exists
|
||||
exists, err := issueDepExists(x, issueID, depID)
|
||||
exists, err := issueDepExists(x, issue.ID, dep.ID)
|
||||
if err != nil {
|
||||
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 exists {
|
||||
|
||||
if depType == 1{
|
||||
_, err := x.Delete(&IssueDependency{IssueID: issueID, DependencyID: depID})
|
||||
if depType == 1 {
|
||||
_, err := x.Delete(&IssueDependency{IssueID: issue.ID, DependencyID: dep.ID})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if depType == 2{
|
||||
_, err := x.Delete(&IssueDependency{IssueID: depID, DependencyID: issueID})
|
||||
if depType == 2 {
|
||||
_, err := x.Delete(&IssueDependency{IssueID: dep.ID, DependencyID: issue.ID})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Add comment referencing the removed dependency
|
||||
issue, err := getIssueByID(x, depID)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user, _ := getUserByID(x, userID)
|
||||
|
||||
repo, _ := getRepositoryByID(x, issue.RepoID)
|
||||
|
||||
_, err = createIssueDependencyComment(sess, user, repo, issue, depID, false)
|
||||
_, err = createIssueDependencyComment(sess, user, issue, dep, false)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create a new comment for the dependent issue
|
||||
depIssue, err := getIssueByID(x, issueID)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
repo, _ = getRepositoryByID(x, depIssue.RepoID)
|
||||
|
||||
_, err = createIssueDependencyComment(sess, user, repo, depIssue, issueID, false)
|
||||
_, err = createIssueDependencyComment(sess, user, dep, issue, false)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -202,12 +154,12 @@ 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(issueID int64) bool {
|
||||
|
||||
var issueDeps []IssueDependency
|
||||
err := x.Where("issue_id = ?", issueID).Find(&issueDeps)
|
||||
|
||||
for _, issueDep := range issueDeps{
|
||||
for _, issueDep := range issueDeps {
|
||||
issueDetails, _ := getIssueByID(x, issueDep.DependencyID)
|
||||
if !issueDetails.IsClosed {
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
|
||||
// Adds new dependencies
|
||||
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 {
|
||||
c.Handle(http.StatusBadRequest, "issue ID is not int", err)
|
||||
return
|
||||
|
|
@ -28,12 +28,19 @@ func AddDependency(c *context.Context) {
|
|||
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
|
||||
if dep == issueIndex{
|
||||
if dep.Index == issueIndex{
|
||||
c.Flash.Error("You cannot make an issue depend on itself!")
|
||||
} else {
|
||||
|
||||
err, exists, depExists := models.CreateIssueDependency(c.User.ID, issue.ID, dep)
|
||||
err, exists, depExists := models.CreateIssueDependency(c.User, issue, dep)
|
||||
if err != nil {
|
||||
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueDependency", err)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
|
||||
// IssueWatch sets issue watching
|
||||
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 {
|
||||
c.Handle(http.StatusBadRequest, "issue ID is not int", err)
|
||||
return
|
||||
|
|
@ -41,9 +41,15 @@ func RemoveDependency(c *context.Context) {
|
|||
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 {
|
||||
panic(err)
|
||||
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueDependency", err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,7 +152,10 @@
|
|||
<div class="detail">
|
||||
<span class="text grey">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -168,7 +171,7 @@
|
|||
<div class="detail">
|
||||
<span class="text grey">
|
||||
<i class="octicon octicon-trashcan"></i>
|
||||
<a href="{{$.RepoLink}}/issues/{{.DependentIssue}}">#{{.DependentIssue}} {{.Content}}</a>
|
||||
<a href="{{$.RepoLink}}/issues/{{.DependentIssueID}}">#{{.DependentIssueID}} {{.Content}}</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user