-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[API] Extend times API #9200
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
Merged
Merged
[API] Extend times API #9200
Changes from 107 commits
Commits
Show all changes
114 commits
Select commit
Hold shift + click to select a range
15cba15
git ignore fuse tmp files
6543 81e5ea6
Deprecate old "times" API
6543 e14d62b
add new times api struct
6543 7946829
update "GET /user/times"
6543 d8c0c4e
update "GET /repos/{owner}/{repo}/times"
6543 7601790
corect swagger description (id -> index)
6543 7e5b5b0
update time POST
6543 c06805d
add reset func
6543 261222d
AddTimeOption -> EditTimeOption
6543 e5ece6b
make delete work + forbidden to remove more time on issue than you have
6543 88c6147
return full issue instead of issue_index
6543 a64cc39
dont Deprecate TimesByUser
6543 9d71a37
new Delete func & optimize
6543 b6239c0
add Created to EditTimeOption
6543 5bb0b2c
add CommentTypeDeleteTimeManual
6543 8dfcd5e
use CommentTypeDeleteTimeManual
6543 9dda7db
add DELETE .../times/{id} endpoint
6543 855002d
cleanup & co
6543 979a13c
do ToDo
6543 e0facee
allow RepoAdmin, Admin and User to add tracked time for User
6543 8720395
Merge branch 'master' into api-times-refactor
6543 754b813
fix lint
6543 3892d0b
Merge branch 'master' into api-times-refactor
6543 ffa9ea3
fix thing after merge
6543 cd77248
correct comments
6543 4a37fb8
code format
6543 aa4162e
TEST related things
6543 140946a
add TestAPIGetTrackedTimes
6543 7ca2a6a
Merge branch 'master' into api-times-refactor
6543 59f8a0e
DELETE send 204 on succes
6543 c4b20ef
extend unit test + fixtures
6543 6726e3c
extend unit test + fixtures
6543 3fa89a5
add TESTs for addition and deletion
6543 fbfbf73
fix TEST: time compare with Unix()
6543 e83f743
fix TestAPIDeleteTrackedTime
6543 4a597db
check if tracked time exist on issue befor reset & more
6543 76eb17e
deactivate test for DEL specific TrackedTime:
6543 16cef4a
Merge branch 'master' into api-times-refactor
6543 64f6a10
Print PASS for "test" like "test-sqlite" does
6543 18d65bf
Merge branch 'master' into api-times-refactor
6543 16b5689
Merge branch 'master' into api-times-refactor
6543 68474d1
Revert "git ignore fuse tmp files"
6543 33030cc
add comment (only for backwards compatibility)
6543 e1b9a4f
Merge branch 'master' into api-times-refactor
6543 81d039e
swagger got it
6543 6a62537
add suggestions @lunny
6543 0f666cb
Merge branch 'master' into api-times-refactor
6543 a8bf5c7
Merge branch 'master' into api-times-refactor
6543 f9b4114
Merge branch 'master' into api-times-refactor
6543 cf9b9d4
Merge branch 'master' into api-times-refactor
6543 f187d02
Merge branch 'master' into api-times-refactor
6543 f0008d7
Merge branch 'master' into api-times-refactor
6543 627f9a8
Merge branch 'master' into api-times-refactor
6543 220879e
Merge branch 'master' into api-times-refactor
6543 de4e79d
Merge branch 'master' into api-times-refactor
6543 898f515
Merge branch 'master' into api-times-refactor
6543 a6d1176
Merge branch 'master' into api-times-refactor
6543 df56c56
add suggestion
6543 c805fff
Merge branch 'master' into api-times-refactor
6543 f2c6efe
use Engine opt for deleteTimes to make it reusable
6543 e7daebf
Merge branch 'master' into api-times-refactor
6543 dc626b6
format code
6543 59ac977
handle error
6543 21b7754
Merge branch 'master' into api-times-refactor
6543 0771fff
Merge branch 'master' into api-times-refactor
6543 2153fbe
Merge branch 'master' into api-times-refactor
6543 8a0d8a0
spell corect
6543 46ab8e9
only one AddTime()
6543 318e238
add attribues
6543 25474e7
add functions for a single session
6543 9661f85
use same session
6543 8a541b1
spell corect
6543 398707c
Merge branch 'master' into api-times-refactor
6543 4562fcf
dont delete times - mark as deleted
6543 b540212
old functions ignor deleted
6543 cfd79fb
make sure no nil pointer exeption
6543 a02d80f
handle deleted flag correct
6543 18f5aa6
fmt
6543 6145a0f
bool false is 0
6543 71677da
use xorm builder to support all DBs
6543 1a93cb4
Merge branch 'master' into api-times-refactor
6543 5d707d8
dont forget sess.Begin()
6543 887df7d
Merge branch 'master' into api-times-refactor
6543 ed57d8e
use createComment
6543 fb192bf
more specific
6543 c409f9e
Merge branch 'master' into api-times-refactor
6543 9a0517c
Update models/issue_tracked_time.go
6543 c0244ab
code format
6543 8f1dc9a
Merge branch 'master' into api-times-refactor
6543 bca58d4
move to right place
6543 cbe5075
Merge branch 'master' into api-times-refactor
6543 92186f2
Merge branch 'master' into api-times-refactor
6543 43dbc59
Merge branch 'master' into api-times-refactor
6543 60ab62c
Apply suggestions from code review
6543 69f2fa5
Update models/issue_list.go
6543 2b38708
Merge branch 'master' into api-times-refactor
6543 7f2876a
optimize deleteTimes()
6543 34a90d8
not working jet
6543 f6d8e6d
make it work
6543 ed1f495
update gitignore after code refactor
6543 d6c35bb
workaround by @zeripath
6543 16b5ca6
add Comment to do this better in future
6543 8f137db
revert "add PASS to -make test-"
6543 050ae6f
working solution ... for now
6543 7f9d174
Merge branch 'master' into api-times-refactor
6543 1b14ac9
revert suggestion
6543 f07a761
give it a try
6543 0366115
Merge branch 'master' into api-times-refactor
lunny a12aac9
Merge branch 'master' into api-times-refactor
zeripath 4438401
Merge branch 'master' into api-times-refactor
6543 0419d99
Apply suggestions from code review
6543 c4bc46e
prepare for conflict resolve
6543 753b1fc
Merge branch 'master' into api-times-refactor
6543 36cc104
Merge branch 'master' into api-times-refactor
zeripath 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
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,109 @@ | ||
// Copyright 2019 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 integrations | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
"code.gitea.io/gitea/models" | ||
api "code.gitea.io/gitea/modules/structs" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAPIGetTrackedTimes(t *testing.T) { | ||
defer prepareTestEnv(t)() | ||
|
||
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) | ||
issue2 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue) | ||
assert.NoError(t, issue2.LoadRepo()) | ||
|
||
session := loginUser(t, user2.Name) | ||
token := getTokenForLoggedInUser(t, session) | ||
|
||
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/times?token=%s", user2.Name, issue2.Repo.Name, issue2.Index, token) | ||
resp := session.MakeRequest(t, req, http.StatusOK) | ||
var apiTimes api.TrackedTimeList | ||
DecodeJSON(t, resp, &apiTimes) | ||
expect, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{IssueID: issue2.ID}) | ||
assert.NoError(t, err) | ||
assert.Len(t, apiTimes, 3) | ||
|
||
for i, time := range expect { | ||
assert.Equal(t, time.ID, apiTimes[i].ID) | ||
assert.EqualValues(t, issue2.Title, apiTimes[i].Issue.Title) | ||
assert.EqualValues(t, issue2.ID, apiTimes[i].IssueID) | ||
assert.Equal(t, time.Created.Unix(), apiTimes[i].Created.Unix()) | ||
assert.Equal(t, time.Time, apiTimes[i].Time) | ||
user, err := models.GetUserByID(time.UserID) | ||
assert.NoError(t, err) | ||
assert.Equal(t, user.Name, apiTimes[i].UserName) | ||
} | ||
} | ||
|
||
func TestAPIDeleteTrackedTime(t *testing.T) { | ||
defer prepareTestEnv(t)() | ||
|
||
time6 := models.AssertExistsAndLoadBean(t, &models.TrackedTime{ID: 6}).(*models.TrackedTime) | ||
issue2 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue) | ||
assert.NoError(t, issue2.LoadRepo()) | ||
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) | ||
|
||
session := loginUser(t, user2.Name) | ||
token := getTokenForLoggedInUser(t, session) | ||
|
||
//Deletion not allowed | ||
req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/%d/times/%d?token=%s", user2.Name, issue2.Repo.Name, issue2.Index, time6.ID, token) | ||
session.MakeRequest(t, req, http.StatusForbidden) | ||
/* Delete own time <-- ToDo: timout without reason | ||
time3 := models.AssertExistsAndLoadBean(t, &models.TrackedTime{ID: 3}).(*models.TrackedTime) | ||
req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/%d/times/%d?token=%s", user2.Name, issue2.Repo.Name, issue2.Index, time3.ID, token) | ||
session.MakeRequest(t, req, http.StatusNoContent) | ||
//Delete non existing time | ||
session.MakeRequest(t, req, http.StatusInternalServerError) */ | ||
|
||
//Reset time of user 2 on issue 2 | ||
trackedSeconds, err := models.GetTrackedSeconds(models.FindTrackedTimesOptions{IssueID: 2, UserID: 2}) | ||
assert.NoError(t, err) | ||
assert.Equal(t, int64(3662), trackedSeconds) | ||
|
||
req = NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/%d/times?token=%s", user2.Name, issue2.Repo.Name, issue2.Index, token) | ||
session.MakeRequest(t, req, http.StatusNoContent) | ||
session.MakeRequest(t, req, http.StatusNotFound) | ||
|
||
trackedSeconds, err = models.GetTrackedSeconds(models.FindTrackedTimesOptions{IssueID: 2, UserID: 2}) | ||
assert.NoError(t, err) | ||
assert.Equal(t, int64(0), trackedSeconds) | ||
} | ||
|
||
func TestAPIAddTrackedTimes(t *testing.T) { | ||
defer prepareTestEnv(t)() | ||
|
||
issue2 := models.AssertExistsAndLoadBean(t, &models.Issue{ID: 2}).(*models.Issue) | ||
assert.NoError(t, issue2.LoadRepo()) | ||
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) | ||
admin := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User) | ||
|
||
session := loginUser(t, admin.Name) | ||
token := getTokenForLoggedInUser(t, session) | ||
|
||
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/times?token=%s", user2.Name, issue2.Repo.Name, issue2.Index, token) | ||
|
||
req := NewRequestWithJSON(t, "POST", urlStr, &api.AddTimeOption{ | ||
Time: 33, | ||
User: user2.Name, | ||
Created: time.Unix(947688818, 0), | ||
}) | ||
resp := session.MakeRequest(t, req, http.StatusOK) | ||
var apiNewTime api.TrackedTime | ||
DecodeJSON(t, resp, &apiNewTime) | ||
|
||
assert.EqualValues(t, 33, apiNewTime.Time) | ||
assert.EqualValues(t, user2.ID, apiNewTime.UserID) | ||
assert.EqualValues(t, 947688818, apiNewTime.Created.Unix()) | ||
} |
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
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.