-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Issue priority #4823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Issue priority #4823
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
818f471
Priority updating api for issues (both web and api).
BetaCat0 87140e9
recovery vendor.
BetaCat0 5177834
remove update-issue-priority api temporarily
BetaCat0 b38e733
fix comments
BetaCat0 8a021f2
fix issues & bug
BetaCat0 52109e3
fix issue
BetaCat0 461046b
Web UI for issue pin/unpin
BetaCat0 f9297e5
update vendor
BetaCat0 ee58221
update vendor
BetaCat0 5d3c900
append -v to make vendor: to show what's actually going on during ven…
BetaCat0 c516e8e
reset priority in fixtures/issue.yml
BetaCat0 9e726b9
update test case
BetaCat0 4083ee0
Priority updating api for issues (both web and api).
BetaCat0 656ae37
recovery vendor.
BetaCat0 6613309
update UI in issue pin
BetaCat0 552ea89
renamed files
BetaCat0 0100f33
resolve conflicts
BetaCat0 5953bed
resolve conflicts
BetaCat0 e0b6699
Merge branch 'master' into feature-priority
BetaCat0 4de6e95
Merge branch 'master' into feature-priority
techknowlogick 4d1aded
Update type & add copyright
techknowlogick 5d9ce31
Update type & add copyright
techknowlogick db32f2a
Update issuse_priority.go
techknowlogick 300b19e
Update type
techknowlogick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2018 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 models | ||
|
||
import ( | ||
"github.com/go-xorm/xorm" | ||
) | ||
|
||
const ( | ||
// PriorityDefault defines the default priority | ||
PriorityDefault = 0 | ||
) | ||
|
||
// UpdateIssuePriority updates the priority | ||
func UpdateIssuePriority(issue *Issue) error { | ||
if err := issue.loadRepo(x); err != nil { | ||
return err | ||
} | ||
|
||
if issue.Priority < PriorityDefault { | ||
return ErrIssueInvalidPriority{ID: issue.ID, RepoID: issue.Repo.ID, DesiredPriority: issue.Priority} | ||
} | ||
|
||
_, err := AutoTransaction(func(session *xorm.Session) (interface{}, error) { | ||
return nil, updateIssueCols(session, &Issue{ID: issue.ID, Priority: issue.Priority}, "priority") | ||
}, x) | ||
|
||
return err | ||
} | ||
|
||
// PinIssue to pin an issue | ||
func PinIssue(issue *Issue, doer *User) error { | ||
if err := issue.loadRepo(x); err != nil { | ||
return err | ||
} | ||
|
||
if has, err := HasAccess(doer.ID, issue.Repo, AccessModeWrite); err != nil { | ||
return err | ||
} else if !has { | ||
return ErrUserDoesNotHaveAccessToRepo{UserID: doer.ID, RepoName: issue.Repo.Name} | ||
} | ||
|
||
_, err := AutoTransaction(func(session *xorm.Session) (interface{}, error) { | ||
var p int64 | ||
_, err := session.Table("issue"). | ||
Select("MAX(priority)").Where("repo_id=? and is_pull=0", issue.Repo.ID).Get(&p) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
_, err = session.Table("issue").Where("id = ?", issue.ID). | ||
Update(map[string]interface{}{"priority": p + 10}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return nil, nil | ||
}, x) | ||
|
||
return err | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2018 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 models | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestUpdateIssuePriority(t *testing.T) { | ||
assert.NoError(t, PrepareTestDatabase()) | ||
|
||
issue := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) | ||
|
||
issue.Priority = 99 | ||
err := UpdateIssuePriority(issue) | ||
assert.NoError(t, err) | ||
|
||
issue = AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) | ||
assert.EqualValues(t, 99, issue.Priority) | ||
|
||
issue.Priority = -1 | ||
err = UpdateIssuePriority(issue) | ||
assert.Error(t, err) | ||
assert.EqualValues(t, err, ErrIssueInvalidPriority{ | ||
ID: issue.ID, RepoID: issue.Repo.ID, DesiredPriority: issue.Priority}) | ||
} | ||
|
||
func TestPinIssue(t *testing.T) { | ||
assert.NoError(t, PrepareTestDatabase()) | ||
|
||
issue := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) | ||
repo := AssertExistsAndLoadBean(t, &Repository{ID: issue.RepoID}).(*Repository) | ||
doer := AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User) | ||
|
||
err := PinIssue(issue, doer) | ||
assert.NoError(t, err) | ||
|
||
issue = AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue) | ||
assert.EqualValues(t, 10, issue.Priority) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2018 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 models | ||
|
||
import ( | ||
"github.com/go-xorm/xorm" | ||
) | ||
|
||
// AutoTransaction Execute sql wrapped in a transaction(abbr as tx), tx will automatic commit if no errors occurred | ||
func AutoTransaction(f func(*xorm.Session) (interface{}, error), engine *xorm.Engine) (interface{}, error) { | ||
session := engine.NewSession() | ||
defer session.Close() | ||
|
||
if err := session.Begin(); err != nil { | ||
return nil, err | ||
} | ||
|
||
result, err := f(session) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := session.Commit(); err != nil { | ||
return nil, err | ||
} | ||
|
||
return result, nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.