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

Show total TrackedTime on issue/pull/milestone lists #26672

Merged
merged 44 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
377d160
Show total TrackedTime in issue list and milestone issue list [partia…
6543 Jun 6, 2023
056ea96
rm diff thats to be in next pull
6543 Aug 22, 2023
7e7a2c5
adjust to renamed opt
6543 Aug 22, 2023
b96699e
Add GetIssueTotalTrackedTime, witch returns the total tracked time fo…
6543 Aug 22, 2023
a14d804
adjust to current codebase
6543 Aug 22, 2023
b9db680
adjust code-scope [see with no whitespace changes]
6543 Aug 22, 2023
ecccc50
add TotalTrackedTime Data for template
6543 Aug 22, 2023
2f4728d
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Aug 23, 2023
e2349bc
Update routers/web/repo/issue.go
6543 Aug 23, 2023
c50d2f1
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Aug 30, 2023
b18c837
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Sep 25, 2023
e9766f1
fix
6543 Sep 25, 2023
b3e9420
comment
6543 Sep 25, 2023
26c34c7
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Sep 30, 2023
cbf2965
WIP: WebUI
6543 Sep 30, 2023
bffb2b2
TTT in MS looks good now ;)
6543 Sep 30, 2023
4706f89
WIP: TTT on issue list
6543 Sep 30, 2023
f80779d
try vertical align ?!?
6543 Sep 30, 2023
0463116
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Sep 30, 2023
b110d85
TTT in issue list looks good now ;)
6543 Sep 30, 2023
4cd950c
fix lint & wip test
6543 Sep 30, 2023
aa562fc
context
6543 Oct 1, 2023
db387c0
fix and extend tests
6543 Oct 1, 2023
ae166a0
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 1, 2023
ecb01c2
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 1, 2023
969bb41
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 2, 2023
fc27f22
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 2, 2023
3a1dab8
Update options/locale/locale_en-US.ini
6543 Oct 3, 2023
bc900f4
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 3, 2023
f1b4128
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 4, 2023
d4ffd1b
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 7, 2023
10d18bd
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 8, 2023
5385025
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 9, 2023
a82da3a
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 12, 2023
2d55b1a
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 13, 2023
04594bc
only exec if tt in repo is enabled
6543 Oct 13, 2023
beb3b64
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 14, 2023
3b1b7a0
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 15, 2023
697c4a1
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 15, 2023
d102bd8
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 16, 2023
b809a91
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 17, 2023
77e3d4e
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
silverwind Oct 17, 2023
d7f0392
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 19, 2023
d0bedae
Merge branch 'main' into upstream_trackedTimeSummaryOnIssueList
6543 Oct 19, 2023
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
46 changes: 46 additions & 0 deletions models/issues/tracked_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/modules/util"

"xorm.io/builder"
"xorm.io/xorm"
)

// TrackedTime represents a time that was spent for a specific issue.
Expand Down Expand Up @@ -325,3 +326,48 @@ func GetTrackedTimeByID(id int64) (*TrackedTime, error) {
}
return time, nil
}

// GetIssueTotalTrackedTime returns the total tracked time for issues by given conditions.
func GetIssueTotalTrackedTime(opts *IssuesOptions, isClosed bool) (int64, error) {
if len(opts.IssueIDs) <= MaxQueryParameters {
return getIssueTotalTrackedTimeChunk(opts, isClosed, opts.IssueIDs)
}

// If too long a list of IDs is provided, we get the statistics in
// smaller chunks and get accumulates. Note: this could potentially
// get us invalid results. The alternative is to insert the list of
// ids in a temporary table and join from them.
var accum int64 = 0
for i := 0; i < len(opts.IssueIDs); {
chunk := i + MaxQueryParameters
if chunk > len(opts.IssueIDs) {
chunk = len(opts.IssueIDs)
}
time, err := getIssueTotalTrackedTimeChunk(opts, isClosed, opts.IssueIDs[i:chunk])
if err != nil {
return 0, err
}
accum += time
i = chunk
}
return accum, nil
}

func getIssueTotalTrackedTimeChunk(opts *IssuesOptions, isClosed bool, issueIDs []int64) (int64, error) {
sumSession := func(opts *IssuesOptions, issueIDs []int64) *xorm.Session {
sess := db.GetEngine(db.DefaultContext).
Table("tracked_time").
Where("tracked_time.deleted = ?", false).
Join("INNER", "issue", "tracked_time.issue_id = issue.id")

return applyIssuesOptions(sess, opts, issueIDs)
}

type trackedTime struct {
Time int64
}

return sumSession(opts, issueIDs).
And("issue.is_closed = ?", isClosed).
SumInt(new(trackedTime), "tracked_time.time")
}
77 changes: 41 additions & 36 deletions routers/web/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,46 +197,43 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
}

var issueStats *issues_model.IssueStats
{
statsOpts := &issues_model.IssuesOptions{
RepoIDs: []int64{repo.ID},
LabelIDs: labelIDs,
MilestoneIDs: mileIDs,
ProjectID: projectID,
AssigneeID: assigneeID,
MentionedID: mentionedID,
PosterID: posterID,
ReviewRequestedID: reviewRequestedID,
ReviewedID: reviewedID,
IsPull: isPullOption,
IssueIDs: nil,
}
if keyword != "" {
allIssueIDs, err := issueIDsFromSearch(ctx, keyword, statsOpts)
if err != nil {
if issue_indexer.IsAvailable(ctx) {
ctx.ServerError("issueIDsFromSearch", err)
return
}
ctx.Data["IssueIndexerUnavailable"] = true
statsOpts := &issues_model.IssuesOptions{
RepoIDs: []int64{repo.ID},
LabelIDs: labelIDs,
MilestoneIDs: mileIDs,
ProjectID: projectID,
AssigneeID: assigneeID,
MentionedID: mentionedID,
PosterID: posterID,
ReviewRequestedID: reviewRequestedID,
ReviewedID: reviewedID,
IsPull: isPullOption,
IssueIDs: nil,
}
if keyword != "" {
allIssueIDs, err := issueIDsFromSearch(ctx, keyword, statsOpts)
if err != nil {
if issue_indexer.IsAvailable(ctx) {
ctx.ServerError("issueIDsFromSearch", err)
return
}
statsOpts.IssueIDs = allIssueIDs
ctx.Data["IssueIndexerUnavailable"] = true
return
}
if keyword != "" && len(statsOpts.IssueIDs) == 0 {
// So it did search with the keyword, but no issue found.
// Just set issueStats to empty.
issueStats = &issues_model.IssueStats{}
} else {
// So it did search with the keyword, and found some issues. It needs to get issueStats of these issues.
// Or the keyword is empty, so it doesn't need issueIDs as filter, just get issueStats with statsOpts.
issueStats, err = issues_model.GetIssueStats(statsOpts)
if err != nil {
ctx.ServerError("GetIssueStats", err)
return
}
statsOpts.IssueIDs = allIssueIDs
}
if keyword != "" && len(statsOpts.IssueIDs) == 0 {
// So it did search with the keyword, but no issue found.
// Just set issueStats to empty.
issueStats = &issues_model.IssueStats{}
} else {
// So it did search with the keyword, and found some issues. It needs to get issueStats of these issues.
// Or the keyword is empty, so it doesn't need issueIDs as filter, just get issueStats with statsOpts.
issueStats, err = issues_model.GetIssueStats(statsOpts)
if err != nil {
ctx.ServerError("GetIssueStats", err)
return
}

}

isShowClosed := ctx.FormString("state") == "closed"
Expand All @@ -245,6 +242,13 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
isShowClosed = true
}

var totalTrackedTime int64 = 0
totalTrackedTime, err = issues_model.GetIssueTotalTrackedTime(statsOpts, isShowClosed)
6543 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
ctx.ServerError("GetIssueTotalTrackedTime", err)
return
}

page := ctx.FormInt("page")
if page <= 1 {
page = 1
Expand Down Expand Up @@ -324,6 +328,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti
ctx.Data["Issues"] = issues
ctx.Data["CommitLastStatus"] = lastStatus
ctx.Data["CommitStatuses"] = commitStatuses
ctx.Data["TotalTrackedTime"] = totalTrackedTime

// Get assignees.
assigneeUsers, err := repo_model.GetRepoAssignees(ctx, repo)
Expand Down