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

Add "n commits" link to contributors in contributors graph page #29429

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

sahinakkaya
Copy link
Contributor

Fixes #29365.

@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Feb 26, 2024
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 26, 2024
sahinakkaya and others added 2 commits February 26, 2024 19:54
Co-authored-by: silverwind <me@silverwind.io>
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 26, 2024
@@ -88,6 +91,9 @@ export default {
methods: {
sortContributors() {
const contributors = this.filterContributorWeeksByDateRange();
const min = dayjs(this.xAxisMin).format('YYYY-MM-DD');
const max = dayjs(this.xAxisMax).format('YYYY-MM-DD');
this.searchQuery = `${this.repoLink}/commits/branch/${this.repoBranch}/search?q=after:${min}, before:${max}, author:`;
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to encodeURIComponent(this.repoBranch)? Try with a branch name that contains a space character.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup.

Actually this.repoBranch might need to use path segment escape.

The q parameter also needs to be escaped (encodeURIComponent)

Copy link
Member

@silverwind silverwind Feb 26, 2024

Choose a reason for hiding this comment

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

Actually this.repoBranch might need to use path segment escape.

There is no path escape function in JS, I think encodeURIComponent is suitable for alle cases, path or search params.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess "org/repo/branch/feature%2Fbranch" doesn't work.

Copy link
Member

@silverwind silverwind Feb 26, 2024

Choose a reason for hiding this comment

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

Yes, you can not pass / to encodeURIComponent if it's part of the path, it's meant for individual path segments or search param values.

@@ -88,6 +91,9 @@ export default {
methods: {
sortContributors() {
const contributors = this.filterContributorWeeksByDateRange();
const min = dayjs(this.xAxisMin).format('YYYY-MM-DD');
const max = dayjs(this.xAxisMax).format('YYYY-MM-DD');
this.searchQuery = `${this.repoLink}/commits/branch/${this.repoBranch}/search?q=after:${min}, before:${max}, author:`;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
this.searchQuery = `${this.repoLink}/commits/branch/${this.repoBranch}/search?q=after:${min}, before:${max}, author:`;
this.searchQuery = `${this.repoLink}/commits/branch/${this.repoBranch}/search?q=after:${min},before:${max},author:`;

also, it looks really weird to construct the search query like this.
Wouldn't it make more sense to have ?after=…&before=…&author=…?
And is all that functionality already supported?
I would have guessed that you need to add it yourself…

Copy link
Member

@silverwind silverwind Feb 26, 2024

Choose a reason for hiding this comment

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

Ideally we should use URLSearchParams to construct search params:

String(new URLSearchParams({foo: "bar", baz: "a b"}))
// 'foo=bar&baz=a+b'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't it make more sense to have ?after=…&before=…&author=…?

yeah, it would. But I can't do that way because it is not something I decided. Gitea currently works the other way.

And is all that functionality already supported?

Yes. And it won't work if I accept your code suggestion. The spaces are important. As I said, this is how 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.

If it's existing API, I guess this weird format is okay, otherwise it would be a breaking change. Still we should ensure the individual paramters and path segments are encoded correctly.

@@ -384,7 +390,7 @@ export default {
{{ contributor.name }}
</h4>
<p class="gt-font-12 gt-df gt-gap-2">
<strong v-if="contributor.total_commits">{{ contributor.total_commits.toLocaleString() }} {{ locale.contributionType.commits }}</strong>
<strong v-if="contributor.total_commits"><a :href="searchQuery + contributor.email">{{ contributor.total_commits.toLocaleString() }} {{ locale.contributionType.commits }}</a></strong>
Copy link
Member

Choose a reason for hiding this comment

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

What about users having multiple emails?
For those, only the primary email will be counted if I see that correctly…

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All email addresses of a user are mapped to their primary email address in backend. See:

if u != nil {
// update userEmail with user's primary email address so
// that different mail addresses will linked to same account
userEmail = u.GetEmail()
}

If I don't do that, we will see same user multiple times in the contributor graphs page (for multiple emails). And problem you mentioned will be fixed.

But I would prefer it this way as it looks cleaner. I guess it doesn't have to be perfect all the times. If you really want it to be perfect, you may modify the backend code to include commits of a user with their other email addresses when queried (maybe it already works this way, I didn't check)

@wxiaoguang wxiaoguang self-requested a review February 26, 2024 17:53
@GiteaBot GiteaBot added lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 26, 2024
@sahinakkaya
Copy link
Contributor Author

Everyone reviewing this PR, please experiment with the following search box before your reviews:
image

It seems that most of the people aren't aware of the functionality this PR makes use of.

@yp05327
Copy link
Contributor

yp05327 commented Feb 27, 2024

The design now:
image
Tried to add muted class to the link:
image
But it seems that it is not the best resolution, as the color of hover is same to the username's color.
Then there are too many green here:
image

Maybe this is better?
image

@sahinakkaya
Copy link
Contributor Author

Yeah, it's a good change @yp05327. Feel free to open a PR in my fork and I will accept it.

@silverwind
Copy link
Member

silverwind commented Feb 27, 2024

Tried to add muted class to the link

This is how GH has it and I think I'm fine with it. Could also mute both links or even use text grey on the second line.

Then there are too many green here

#29283 will make links blue soon on dark theme.

@yp05327
Copy link
Contributor

yp05327 commented Mar 1, 2024

Yeah, it's a good change @yp05327. Feel free to open a PR in my fork and I will accept it.

Sorry, I'm afraid I can't finish this, as I'm not good at CSS, so the screenshot is made by PPT. 😭

#29283 will make links blue soon on dark theme.

Then the user name and the x commits (hover) will be blue, and too many blue?
Can we add a new class that hover with not change the color and only add underbars?
Then this place will look more clearly with different colors.

@silverwind
Copy link
Member

Can we add a new class that hover with not change the color and only add underbars?

Yes, in fact I made that exact class in another open PR, we can copy the CSS:

https://github.com/go-gitea/gitea/pull/29344/files#diff-bf3a284bc2ea51adf0333a1ece388b60b4aff10e3ec715a889c6fed44450f2d3,

@silverwind
Copy link
Member

Can we add a new class that hover with not change the color and only add underbars?

Yes, in fact I made that exact class in another open PR, we can copy the CSS:

https://github.com/go-gitea/gitea/pull/29344/files#diff-bf3a284bc2ea51adf0333a1ece388b60b4aff10e3ec715a889c6fed44450f2d3,

#29847 will add this support for a.suppressed.

silverwind added a commit that referenced this pull request Mar 16, 2024
Extract from #29344. With this
class it's possible to have links that don't color on hover. It will be
useful for #29429.
DennisRasey pushed a commit to DennisRasey/forgejo that referenced this pull request Mar 20, 2024
Extract from go-gitea/gitea#29344. With this
class it's possible to have links that don't color on hover. It will be
useful for go-gitea/gitea#29429.

(cherry picked from commit ffeaf2d0bd6c99c486aa7869779bb9ceb0aedad6)
@wxiaoguang
Copy link
Contributor

Stale for long time?

@wxiaoguang wxiaoguang added the issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail label Nov 10, 2024
@sahinakkaya
Copy link
Contributor Author

Stale for long time?

Yeah, it is. Unfortunetely, I don't have much time to work on this. Maybe someone can take over from here. Only style issues were left iirc. Shouldn't be hard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue/needs-feedback For bugs, we need more details. For features, the feature must be described in more detail lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a link to user's commits in contributors graph
6 participants