-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Add Activity page to repository #2674
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2674 +/- ##
==========================================
- Coverage 27.38% 27.12% -0.26%
==========================================
Files 86 87 +1
Lines 17014 17176 +162
==========================================
Hits 4659 4659
- Misses 11675 11837 +162
Partials 680 680
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With regard to the screenshots, we should try to fix ungrammatical phrases like "1 pull requests" and "1 people".
Also, would "users" be a better word choice than "people"?
models/repo_pulse.go
Outdated
sess := x.Where("pull_request.base_repo_id=?", baseRepoID). | ||
Join("INNER", "issue", "pull_request.issue_id = issue.id") | ||
|
||
var mergedCond, createdCond builder.Cond |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this can be simplified
var cond builder.Cond
if merged {
cond = cond.Or(...)
}
if created {
cond = cond.Or(...)
}
sess.And(cond)
routers/repo/pulse.go
Outdated
timeFrom = timeTill.Add(-time.Hour * 168) | ||
} | ||
ctx.Data["DateFrom"] = timeFrom.Format("January 2, 2006") | ||
ctx.Data["DateTill"] = timeTill.Format("January 2, 2006") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please use "DateUntil"; it is not substanially longer, and is more explicit
routers/repo/pulse.go
Outdated
|
||
if ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests) { | ||
if err := models.FillPullRequestsForPulse(stats, ctx.Repo.Repository.ID, timeFrom); err != nil { | ||
ctx.Error(500, "FillPullRequestsForPulse: "+err.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe ctx.Status(500, "Function", err)
is preferred, and is used everywhere else
routers/routes/routes.go
Outdated
@@ -639,6 +644,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
m.Get("/compare/:before([a-z0-9]{40})\\.\\.\\.:after([a-z0-9]{40})", repo.SetEditorconfigIfExists, | |||
repo.SetDiffViewStyle, repo.MustBeNotBare, context.CheckUnit(models.UnitTypeCode), repo.CompareDiff) | |||
}, ignSignIn, context.RepoAssignment(), context.UnitTypes(), context.LoadRepoUnits()) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please remove
Could we call it "Activity" instead? (I never understood they GitHub called it "Pulse" 😂 ) |
@bkcsoft renamed tab to "Activity" As bonus added published releases info |
routers/repo/activity.go
Outdated
package repo | ||
|
||
import ( | ||
//"fmt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just remove the comment imports?
routers/routes/routes.go
Outdated
m.Group("/activity", func() { | ||
m.Get("", repo.Activity) | ||
m.Get("/:period", repo.Activity) | ||
}, context.RepoRef(), repo.MustBeNotBare, context.CheckUnit(models.UnitTypeCode)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a sub feature of unit Code
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking at first it should be code but now I don't know actually... What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be available to users who have permission to view PR and Issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lunny cleaned up forgotten imports and changed unit check to only needed ones |
LGTM |
models/repo_activity.go
Outdated
|
||
// Published releases authors | ||
sess = releasesForActivityStatement(baseRepoID, fromTime) | ||
if _, err = sess.Select("count(distinct release.publisher_id) as `count`").Table("release").Get(row); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var count int64
sess.Select().Table().Get(&count)
The current vendored xorm
already allowed you do that.
One more improvement. |
routers/repo/activity.go
Outdated
if err := models.FillUnresolvedIssuesForActivity(stats, ctx.Repo.Repository.ID, timeFrom, | ||
ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues), | ||
ctx.Repo.Repository.UnitEnabled(models.UnitTypePullRequests)); err != nil { | ||
ctx.Handle(500, "FillIssuesForActivity", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong error message
routers/repo/activity.go
Outdated
package repo | ||
|
||
import ( | ||
//"fmt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove all of these commented-out imports
modules/templates/helper.go
Outdated
} | ||
|
||
// Special rules for Latvian language | ||
if lang == "lv-LV" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe outside scope of this PR, but...
I'm not sure having hard-coded language-specific rules in the code is the right approach. I think ideally that language-specific rules should be expressed in that language's locale file, not in code. Two reasons for this:
- Many gitea translators are not familiar with the codebase
- Even hard-coded rules like this one may not be enough to support all languages. For instance, Arabic has three grammatical numbers (singular, dual, plural), so a function taking
key1
andkeyN
arguments wouldn't work for Arabic, regardless of what hard-coded rules we add.
Of course, encoding language-specific rule in the locale may require a more expressive i18n scheme, but that seems like the more sustainable approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ethantkoenig I don't see how such rule could be implemented in locale file. That would require to implement math parser in GoLang so that such rules could be used and this is totally out of scope for this PR
models/repo.go
Outdated
@@ -392,6 +392,19 @@ func (repo *Repository) UnitEnabled(tp UnitType) bool { | |||
return false | |||
} | |||
|
|||
// AnyUnitEnabled if this repository has the any of the given units enabled | |||
func (repo *Repository) AnyUnitEnabled(tps ...UnitType) bool { | |||
repo.getUnits(x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also getUnitsByRepoIDAndIDs
(currently unused anywhere)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we already discussed in discord it is better to keep same behaviour as in UnitEnabled
Shouldn't this feature be new |
@Morlinest Units are like right units. So they are not same as tabs, so no new unit is not needed for this |
@lafriks Right, I was thinking about option to disable/enable it. But there's probably no reason to do that. |
models/repo.go
Outdated
@@ -392,6 +392,19 @@ func (repo *Repository) UnitEnabled(tp UnitType) bool { | |||
return false | |||
} | |||
|
|||
// AnyUnitEnabled if this repository has the any of the given units enabled | |||
func (repo *Repository) AnyUnitEnabled(tps ...UnitType) bool { | |||
repo.getUnits(x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unchecked error returned by repo.getUnits(x)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm keeping same behaviour as in CheckUnit :) I will see if without much of rewriting there is anything I can do about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ethantkoenig as this needs to be used in templates so it can not return error so I don't see much I can do here and it is same as it is in UnitEnabled
method already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we at least log it?
* Rename pulse to activity * Implement correct count wording * Code cleanup
@ethantkoenig I did rewrite plural text translation method a bit to easier support multiple language exceptions but that is all that can be done currently. My native Latvian language also has 3 forms (singular for numbers ending with 1 except if ending with 11, plural and special case for 0) but without completely changing i18n library that is built into go-macaron framework gitea uses there is no way we can support that... |
@lafriks Okay, definitely an improvement. To be clear, I didn't mean that this PR be should blocked on the translation issue, but was just trying to make a general comment about a long-term possibility; sorry if that wasn't clear. And yes, I realize that we would need to update the i18n library to do what I was suggesting. |
@ethantkoenig added repo unit error logging |
LGTM |
One other thing: could we add a test? |
@ethantkoenig I thought about it but only test I can add if page opens without errors as stats are depending on time and preparing data for that would be quite hard |
Adds pulse page to repository to display latest activity from issues and pull requests
Screenshot:
