Added delete Dependency function
+ Improved Event Comments Signed-off-by: Konrad <konrad@kola-entertainments.de>
This commit is contained in:
parent
0a1e57a995
commit
ab4d5b2126
4
conf/app.ini
vendored
4
conf/app.ini
vendored
|
|
@ -23,6 +23,8 @@ PULL_REQUEST_QUEUE_LENGTH = 1000
|
||||||
PREFERRED_LICENSES = Apache License 2.0,MIT License
|
PREFERRED_LICENSES = Apache License 2.0,MIT License
|
||||||
; Disable ability to interact with repositories by HTTP protocol
|
; Disable ability to interact with repositories by HTTP protocol
|
||||||
DISABLE_HTTP_GIT = false
|
DISABLE_HTTP_GIT = false
|
||||||
|
; Force ssh:// clone url instead of scp-style uri when default SSH port is used
|
||||||
|
USE_COMPAT_SSH_URI = false
|
||||||
|
|
||||||
[repository.editor]
|
[repository.editor]
|
||||||
; List of file extensions that should have line wraps in the CodeMirror editor
|
; List of file extensions that should have line wraps in the CodeMirror editor
|
||||||
|
|
@ -379,7 +381,7 @@ MODE = console
|
||||||
; Buffer length of channel, keep it as it is if you don't know what it is.
|
; Buffer length of channel, keep it as it is if you don't know what it is.
|
||||||
BUFFER_LEN = 10000
|
BUFFER_LEN = 10000
|
||||||
; Either "Trace", "Debug", "Info", "Warn", "Error", "Critical", default is "Trace"
|
; Either "Trace", "Debug", "Info", "Warn", "Error", "Critical", default is "Trace"
|
||||||
LEVEL = Debug
|
LEVEL = Trace
|
||||||
|
|
||||||
; For "console" mode only
|
; For "console" mode only
|
||||||
[log.console]
|
[log.console]
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,8 @@ const (
|
||||||
CommentTypeDeleteBranch
|
CommentTypeDeleteBranch
|
||||||
// Dependency added
|
// Dependency added
|
||||||
CommentTypeAddedDependency
|
CommentTypeAddedDependency
|
||||||
|
//Dependency removed
|
||||||
|
CommentTypeRemovedDependency
|
||||||
)
|
)
|
||||||
|
|
||||||
// CommentTag defines comment tag type
|
// CommentTag defines comment tag type
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IssueDependency is connection request for receiving issue notification.
|
// IssueDependency is connection request for receiving issue notification.
|
||||||
|
|
@ -43,6 +44,7 @@ func (iw *IssueDependency) BeforeUpdate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateIssueDependency creates a new dependency for an issue
|
// CreateIssueDependency creates a new dependency for an issue
|
||||||
|
// TODO: prevent issues having itself as dependency
|
||||||
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) {
|
||||||
err = x.Sync(new(IssueDependency))
|
err = x.Sync(new(IssueDependency))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -75,6 +77,17 @@ func CreateIssueDependency(userID, issueID int64, depID int64) (err error, exist
|
||||||
IssueID: issueID,
|
IssueID: issueID,
|
||||||
PosterID: userID,
|
PosterID: userID,
|
||||||
Type: CommentTypeAddedDependency,
|
Type: CommentTypeAddedDependency,
|
||||||
|
Content: strconv.FormatInt(depID, 10),
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := x.Insert(comment); err != nil {
|
||||||
|
return err, exists, false
|
||||||
|
}
|
||||||
|
comment = &Comment{
|
||||||
|
IssueID: depID,
|
||||||
|
PosterID: userID,
|
||||||
|
Type: CommentTypeAddedDependency,
|
||||||
|
Content: strconv.FormatInt(issueID, 10),
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := x.Insert(comment); err != nil {
|
if _, err := x.Insert(comment); err != nil {
|
||||||
|
|
@ -86,6 +99,62 @@ func CreateIssueDependency(userID, issueID int64, depID int64) (err error, exist
|
||||||
return nil, exists, false
|
return nil, exists, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removes a dependency from an issue
|
||||||
|
func RemoveIssueDependency(userID, issueID int64, depID int64, depType int64) (err error) {
|
||||||
|
err = x.Sync(new(IssueDependency))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it exists
|
||||||
|
exists, err := issueDepExists(x, issueID, depID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it exists, remove it, otherwise show an error message
|
||||||
|
if exists {
|
||||||
|
|
||||||
|
if depType == 1{
|
||||||
|
_, err := x.Delete(&IssueDependency{IssueID: issueID, DependencyID: depID})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if depType == 2{
|
||||||
|
_, err := x.Delete(&IssueDependency{IssueID: depID, DependencyID: issueID})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add comment referencing the removed dependency
|
||||||
|
comment := &Comment{
|
||||||
|
IssueID: issueID,
|
||||||
|
PosterID: userID,
|
||||||
|
Type: CommentTypeRemovedDependency,
|
||||||
|
Content: strconv.FormatInt(depID, 10),
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := x.Insert(comment); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
comment = &Comment{
|
||||||
|
IssueID: depID,
|
||||||
|
PosterID: userID,
|
||||||
|
Type: CommentTypeRemovedDependency,
|
||||||
|
Content: strconv.FormatInt(issueID, 10),
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := x.Insert(comment); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the dependency already exists
|
// Check if the dependency already exists
|
||||||
func issueDepExists(e Engine, issueID int64, depID int64) (exists bool, err error) {
|
func issueDepExists(e Engine, issueID int64, depID int64) (exists bool, err error) {
|
||||||
var Dependencies = IssueDependency{IssueID: issueID, DependencyID: depID}
|
var Dependencies = IssueDependency{IssueID: issueID, DependencyID: depID}
|
||||||
|
|
@ -700,6 +700,7 @@ issues.dependency.cancel = Cancel
|
||||||
issues.dependency.add_header = Add New Dependency
|
issues.dependency.add_header = Add New Dependency
|
||||||
issues.dependency.issue_number = Issuenumber
|
issues.dependency.issue_number = Issuenumber
|
||||||
issues.dependency.added_dependency = `<a href="%[1]s">%[2]s</a> added a new dependency %[3]s`
|
issues.dependency.added_dependency = `<a href="%[1]s">%[2]s</a> added a new dependency %[3]s`
|
||||||
|
issues.dependency.removed_dependency = `<a href="%[1]s">%[2]s</a> removed a dependency %[3]s`
|
||||||
|
|
||||||
pulls.desc = Pulls management your code review and merge requests
|
pulls.desc = Pulls management your code review and merge requests
|
||||||
pulls.new = New Pull Request
|
pulls.new = New Pull Request
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ func AddDependency(c *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if depExists {
|
if !depExists {
|
||||||
c.Flash.Error("Dependend issue does not exist!")
|
c.Flash.Error("Dependend issue does not exist!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
52
routers/repo/issue_dependency_remove.go
Normal file
52
routers/repo/issue_dependency_remove.go
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package repo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/modules/context"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IssueWatch sets issue watching
|
||||||
|
func RemoveDependency(c *context.Context) {
|
||||||
|
dep, err := strconv.ParseInt(c.Req.PostForm.Get("removeDependencyID"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
c.Handle(http.StatusBadRequest, "issue ID is not int", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
issueIndex := c.ParamsInt64("index")
|
||||||
|
issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, issueIndex)
|
||||||
|
if err != nil {
|
||||||
|
c.Handle(http.StatusInternalServerError, "GetIssueByIndex", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dependency Type
|
||||||
|
// Types: 1 = blockedBy, 2 = blocking
|
||||||
|
depType, err := strconv.ParseInt(c.Req.PostForm.Get("dependencyType"), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
c.Handle(http.StatusInternalServerError, "GetDependecyType", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if depType != 1 && depType != 2{
|
||||||
|
c.Handle(http.StatusBadRequest, "GetDependecyType", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = models.RemoveIssueDependency(c.User.ID, issue.ID, dep, depType)
|
||||||
|
if err != nil {
|
||||||
|
c.Handle(http.StatusInternalServerError, "CreateOrUpdateIssueDependency", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
url := fmt.Sprintf("%s/issues/%d", c.Repo.RepoLink, issueIndex)
|
||||||
|
c.Redirect(url, http.StatusSeeOther)
|
||||||
|
}
|
||||||
|
|
@ -467,6 +467,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
||||||
m.Post("/content", repo.UpdateIssueContent)
|
m.Post("/content", repo.UpdateIssueContent)
|
||||||
m.Post("/watch", repo.IssueWatch)
|
m.Post("/watch", repo.IssueWatch)
|
||||||
m.Post("/addDependency", repo.AddDependency)
|
m.Post("/addDependency", repo.AddDependency)
|
||||||
|
m.Post("/removeDependency", repo.RemoveDependency)
|
||||||
m.Combo("/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment)
|
m.Combo("/comments").Post(bindIgnErr(auth.CreateCommentForm{}), repo.NewComment)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -143,12 +143,30 @@
|
||||||
{{else if eq .Type 12}}
|
{{else if eq .Type 12}}
|
||||||
<div class="event">
|
<div class="event">
|
||||||
<span class="octicon octicon-primitive-dot"></span>
|
<span class="octicon octicon-primitive-dot"></span>
|
||||||
|
<a class="ui avatar image" href="{{.Poster.HomeLink}}">
|
||||||
|
<img src="{{.Poster.RelAvatarLink}}">
|
||||||
|
</a>
|
||||||
|
<span class="text grey">
|
||||||
|
{{$.i18n.Tr "repo.issues.dependency.added_dependency" .Poster.HomeLink .Poster.Name $createdStr | Safe}}
|
||||||
|
</span>
|
||||||
|
<div class="detail">
|
||||||
|
<span class="octicon octicon-plus"></span>
|
||||||
|
<span class="text grey">{{.Content}}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{else if eq .Type 13}}
|
||||||
|
<div class="event">
|
||||||
|
<span class="octicon octicon-primitive-dot"></span>
|
||||||
|
<a class="ui avatar image" href="{{.Poster.HomeLink}}">
|
||||||
|
<img src="{{.Poster.RelAvatarLink}}">
|
||||||
|
</a>
|
||||||
|
<span class="text grey">
|
||||||
|
{{$.i18n.Tr "repo.issues.dependency.removed_dependency" .Poster.HomeLink .Poster.Name $createdStr | Safe}}
|
||||||
|
</span>
|
||||||
|
<div class="detail">
|
||||||
|
<span class="text grey octicon octicon-trashcan"></span>
|
||||||
|
<span class="text grey">{{.Content}} </span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<a class="ui avatar image" href="{{.Poster.HomeLink}}">
|
|
||||||
<img src="{{.Poster.RelAvatarLink}}">
|
|
||||||
</a>
|
|
||||||
<span class="text grey">
|
|
||||||
{{$.i18n.Tr "repo.issues.dependency.added_dependency" .Poster.HomeLink .Poster.Name $createdStr | Safe}}
|
|
||||||
</span>
|
|
||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@
|
||||||
{{range .BlockedByDependencies}}
|
{{range .BlockedByDependencies}}
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<div class="right floated content">
|
<div class="right floated content">
|
||||||
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.ID}}, 'blockedBy');">
|
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.ID}}, 1);">
|
||||||
<i class="delete icon text red"></i>
|
<i class="delete icon text red"></i>
|
||||||
</a>
|
</a>
|
||||||
{{if .IsClosed}}
|
{{if .IsClosed}}
|
||||||
|
|
@ -159,7 +159,7 @@
|
||||||
{{range .BlockingDependencies}}
|
{{range .BlockingDependencies}}
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<div class="right floated content">
|
<div class="right floated content">
|
||||||
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.ID}}, 'blocking');">
|
<a class="delete-dependency-button" onclick="deleteDependencyModal({{.ID}}, 2);">
|
||||||
<i class="delete icon text red"></i>
|
<i class="delete icon text red"></i>
|
||||||
</a>
|
</a>
|
||||||
{{if .IsClosed}}
|
{{if .IsClosed}}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user