Started implementation of comments
Signed-off-by: Konrad <konrad@kola-entertainments.de>
This commit is contained in:
parent
4cb857fe0d
commit
8c8a244c34
|
|
@ -322,8 +322,18 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
|
||||||
Content: opts.Content,
|
Content: opts.Content,
|
||||||
OldTitle: opts.OldTitle,
|
OldTitle: opts.OldTitle,
|
||||||
NewTitle: opts.NewTitle,
|
NewTitle: opts.NewTitle,
|
||||||
|
DependentIssue: opts.DependentIssue,
|
||||||
}
|
}
|
||||||
if _, err = e.Insert(comment); err != nil {
|
|
||||||
|
//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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -495,6 +505,23 @@ 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) {
|
||||||
|
cType := CommentTypeAddedDependency
|
||||||
|
if !added {
|
||||||
|
cType = CommentTypeRemovedDependency
|
||||||
|
}
|
||||||
|
|
||||||
|
return createComment(e, &CreateCommentOptions{
|
||||||
|
Type: cType,
|
||||||
|
Doer: doer,
|
||||||
|
Repo: repo,
|
||||||
|
Issue: issue,
|
||||||
|
DependentIssue: dependantIssue,
|
||||||
|
Content: issue.Title,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// CreateCommentOptions defines options for creating comment
|
// CreateCommentOptions defines options for creating comment
|
||||||
type CreateCommentOptions struct {
|
type CreateCommentOptions struct {
|
||||||
Type CommentType
|
Type CommentType
|
||||||
|
|
@ -514,6 +541,7 @@ 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.
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,13 @@ 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(userID, issueID int64, depID int64) (err error, exists bool, depExists bool) {
|
||||||
|
sess := x.NewSession()
|
||||||
|
defer sess.Close()
|
||||||
|
if err = sess.Begin(); err != nil {
|
||||||
|
return err, false, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Move this to the appropriate place
|
||||||
err = x.Sync(new(IssueDependency))
|
err = x.Sync(new(IssueDependency))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, exists, false
|
return err, exists, false
|
||||||
|
|
@ -60,6 +67,7 @@ func CreateIssueDependency(userID, issueID int64, depID int64) (err error, exist
|
||||||
// Check if the other issue exists
|
// Check if the other issue exists
|
||||||
var issue = Issue{}
|
var issue = Issue{}
|
||||||
issueExists, err := x.Id(depID).Get(&issue)
|
issueExists, err := x.Id(depID).Get(&issue)
|
||||||
|
|
||||||
if issueExists {
|
if issueExists {
|
||||||
newId := new(IssueDependency)
|
newId := new(IssueDependency)
|
||||||
newId.UserID = userID
|
newId.UserID = userID
|
||||||
|
|
@ -70,30 +78,40 @@ func CreateIssueDependency(userID, issueID int64, depID int64) (err error, exist
|
||||||
return err, exists, false
|
return err, exists, false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add comment referencing the new dependency
|
user, err := getUserByID(x, userID)
|
||||||
comment := &Comment{
|
if err != nil {
|
||||||
IssueID: issueID,
|
|
||||||
PosterID: userID,
|
|
||||||
Type: CommentTypeAddedDependency,
|
|
||||||
Content: issue.Title,
|
|
||||||
DependentIssue: depID,
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := x.Insert(comment); err != nil {
|
|
||||||
return err, exists, false
|
return err, exists, false
|
||||||
}
|
}
|
||||||
|
|
||||||
var depIssue = Issue{}
|
// Add comment referencing the new dependency
|
||||||
_, err = x.Id(issueID).Get(&depIssue)
|
|
||||||
comment = &Comment{
|
repo, err := getRepositoryByID(x, issue.RepoID)
|
||||||
IssueID: depID,
|
|
||||||
PosterID: userID,
|
if err != nil {
|
||||||
Type: CommentTypeAddedDependency,
|
return err, exists, false
|
||||||
Content: depIssue.Title,
|
|
||||||
DependentIssue: issueID,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := x.Insert(comment); err != nil {
|
|
||||||
|
_, 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, false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -104,6 +122,13 @@ func CreateIssueDependency(userID, issueID int64, depID int64) (err error, exist
|
||||||
|
|
||||||
// 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(userID, issueID int64, depID int64, depType int64) (err error) {
|
||||||
|
sess := x.NewSession()
|
||||||
|
defer sess.Close()
|
||||||
|
if err = sess.Begin(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Same as above
|
||||||
err = x.Sync(new(IssueDependency))
|
err = x.Sync(new(IssueDependency))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -133,31 +158,34 @@ func RemoveIssueDependency(userID, issueID int64, depID int64, depType int64) (e
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add comment referencing the removed dependency
|
// Add comment referencing the removed dependency
|
||||||
var issue = Issue{}
|
issue, err := getIssueByID(x, depID)
|
||||||
_, err = x.Id(depID).Get(&issue)
|
|
||||||
comment := &Comment{
|
|
||||||
IssueID: issueID,
|
|
||||||
PosterID: userID,
|
|
||||||
Type: CommentTypeRemovedDependency,
|
|
||||||
Content: issue.Title,
|
|
||||||
DependentIssue: depID,
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := x.Insert(comment); err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var depIssue = Issue{}
|
user, _ := getUserByID(x, userID)
|
||||||
_, err = x.Id(issueID).Get(&depIssue)
|
|
||||||
comment = &Comment{
|
repo, _ := getRepositoryByID(x, issue.RepoID)
|
||||||
IssueID: depID,
|
|
||||||
PosterID: userID,
|
_, err = createIssueDependencyComment(sess, user, repo, issue, depID, false)
|
||||||
Type: CommentTypeRemovedDependency,
|
|
||||||
Content: depIssue.Title,
|
if err != nil {
|
||||||
DependentIssue: issueID,
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := x.Insert(comment); err != nil {
|
// 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)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IssueWatch sets issue watching
|
// Adds new dependencies
|
||||||
func AddDependency(c *context.Context) {
|
func AddDependency(c *context.Context) {
|
||||||
dep, err := strconv.ParseInt(c.Req.PostForm.Get("newDependency"), 10, 64)
|
dep, err := strconv.ParseInt(c.Req.PostForm.Get("newDependency"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -33,7 +33,7 @@ func AddDependency(c *context.Context) {
|
||||||
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.ID, issue.ID, dep)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueDependency", err)
|
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueDependency", err)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ func RemoveDependency(c *context.Context) {
|
||||||
|
|
||||||
err = models.RemoveIssueDependency(c.User.ID, issue.ID, dep, depType)
|
err = models.RemoveIssueDependency(c.User.ID, issue.ID, dep, depType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueDependency", err)
|
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueDependency", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user