Skip to content

Commit c9487a7

Browse files
changchaishiBen Changwxiaoguang
authored
Add "n commits" link to contributors in contributors graph page (#32799)
Fixes Issue #29365 and inherit PR #29429 - I should extend the #29429 fork but the fork is not synced, so I created another PR. - Use `silenced` class for the link, as in #29847 --------- Co-authored-by: Ben Chang <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent 00e2b33 commit c9487a7

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

Diff for: templates/repo/contributors.tmpl

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{{if .Permission.CanRead ctx.Consts.RepoUnitTypeCode}}
22
<div id="repo-contributors-chart"
33
data-repo-link="{{.RepoLink}}"
4+
data-repo-default-branch-name="{{.Repository.DefaultBranch}}"
45
data-locale-filter-label="{{ctx.Locale.Tr "repo.contributors.contribution_type.filter_label"}}"
56
data-locale-contribution-type-commits="{{ctx.Locale.Tr "repo.contributors.contribution_type.commits"}}"
67
data-locale-contribution-type-additions="{{ctx.Locale.Tr "repo.contributors.contribution_type.additions"}}"

Diff for: web_src/js/components/RepoContributors.vue

+23-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
22
import {SvgIcon} from '../svg.ts';
3+
import dayjs from 'dayjs';
34
import {
45
Chart,
56
Title,
@@ -26,6 +27,7 @@ import {sleep} from '../utils.ts';
2627
import 'chartjs-adapter-dayjs-4/dist/chartjs-adapter-dayjs-4.esm';
2728
import {fomanticQuery} from '../modules/fomantic/base.ts';
2829
import type {Entries} from 'type-fest';
30+
import {pathEscapeSegments} from '../utils/url.ts';
2931
3032
const customEventListener: Plugin = {
3133
id: 'customEventListener',
@@ -65,6 +67,10 @@ export default {
6567
type: String,
6668
required: true,
6769
},
70+
repoDefaultBranchName: {
71+
type: String,
72+
required: true,
73+
},
6874
},
6975
data: () => ({
7076
isLoading: false,
@@ -100,6 +106,15 @@ export default {
100106
.slice(0, 100);
101107
},
102108
109+
getContributorSearchQuery(contributorEmail: string) {
110+
const min = dayjs(this.xAxisMin).format('YYYY-MM-DD');
111+
const max = dayjs(this.xAxisMax).format('YYYY-MM-DD');
112+
const params = new URLSearchParams({
113+
'q': `after:${min}, before:${max}, author:${contributorEmail}`,
114+
});
115+
return `${this.repoLink}/commits/branch/${pathEscapeSegments(this.repoDefaultBranchName)}/search?${params.toString()}`;
116+
},
117+
103118
async fetchGraphData() {
104119
this.isLoading = true;
105120
try {
@@ -167,7 +182,7 @@ export default {
167182
// for details.
168183
user.max_contribution_type += 1;
169184
170-
filteredData[key] = {...user, weeks: filteredWeeks};
185+
filteredData[key] = {...user, weeks: filteredWeeks, email: key};
171186
}
172187
173188
return filteredData;
@@ -215,7 +230,7 @@ export default {
215230
};
216231
},
217232
218-
updateOtherCharts({chart}: {chart: Chart}, reset?: boolean = false) {
233+
updateOtherCharts({chart}: {chart: Chart}, reset: boolean = false) {
219234
const minVal = chart.options.scales.x.min;
220235
const maxVal = chart.options.scales.x.max;
221236
if (reset) {
@@ -381,15 +396,19 @@ export default {
381396
<div class="ui top attached header tw-flex tw-flex-1">
382397
<b class="ui right">#{{ index + 1 }}</b>
383398
<a :href="contributor.home_link">
384-
<img class="ui avatar tw-align-middle" height="40" width="40" :src="contributor.avatar_link">
399+
<img class="ui avatar tw-align-middle" height="40" width="40" :src="contributor.avatar_link" alt="">
385400
</a>
386401
<div class="tw-ml-2">
387402
<a v-if="contributor.home_link !== ''" :href="contributor.home_link"><h4>{{ contributor.name }}</h4></a>
388403
<h4 v-else class="contributor-name">
389404
{{ contributor.name }}
390405
</h4>
391406
<p class="tw-text-12 tw-flex tw-gap-1">
392-
<strong v-if="contributor.total_commits">{{ contributor.total_commits.toLocaleString() }} {{ locale.contributionType.commits }}</strong>
407+
<strong v-if="contributor.total_commits">
408+
<a class="silenced" :href="getContributorSearchQuery(contributor.email)">
409+
{{ contributor.total_commits.toLocaleString() }} {{ locale.contributionType.commits }}
410+
</a>
411+
</strong>
393412
<strong v-if="contributor.total_additions" class="text green">{{ contributor.total_additions.toLocaleString() }}++ </strong>
394413
<strong v-if="contributor.total_deletions" class="text red">
395414
{{ contributor.total_deletions.toLocaleString() }}--</strong>

Diff for: web_src/js/features/contributors.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export async function initRepoContributors() {
88
try {
99
const View = createApp(RepoContributors, {
1010
repoLink: el.getAttribute('data-repo-link'),
11+
repoDefaultBranchName: el.getAttribute('data-repo-default-branch-name'),
1112
locale: {
1213
filterLabel: el.getAttribute('data-locale-filter-label'),
1314
contributionType: {

0 commit comments

Comments
 (0)