mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-03 00:45:22 +02:00
Refactor: move Commit To APIFormat Code & Lot of StopWatch related things (#12729)
* move GitCommit to APIFormat convertion into convert package * rename Commit convert functions * move stopwatch to api convertion into convert package & rm unused code & extend test * fix compare time * Gitea not Gogs ;)
This commit is contained in:
parent
5995326d51
commit
1418288734
8 changed files with 230 additions and 228 deletions
|
@ -115,6 +115,46 @@ func ToTrackedTime(t *models.TrackedTime) (apiT *api.TrackedTime) {
|
|||
return
|
||||
}
|
||||
|
||||
// ToStopWatches convert Stopwatch list to api.StopWatches
|
||||
func ToStopWatches(sws []*models.Stopwatch) (api.StopWatches, error) {
|
||||
result := api.StopWatches(make([]api.StopWatch, 0, len(sws)))
|
||||
|
||||
issueCache := make(map[int64]*models.Issue)
|
||||
repoCache := make(map[int64]*models.Repository)
|
||||
var (
|
||||
issue *models.Issue
|
||||
repo *models.Repository
|
||||
ok bool
|
||||
err error
|
||||
)
|
||||
|
||||
for _, sw := range sws {
|
||||
issue, ok = issueCache[sw.IssueID]
|
||||
if !ok {
|
||||
issue, err = models.GetIssueByID(sw.IssueID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
repo, ok = repoCache[issue.RepoID]
|
||||
if !ok {
|
||||
repo, err = models.GetRepositoryByID(issue.RepoID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
result = append(result, api.StopWatch{
|
||||
Created: sw.CreatedUnix.AsTime(),
|
||||
IssueIndex: issue.Index,
|
||||
IssueTitle: issue.Title,
|
||||
RepoOwnerName: repo.OwnerName,
|
||||
RepoName: repo.Name,
|
||||
})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ToTrackedTimeList converts TrackedTimeList to API format
|
||||
func ToTrackedTimeList(tl models.TrackedTimeList) api.TrackedTimeList {
|
||||
result := make([]*api.TrackedTime, 0, len(tl))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue