Skip to content
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

Added dependencies for issues (#2196) #2531

Merged
merged 380 commits into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from 107 commits
Commits
Show all changes
380 commits
Select commit Hold shift + click to select a range
c5992f5
Fixed translation issue
kolaente Oct 28, 2017
021a7e0
Fixed whitespace
kolaente Oct 28, 2017
55f6cf9
Fixed issue where an issue could not be closed because of non-existin…
kolaente Oct 28, 2017
30fe97a
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Oct 30, 2017
751bbee
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Oct 30, 2017
913584a
fmt
kolaente Oct 30, 2017
53ec08f
fmt
kolaente Oct 30, 2017
14aa1d2
When adding a dependency, the current issue is not shown in the list …
kolaente Oct 31, 2017
0bbc695
Fixed a bug where a border in the issue dependency list was on the wr…
kolaente Oct 31, 2017
a651cc3
Rebased Font-awesome with master
kolaente Nov 1, 2017
f188031
Rebased sidebar template to remove unrelated changes
kolaente Nov 1, 2017
58e7c2b
Rebased Font-awesome License file with master
kolaente Nov 1, 2017
5a9f273
Removed unrelated changes
kolaente Nov 1, 2017
ba734d6
Removed unrelated changes
kolaente Nov 1, 2017
5e4b6fc
Removed unrelated changes in locales
kolaente Nov 1, 2017
5302eca
Removed unrelated changes in gitgraph
kolaente Nov 1, 2017
2fe66c2
Removed unrelated changes in routes
kolaente Nov 1, 2017
a2b652e
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Nov 1, 2017
762266f
Removed unrelated changes in routes
kolaente Nov 1, 2017
6b3a51a
Removed unrelated changes in locales
kolaente Nov 1, 2017
2dca487
gofmt
kolaente Nov 1, 2017
d1df4ec
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Nov 1, 2017
dd24b9f
Implemented missing create table for Issue Dependencies table \
kolaente Nov 1, 2017
827291e
Cleanup
kolaente Nov 1, 2017
c0bc5e8
Fixed indetion
kolaente Nov 1, 2017
993a3c0
Fixed indention
kolaente Nov 1, 2017
3beecd2
Improved readability
kolaente Nov 1, 2017
4e9e1f8
Removed unused named returns
kolaente Nov 1, 2017
e364cfc
Improved Readability
kolaente Nov 1, 2017
c4ba8d6
Merge branch 'master' into master
kolaente Nov 6, 2017
9e9d8b9
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Nov 6, 2017
80437f8
Merge remote-tracking branch 'origin/master'
kolaente Nov 6, 2017
a54f930
Removed wrong notification content in struct
kolaente Nov 6, 2017
d65fe40
Added unique to issue dependency struct for issueID and DependencyID
kolaente Nov 6, 2017
f38b3b4
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Nov 13, 2017
f1f0607
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Nov 14, 2017
6109fcf
Simplified check for open dependencies
kolaente Nov 14, 2017
85cdd94
Moved methods to get issue dependencies for a given issue from repo t…
kolaente Nov 14, 2017
a57bcf1
Added more specific error when creating a new dependency if it alread…
kolaente Nov 26, 2017
fc35252
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Nov 26, 2017
33c5033
Started implementing settign for dependencies
kolaente Nov 27, 2017
c81041f
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Nov 27, 2017
db4f578
Finished implementing setting for dependencies
kolaente Nov 27, 2017
03769da
gofmt
kolaente Nov 27, 2017
6eea6c6
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Nov 29, 2017
d00eb86
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Nov 29, 2017
78dd6c1
Moved checking if dependencies are enabled to issue_dependency.go
kolaente Dec 2, 2017
1fded52
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Dec 2, 2017
3566e9e
Added tests for issue dependencies
kolaente Dec 3, 2017
9af3aae
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Dec 3, 2017
f61ba0f
gofmt
kolaente Dec 3, 2017
d0baadc
gofmt
kolaente Dec 3, 2017
9dd0cb1
Fixed misspell
kolaente Dec 3, 2017
fae4466
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Dec 4, 2017
8bcb624
Added missing license header
kolaente Dec 4, 2017
25427ae
Using "sess" instead of "x" when removing a depencency
kolaente Dec 4, 2017
66433a9
gofmt
kolaente Dec 4, 2017
01f9e63
Modified import order
kolaente Dec 6, 2017
13f0e17
Fixed using xorm session
kolaente Dec 6, 2017
cdd322f
Merge branch 'master' into master
kolaente Dec 6, 2017
e98f92d
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Dec 6, 2017
822c75c
Merge remote-tracking branch 'origin/master'
kolaente Dec 6, 2017
f02fd33
Fixed import order
kolaente Dec 7, 2017
7e93434
Merge branch 'master' into master
kolaente Dec 7, 2017
172b1f0
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Dec 19, 2017
8354f2b
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Dec 19, 2017
69769ec
gofmt
kolaente Dec 19, 2017
1608248
Fixed deleting a dependency when it going from the blocking one
kolaente Dec 19, 2017
46f099c
Merge remote-tracking branch 'origin/master'
kolaente Dec 19, 2017
e6aeeac
typo
kolaente Dec 19, 2017
08763cf
typo
kolaente Dec 19, 2017
32c5605
Added docs for dependencies
kolaente Dec 19, 2017
ed4a47d
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Dec 29, 2017
200f88d
Small fixes to xorm-stuff
kolaente Dec 29, 2017
9714024
Renamed "CanUseDependencies" to "CanCreateDependencies" to be more pr…
kolaente Dec 29, 2017
2c8103f
Fixed import order
kolaente Dec 29, 2017
1f0bac0
Fixed using strconvert
kolaente Dec 29, 2017
d29ca0c
Fixed comment
kolaente Dec 29, 2017
70589e6
Added Custom error types for issue dependencies
kolaente Dec 29, 2017
1064acc
Logging error
kolaente Dec 29, 2017
c176353
fixed typos
kolaente Dec 29, 2017
866beeb
Removed unsued code
kolaente Dec 29, 2017
5e20447
Replaced c with ctx for consistency
kolaente Dec 29, 2017
2058f4e
Fixed error message
kolaente Dec 29, 2017
5dc9c22
Renamed "c" to "ctx" for consistency
kolaente Dec 29, 2017
f48d6cd
Error messages moved to locale file
kolaente Dec 29, 2017
8931ced
Fixed error messages
kolaente Dec 29, 2017
df638db
Removed unused import
kolaente Dec 29, 2017
4855f83
Fixed indent
kolaente Dec 29, 2017
108edf9
Modified tests to work again with modified functions
kolaente Dec 29, 2017
2a249c4
gofmt
kolaente Dec 29, 2017
c534699
Fixed Lint suggestions
kolaente Dec 29, 2017
57a4f86
typo
kolaente Dec 29, 2017
fdb106d
typo
kolaente Dec 29, 2017
a2a6fed
Merge branch 'master' into master
kolaente Dec 30, 2017
436ea16
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Jan 1, 2018
9eedb3f
Fixed check for issue is nil before getting issue details
kolaente Jan 1, 2018
b7ed097
Fixed localization
kolaente Jan 1, 2018
661bd7c
gofmt
kolaente Jan 1, 2018
632cca5
Merge branch 'master' into master
kolaente Jan 1, 2018
12c0093
Merge branch 'master' into master
kolaente Jan 2, 2018
96d6db4
Fixed an issue where it would make a request to get all issues even i…
kolaente Jan 2, 2018
0016a3e
Merge branch 'master' into master
kolaente Jan 3, 2018
cd47077
Merge branch 'master' into master
kolaente Jan 3, 2018
8735bc2
Merge branch 'master' into master
kolaente Jan 4, 2018
37dc550
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Jan 6, 2018
f4cb1c7
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Jan 6, 2018
8bc0947
Added more specific locale
kolaente Jan 6, 2018
86be828
Added more specific locale
kolaente Jan 6, 2018
eb295f4
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Jan 6, 2018
171715b
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Jan 6, 2018
4d15f28
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Jan 8, 2018
1f8ef92
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Jan 8, 2018
0fcc3b2
Merge branch 'master' into master
kolaente Jan 9, 2018
d5b1c33
Merge branch 'master' into master
kolaente Jan 11, 2018
5f187df
Fixed communicating errors to the user
kolaente Jan 11, 2018
c44e13b
typo
kolaente Jan 11, 2018
a5b696a
typo
kolaente Jan 11, 2018
cf1b573
Merge branch 'master' into master
kolaente Jan 13, 2018
f71f2d4
Removed unnessecary errorcheck
kolaente Jan 13, 2018
4277014
Fixed indention
kolaente Jan 13, 2018
31eff2f
Added displaying if dependencies are enabled by default or not on con…
kolaente Jan 13, 2018
30ae70a
Moved check for open dependencies to "changeStatus"
kolaente Jan 14, 2018
dd5cfbf
Simplified "CanCreateIssueDependencies"
kolaente Jan 14, 2018
fdabcf1
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Jan 14, 2018
992e168
Fixed lint + gofmt
kolaente Jan 14, 2018
60834bc
Change nothing to trigger CI
kolaente Jan 14, 2018
18fe48e
Change nothing to trigger CI
kolaente Jan 14, 2018
647296c
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Jan 21, 2018
cd734a3
Merge branch 'master' into master
kolaente Jan 24, 2018
f837429
Added only check if we're about to close an issue when closing an iss…
kolaente Jan 24, 2018
0ce2170
Added only check if we're about to close an issue when closing an iss…
kolaente Jan 24, 2018
9ee04eb
Merge remote-tracking branch 'origin/master'
kolaente Jan 24, 2018
cdb5d65
Merge branch 'master' into master
kolaente Jan 31, 2018
9e29f71
Merge branch 'master' into master
kolaente Feb 8, 2018
16b1636
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Feb 12, 2018
be51a47
Merged 'routers/issue_dependency_add' and 'routers/issue_dependency_r…
kolaente Feb 12, 2018
0ea51f8
Use xorm engine from pararmeter instead of global one
kolaente Feb 12, 2018
e322fa3
Added migration to update comments table
kolaente Feb 12, 2018
9584d3f
gofmt
kolaente Feb 12, 2018
1b63df7
Fixed status codes
kolaente Feb 12, 2018
7566292
Updated copyright header
kolaente Feb 12, 2018
421c9fa
Merge branch 'master' into master
jonasfranz Feb 12, 2018
bd3cf60
FIxed import order
kolaente Feb 12, 2018
b58363c
Merge remote-tracking branch 'origin/master'
kolaente Feb 12, 2018
bcaea09
FIxed import order
kolaente Feb 12, 2018
e842472
Merge branch 'master' into master
jonasfranz Feb 15, 2018
64e61d6
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Feb 15, 2018
637895b
Merge remote-tracking branch 'origin/master'
kolaente Feb 15, 2018
77cf3db
Merge branch 'master' into master
kolaente Feb 17, 2018
32db1b3
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Feb 19, 2018
ec0e693
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Feb 19, 2018
5e0a72c
Merge remote-tracking branch 'origin/master'
kolaente Feb 19, 2018
7d1df8b
Merge branch 'master' into master
kolaente Feb 20, 2018
b4f406c
Fixed lang
kolaente Feb 27, 2018
d2ab9e2
Fixed http status code on redirect
Feb 27, 2018
9313332
Cleanup + fmt
kolaente Feb 27, 2018
e4a6426
Added lazy load for issue list
kolaente Feb 27, 2018
138a80b
Grammar
kolaente Feb 27, 2018
264f895
Only check for open dependencies if they are enabled
kolaente Feb 27, 2018
0c6f56d
Remove redundant sprintf
kolaente Feb 27, 2018
250138f
Return JSON when trying to close issue dependencies and fail
kolaente Feb 27, 2018
91e0b53
Simplify redirect
kolaente Feb 27, 2018
5e5139f
Simplify error
kolaente Feb 27, 2018
5852b7c
Merge branch 'master' into master
kolaente Feb 27, 2018
e1f2a8e
Fixed lint
kolaente Feb 27, 2018
20ed1e9
Merge branch 'master' into master
lunny Mar 7, 2018
4d28a82
Implemented issue search via api when adding new dependencies
kolaente Mar 7, 2018
4f94a01
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Mar 11, 2018
2950021
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Mar 18, 2018
c3a5878
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Mar 18, 2018
7a57b6d
Merge remote-tracking branch 'upstream/master'
kolaente Mar 20, 2018
497628e
Merge branch 'master' into master
kolaente Mar 22, 2018
2edfbcd
Cosmetic
kolaente Mar 23, 2018
a25e1dd
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Apr 3, 2018
f49dd29
re-added migration
kolaente Apr 3, 2018
3a24b65
Merge remote-tracking branch 'origin/master'
kolaente Apr 3, 2018
b589726
small improvements
kolaente Apr 4, 2018
c3818a9
fmt
kolaente Apr 4, 2018
7b26e2c
merge into master
kolaente Apr 10, 2018
3820fc4
Added extra error type for unknown dependency type
kolaente Apr 10, 2018
2f136fc
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Apr 13, 2018
29dbc17
removed unused import
kolaente Apr 13, 2018
6f999a0
Fixed unnessecary nested code
kolaente Apr 14, 2018
7528664
More consitency when defining returned variables
kolaente Apr 14, 2018
be76631
Improvements when returning an error.
kolaente Apr 16, 2018
8d2015f
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Apr 16, 2018
ee77151
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Apr 17, 2018
82129b8
Simplified returning blocked/blocking dependencies
kolaente Apr 17, 2018
b00e209
semantics
kolaente Apr 17, 2018
414d1d0
Optimizations to removing a dependency (thanks @Morlinest)
kolaente Apr 17, 2018
9e11e77
Checking if a dependency exists and/or circular is is now done in two…
kolaente Apr 18, 2018
d0b7307
Merge with gitea-master
kolaente Apr 20, 2018
17b2d43
Simplified checking for circular dependencies
kolaente Apr 20, 2018
6af8ef7
Simplified comment creation of issue dependencies
kolaente Apr 20, 2018
2e096a5
Simplified creation of new dependencies
kolaente Apr 20, 2018
1a86536
removed unessecary comment
kolaente Apr 20, 2018
81b51d0
removed unessecary function call
kolaente Apr 20, 2018
b258bc0
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Apr 21, 2018
6a5e138
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Apr 23, 2018
c0cd0c3
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Apr 29, 2018
022e9d2
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Apr 29, 2018
3cd497f
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 1, 2018
16533e9
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 1, 2018
0f8a212
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 2, 2018
a3a544e
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 2, 2018
8266510
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 5, 2018
edf661d
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 5, 2018
9185958
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 6, 2018
f0406c1
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 6, 2018
395c062
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 9, 2018
c877186
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 9, 2018
288cd40
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 9, 2018
d29f582
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 9, 2018
83b8831
fmt
kolaente May 9, 2018
617d8cd
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 11, 2018
6733682
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 18, 2018
236ad85
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 18, 2018
fbd78f4
pre-merge
kolaente May 20, 2018
ad353f0
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente May 20, 2018
5d8383e
Fixed UI bug
kolaente May 20, 2018
8c1f627
Merged with gitea-master
kolaente Jun 6, 2018
15aa9b1
Merged with gitea-master
kolaente Jun 6, 2018
0da2e34
Simplified error messages
kolaente Jun 6, 2018
e18627c
removed unnecessary index
kolaente Jun 6, 2018
39392de
removed unessecary comment
kolaente Jun 6, 2018
87f41c0
removed unnecessary index in xorm declaration
kolaente Jun 6, 2018
c52e970
Added title for error log when using via the api
kolaente Jun 6, 2018
c212a82
Moved check if the repo is allowed to have dependencies to the top of…
kolaente Jun 6, 2018
990985a
Added missing returns
kolaente Jun 6, 2018
05aaee2
Removed unnecessary setting dependent issue in comment creation
kolaente Jun 8, 2018
ec9797d
Fixed issue dependency comments not showing
kolaente Jun 8, 2018
0879a36
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Jun 8, 2018
425e765
fixed lint + fmt
kolaente Jun 8, 2018
6514da4
Merge branch 'master' into master
kolaente Jun 11, 2018
12602c2
Merge branch 'master' into master
kolaente Jun 13, 2018
c760e6a
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Jun 17, 2018
393013a
Changed delete endpoint to /delete
kolaente Jun 17, 2018
2d95ab1
Added missing return
kolaente Jun 17, 2018
10308a0
removed unused DependentIssue element
kolaente Jun 17, 2018
d89a136
pre-commit
kolaente Jun 19, 2018
8a6ba47
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Jun 19, 2018
f01fdf6
fmt
kolaente Jun 20, 2018
e00e5dd
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Jun 20, 2018
cf6d426
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Jul 6, 2018
49c471f
Merge branch 'master' of https://github.com/go-gitea/gitea
kolaente Jul 6, 2018
a283309
Moved redirect to defer
kolaente Jul 6, 2018
b6e428d
Merge branch 'master' of github.com:go-gitea/gitea
kolaente Jul 15, 2018
c3a6210
Merge branch 'master' of github.com:go-gitea/gitea
kolaente Jul 16, 2018
b8aa1d8
Merge branch 'master' of github.com:go-gitea/gitea
kolaente Jul 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,11 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit) err
continue
}

if err = issue.ChangeStatus(doer, repo, true); err != nil {
return err
// Check for dependencies, if there aren't any, close it
if IssueNoDependenciesLeft(issue) {
if err = issue.ChangeStatus(doer, repo, true); err != nil {
return err
}
}
Copy link
Member

@lunny lunny Jan 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to add a else here to notify the UI to say it cannot be closed since it has some dependencies not closed. @kolaente @bkcsoft

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it shows an error message if it cannot be closed because there are open dependencies 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like so
bildschirmfoto vom 2018-01-01 14-38-04

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kolaente Yes, I thinks that's expected? Shouldn't that?

}

Expand Down
130 changes: 91 additions & 39 deletions models/issue_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const (
CommentTypeAddTimeManual
// Cancel a stopwatch for time tracking
CommentTypeCancelTracking
// Dependency added
CommentTypeAddDependency
//Dependency removed
CommentTypeRemoveDependency
)

// CommentTag defines comment tag type
Expand All @@ -75,23 +79,25 @@ const (

// Comment represents a comment in commit and issue page.
type Comment struct {
ID int64 `xorm:"pk autoincr"`
Type CommentType
PosterID int64 `xorm:"INDEX"`
Poster *User `xorm:"-"`
IssueID int64 `xorm:"INDEX"`
LabelID int64
Label *Label `xorm:"-"`
OldMilestoneID int64
MilestoneID int64
OldMilestone *Milestone `xorm:"-"`
Milestone *Milestone `xorm:"-"`
OldAssigneeID int64
AssigneeID int64
Assignee *User `xorm:"-"`
OldAssignee *User `xorm:"-"`
OldTitle string
NewTitle string
ID int64 `xorm:"pk autoincr"`
Type CommentType
PosterID int64 `xorm:"INDEX"`
Poster *User `xorm:"-"`
IssueID int64 `xorm:"INDEX"`
LabelID int64
Label *Label `xorm:"-"`
OldMilestoneID int64
MilestoneID int64
OldMilestone *Milestone `xorm:"-"`
Milestone *Milestone `xorm:"-"`
OldAssigneeID int64
AssigneeID int64
Assignee *User `xorm:"-"`
OldAssignee *User `xorm:"-"`
OldTitle string
NewTitle string
DependentIssueID int64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes i do?

Copy link
Member

@Morlinest Morlinest Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is 2 places with DependentIssueID. One is definition of Comment struct and second is when you set it to new comment variable...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Thats why i need it.

Copy link
Member Author

@kolaente kolaente Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that i was wrong with removing LoadDepIssueDetails(), which is why I reimplemented it in 752406c.

I use this to get the Dependent issue details displayed in the comments. But to know which issue i need to get informations about, I also need the ID of the Dependent Issue. And that's where DependentIssueID comes in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've probably started the featue and then forget about it, which is why there was this function (and the corresponding DependentIssue in the Comment struct). But i think this is the "cleander" solution instead of saving the titel of the dependent issue with the comment. The new way ensures also the Issues' title will always be the right one, even if it was changed after the comment was saved.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means you can only have 1 dependency right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One per comment. (You can ofc have more than dependency per issue)

The ID here is used to get issue details (title, index) later when displaying the comment to be able to link to it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does Comments track dependencies? 😕

Copy link
Member Author

@kolaente kolaente Nov 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They don't, the ID is only used to display informations in a comment (title, index, link) when someone adds or removes a dependency.

DependentIssue *Issue `xorm:"-"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To load issue Dependency Details in issue_comment.go:278

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But usage of it? I don't see reason to have this field. You never use it. You only set it and save to db, but never read. Or did I overlooked something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used in LoadDepIssueDetails()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, loaded, but for what? Where you use it? You load it to comment.DependentIssue and where are you using that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, see my latest comment...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kolaente yes, that added html is the reason I was looking for. I looked at it yesterday and have some suggestions for it too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what suggestions?


CommitID int64
Line int64
Expand Down Expand Up @@ -269,6 +275,18 @@ func (c *Comment) LoadAssignees() error {
return nil
}

// LoadDepIssueDetails loads Dependent Issue Details
func (c *Comment) LoadDepIssueDetails() error {
var err error
if c.DependentIssueID > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&& c.DependentIssue == nil

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

c.DependentIssue, err = getIssueByID(x, c.DependentIssueID)
if err != nil {
return err
}
}
return nil
}

// MailParticipants sends new comment emails to repository watchers
// and mentioned people.
func (c *Comment) MailParticipants(e Engine, opType ActionType, issue *Issue) (err error) {
Expand Down Expand Up @@ -297,24 +315,40 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
if opts.Label != nil {
LabelID = opts.Label.ID
}

var depID int64
if opts.DependentIssue != nil {
depID = opts.DependentIssue.ID
}

comment := &Comment{
Type: opts.Type,
PosterID: opts.Doer.ID,
Poster: opts.Doer,
IssueID: opts.Issue.ID,
LabelID: LabelID,
OldMilestoneID: opts.OldMilestoneID,
MilestoneID: opts.MilestoneID,
OldAssigneeID: opts.OldAssigneeID,
AssigneeID: opts.AssigneeID,
CommitID: opts.CommitID,
CommitSHA: opts.CommitSHA,
Line: opts.LineNum,
Content: opts.Content,
OldTitle: opts.OldTitle,
NewTitle: opts.NewTitle,
}
if _, err = e.Insert(comment); err != nil {
Type: opts.Type,
PosterID: opts.Doer.ID,
Poster: opts.Doer,
IssueID: opts.Issue.ID,
LabelID: LabelID,
OldMilestoneID: opts.OldMilestoneID,
MilestoneID: opts.MilestoneID,
OldAssigneeID: opts.OldAssigneeID,
AssigneeID: opts.AssigneeID,
CommitID: opts.CommitID,
CommitSHA: opts.CommitSHA,
Line: opts.LineNum,
Content: opts.Content,
OldTitle: opts.OldTitle,
NewTitle: opts.NewTitle,
DependentIssue: opts.DependentIssue,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to set DependentIssue here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you're right, Removed it.

DependentIssueID: depID,
}

//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
}

Expand Down Expand Up @@ -486,13 +520,31 @@ func createDeleteBranchComment(e *xorm.Session, doer *User, repo *Repository, is
})
}

// Creates issue dependency comment
func createIssueDependencyComment(e *xorm.Session, doer *User, issue *Issue, dependentIssue *Issue, add bool) (*Comment, error) {
cType := CommentTypeAddDependency
if !add {
cType = CommentTypeRemoveDependency
}

return createComment(e, &CreateCommentOptions{
Type: cType,
Doer: doer,
Repo: issue.Repo,
Issue: issue,
DependentIssue: dependentIssue,
Content: dependentIssue.Title,
})
}

// CreateCommentOptions defines options for creating comment
type CreateCommentOptions struct {
Type CommentType
Doer *User
Repo *Repository
Issue *Issue
Label *Label
Type CommentType
Doer *User
Repo *Repository
Issue *Issue
Label *Label
DependentIssue *Issue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not dependent issue ID enough?

Copy link
Member Author

@kolaente kolaente Jun 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need that to display informations about the dependent issue when showing the comments.

I think it doesn't really make a difference, as it is a pointer...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO you should always use minimum and be exact of what you need. You know, that only DependentIssue.ID will be used here, but not everyone will read the code to learn what it rly needs (and should not).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've changed that. When I first started this pr, I used only the IDs everywhere, but I was told to use structs instead, which is why I used that here.


OldMilestoneID int64
MilestoneID int64
Expand Down
159 changes: 159 additions & 0 deletions models/issue_dependency.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
// 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 models

import (
"time"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import order

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIxed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kolaente still a missing one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github didn't got it...
But you can see the change when directly viewing it in my repository: https://github.com/kolaente/gitea/blob/master/models/issue_dependency.go

)

// IssueDependency is connection request for receiving issue notification.
type IssueDependency struct {
ID int64 `xorm:"pk autoincr"`
UserID int64 `xorm:"UNIQUE(watch) NOT NULL"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unnecessary. issue notifications are tracked elsewhere, use a JOIN if necessary

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, you're right, it probably is there because I copied it in the beginning 😀 , my fault...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it.

IssueID int64 `xorm:"UNIQUE(watch) NOT NULL"`
DependencyID int64 `xorm:"UNIQUE(watch) NOT NULL"`
Created time.Time `xorm:"-"`
CreatedUnix int64 `xorm:"INDEX created"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INDEX is optional, don't know if you need it or just used code from previous review.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've just used it, think it works.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use util.TimeStamp instead of int64 and time.Time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can find many example on other object.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, maybe you didn't push success? I cannot find the change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did push however github didn't got it...
But you can see the change when directly viewing it in my repository: https://github.com/kolaente/gitea/blob/master/models/issue_dependency.go

Updated time.Time `xorm:"-"`
UpdatedUnix int64 `xorm:"updated"`
}

// DependencyType Defines Dependency Type Constants
type DependencyType int

// Define Dependency Types
const (
DependencyTypeBlockedBy DependencyType = iota
DependencyTypeBlocking
)

// CreateIssueDependency creates a new dependency for an issue
func CreateIssueDependency(user *User, issue, dep *Issue) (exists bool, err error) {
sess := x.NewSession()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer sess.Close()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And you have to

if err := sess.Begin(); err != nil {
return err
}


// Check if it aleready exists
exists, err = issueDepExists(x, issue.ID, dep.ID)
if err != nil {
return exists, err
}

// If it not exists, create it, otherwise show an error message
if !exists {
newIssueDependency := &IssueDependency{
UserID: user.ID,
IssueID: issue.ID,
DependencyID: dep.ID,
}

if _, err := x.Insert(newIssueDependency); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x -> sess

return exists, err
}

// Add comment referencing the new dependency
_, err = createIssueDependencyComment(sess, user, issue, dep, true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace this and the if err != nil below with this:

if _, err = createIssueDependencyComment(sess, user, issue, dep, true); err != nil {
 	return exists, err
}


if err != nil {
return exists, err
}

// Create a new comment for the dependent issue
_, err = createIssueDependencyComment(sess, user, dep, issue, true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above


if err != nil {
return exists, err
}
}
return exists, nil
}

// RemoveIssueDependency removes a dependency from an issue
func RemoveIssueDependency(user *User, issue *Issue, dep *Issue, depType DependencyType) (err error) {
sess := x.NewSession()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer sess.Close()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need sess.Begin()


// Check if it exists
exists, err := issueDepExists(x, issue.ID, dep.ID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do check where you switch issue for dep, but later you are deleting in given order. What it should do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It checks if the dependency already exists as you send it to the backend, but it also checks the other way around to prevent to issues blocking each other. This would result in none of them could be closed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace this with:

var exists bool
if exists, err := issueDepExists(x, issue.ID, dep.ID); err != nil {
	return err
}

if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the fact, that issueDepExists returns type of error as true/false. Anyway (if you dont change it):

	if err == nil || !IsErrDependencyExists(err) {
		return err
	}

And you don't need exists variable at all.

Copy link
Member Author

@kolaente kolaente Apr 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems logic, thanks!

Took me some time to understand, a really good solution. :)

return err
}

// If it exists, remove it, otherwise show an error message
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems to be out-of-date; I don't see an error message anywhere

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I've changed it.

if exists {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if !exists {
  return sess.Commit()
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain that? I don't understand why this would be necessary, because I still need to do all of that stuff when the dependency exists. Sure, I could add the piece of code you described, but I still need sess.Commit() after all the stuff which happens inside of that if (starting in line 97), which would mean to add another sess.Commit() after that (L 97).

IMHO the way I did it is ok, please tell me if I misunderstood you.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's about unnecessary nested code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how is it unnecessary nested? 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'll try to explain with "my" English) You should follow the "break early" rule and also keep standard/expected flow without indentation (not nested). Function name is RemoveIssueDependency so the expecting behaviour is to remove dependency. Missing issue is exception, not common flow/scenario.

If you know, you will not do anything else in some condition you should immidiately end processing. What if there will be more exceptions in future? Then you will have to create another nested block inside (and still not talking aboud returning different exceptions)...

func shouldYouDoIt() {
    if !ex1 {
        if !ex2 {
           if !ex3 {
               doIt()
           }
        }
    }
}

# vs

func shouldYouDoIt() {
    if ex1 {
        return
    }

    if ex2 {
        return
    }

    if ex3 {
        return
    }

    doIt()
}

Another thing is, who will know later why that block is inside "if" and if he/she should add another code after it (between end of block and commit) or inside that block?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I know about that priciple, but this would mean having two times return sess.Commit():

if !exists {
  return sess.Commit()
}

// Actual code which is currently inside of if exists {}
// ...

return sess.Commit()

I like the way I did it more, that way we have one unnecessary return sess.Commit() less. Or should I still do it the way you pointed out as "break early" is more important in that case than unnecessary doubled code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to have maybe more verbose but clear code. Also question is, if you rly need to commit something instead of returning error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think I finally understood how it works. Thanks for taking the time to explain :)

I've fixed it. I also saw that we don't need to return sess.Commit() in any case, fixed that as well.


var issueDepToDelete IssueDependency

switch depType {
case DependencyTypeBlockedBy:
issueDepToDelete = IssueDependency{IssueID: issue.ID, DependencyID: dep.ID}
case DependencyTypeBlocking:
issueDepToDelete = IssueDependency{IssueID: dep.ID, DependencyID: issue.ID}
default:
return
}

_, err := x.Delete(&issueDepToDelete)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please minimize this like shown above

if err != nil {
return err
}

// Add comment referencing the removed dependency
_, err = createIssueDependencyComment(sess, user, issue, dep, false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please minimize this like shown above


if err != nil {
return err
}

// Create a new comment for the dependent issue
_, err = createIssueDependencyComment(sess, user, dep, issue, false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please minimize this like shown above


if err != nil {
return err
}
}
return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return sess.Commit()

}

// Check if the dependency already exists
func issueDepExists(e Engine, issueID int64, depID int64) (exists bool, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like names issueID and depID because you are switching their meaning inside function.

Copy link
Member Author

@kolaente kolaente Sep 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First issueID means issueID and second time issueID means depID. I think both arguments are equivalent because you are trying to find dependency between them not matter which way. Variable names should reflect this fact (eg. issue1ID, issue2ID int64).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I try to find all dependencies, no matter of direction.
But: issueID is the issue we're currently on, depID is the other issue we want to look for. I think it would be more confunsing to rename the variables to issue1ID etc. I would prefer keeping it the way it is.

To be more clear, an example:
When I'm on issue #1 and want to add a new dependency of #2 i send a request to the backend saying something like "Hi, I'm issue #1 and want to add #2 as my dependent issue.". The dependend issue (#2) becomes depID, the issue we're on becomes isuueID.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok with that as long as issueDepExists stays unexported and is used only for your mentioned scenario.

I was thinking about it in more general way. Like using this function for checking (from any place of code) any dependency between two issues.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, cool.

I think to be more general, it would need to return a struct with both issues, but i dont see a usecase for this (yet).


deps := new(IssueDependency)
exists, err = e.Where("(issue_id = ? AND dependency_id = ?) OR (issue_id = ? AND dependency_id = ?)", issueID, depID, depID, issueID).Get(deps)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exist(&IssueDependency{}) instead of Get

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this if clause

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right.

return exists, err
}

return exists, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could simply replace this with return since you use named returns at line 118.

}

// IssueDependencyIssue custom type for mysql join
type IssueDependencyIssue struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you don't need this at all. Everything you need is in IssueDependency table.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, i need it to check if there aren't any dependencies left. To do this, i join IssueDependency with Issue in order to check for Issue.IsClosed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is completely unnecessary since you're already tracking parent<->child in IssueDependecy struct

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But i need this to join issue dependencies with issues to check if there are any open dependent issues, the info if the issue is open or closed is saved with the issue, not the dependency.

I have an issue with dependencies. To know if any of these dependent issues is still open, I need to join issue_dependencies (relation issue->dependent_issue) with issue (informations about the issue, we want to know if it is still open). And to this, I need this struct (or is there a better way to join two tables via xorm?).
See the function IssueNoDependenciesLeft later in that file.

Or am I completly wrong?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need a join table? xorm has support for doing JOINs while only working on a single table 🤔

/cc @lunny

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something I did in another project a while back:

contribs := make([]*Contribution, 0, pageSize)
engine.Table("contribution").
  Select("contribution.*, compo.*").
  Join("INNER", "compo", "compo.id = contribution.compo_id").
  Where("contribution.name=?", name).
  Limit(pageSize, (page-1)*pageSize).
  Find(&contribs)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oookay, i didn't know that, I put it just like on xorm's official documentation: http://gobook.io/read/github.com/go-xorm/manual-en-US/chapter-05/5.join.html

But the thing you have does indeed look a lot cleaner, I will change it to something like this. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

IssueDependency `xorm:"extends"`
Issue `xorm:"extends"`
}

// TableName returns table name for mysql join
func (IssueDependencyIssue) TableName() string {
return "issue_dependency"
}

// IssueNoDependenciesLeft checks if issue can be closed
func IssueNoDependenciesLeft(issue *Issue) bool {

var issueDeps []IssueDependencyIssue

err := x.Join("INNER", "issue", "issue.id = issue_dependency.issue_id").Where("issue_id = ?", issue.ID).Find(&issueDeps)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do simple check if there is record in IssueDependency with appropriate where condition.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But i need all informations of the issue, thats why I made the join.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are just returning true or false, you don't need any information here. Only if record exists. Am I right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, i need to know if Issue.IsClosed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add it to where condition as you need it only to decide if you return true or false (#2531 (review)).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i see how you mean this...

Isn't this basically the same what you said in your newer review? (the one you linked to)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's same (that's why I linked it).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done.


if err != nil {
return false
}

for _, issueDep := range issueDeps {
if !issueDep.IsClosed {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can include this in where condition.

return false
}
}

return true
}
2 changes: 2 additions & 0 deletions models/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ var migrations = []Migration{
NewMigration("add tags to releases and sync existing repositories", releaseAddColumnIsTagAndSyncTags),
// v43 -> v44
NewMigration("fix protected branch can push value to false", fixProtectedBranchCanPushValue),
// v44 -> v45
NewMigration("add issue_dependency table", addIssueDependencyTables),
}

// Migrate database to current version
Expand Down
24 changes: 24 additions & 0 deletions models/migrations/v44.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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 migrations

import (
"fmt"

"code.gitea.io/gitea/models"

"github.com/go-xorm/xorm"
)

func addIssueDependencyTables(x *xorm.Engine) (err error) {

err = x.Sync(new(models.IssueDependency))

if err != nil {
return fmt.Errorf("Error creating issue_dependency_table column definition: %v", err)
}

return err
}
Loading