From ad7df0f70a2e9cd7878312d02c67a374cc194a41 Mon Sep 17 00:00:00 2001 From: Chai-Shi Date: Fri, 13 Dec 2024 03:02:54 +0800 Subject: [PATCH 1/3] 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 Co-authored-by: wxiaoguang --- templates/repo/contributors.tmpl | 1 + web_src/js/components/RepoContributors.vue | 25 +++++++++++++++++++--- web_src/js/features/contributors.js | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/templates/repo/contributors.tmpl b/templates/repo/contributors.tmpl index f7f5d796f4..c71312fc6c 100644 --- a/templates/repo/contributors.tmpl +++ b/templates/repo/contributors.tmpl @@ -1,6 +1,7 @@ {{if .Permission.CanRead $.UnitTypeCode}}
import {SvgIcon} from '../svg.js'; +import dayjs from 'dayjs'; import { Chart, Title, @@ -22,6 +23,7 @@ import {chartJsColors} from '../utils/color.js'; import {sleep} from '../utils.js'; import 'chartjs-adapter-dayjs-4/dist/chartjs-adapter-dayjs-4.esm'; import $ from 'jquery'; +import {pathEscapeSegments} from '../utils/url.js'; const customEventListener = { id: 'customEventListener', @@ -61,6 +63,10 @@ export default { type: String, required: true, }, + repoDefaultBranchName: { + type: String, + required: true, + }, }, data: () => ({ isLoading: false, @@ -96,6 +102,15 @@ export default { .slice(0, 100); }, + getContributorSearchQuery(contributorEmail) { + const min = dayjs(this.xAxisMin).format('YYYY-MM-DD'); + const max = dayjs(this.xAxisMax).format('YYYY-MM-DD'); + const params = new URLSearchParams({ + 'q': `after:${min}, before:${max}, author:${contributorEmail}`, + }); + return `${this.repoLink}/commits/branch/${pathEscapeSegments(this.repoDefaultBranchName)}/search?${params.toString()}`; + }, + async fetchGraphData() { this.isLoading = true; try { @@ -163,7 +178,7 @@ export default { // for details. user.max_contribution_type += 1; - filteredData[key] = {...user, weeks: filteredWeeks}; + filteredData[key] = {...user, weeks: filteredWeeks, email: key}; } return filteredData; @@ -376,7 +391,7 @@ export default {
#{{ index + 1 }} - +

{{ contributor.name }}

@@ -384,7 +399,11 @@ export default { {{ contributor.name }}

- {{ contributor.total_commits.toLocaleString() }} {{ locale.contributionType.commits }} + + + {{ contributor.total_commits.toLocaleString() }} {{ locale.contributionType.commits }} + + {{ contributor.total_additions.toLocaleString() }}++ {{ contributor.total_deletions.toLocaleString() }}-- diff --git a/web_src/js/features/contributors.js b/web_src/js/features/contributors.js index 79b3389fee..c0106b6350 100644 --- a/web_src/js/features/contributors.js +++ b/web_src/js/features/contributors.js @@ -8,6 +8,7 @@ export async function initRepoContributors() { try { const View = createApp(RepoContributors, { repoLink: el.getAttribute('data-repo-link'), + repoDefaultBranchName: el.getAttribute('data-repo-default-branch-name'), locale: { filterLabel: el.getAttribute('data-locale-filter-label'), contributionType: { From 3cd36c4b212174230e0c9a5cf4c9577418c82124 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sun, 15 Dec 2024 22:34:13 +0100 Subject: [PATCH 2/3] Add Playwright test --- tests/e2e/repo-activity-contributors.test.e2e.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tests/e2e/repo-activity-contributors.test.e2e.ts diff --git a/tests/e2e/repo-activity-contributors.test.e2e.ts b/tests/e2e/repo-activity-contributors.test.e2e.ts new file mode 100644 index 0000000000..7235d24b15 --- /dev/null +++ b/tests/e2e/repo-activity-contributors.test.e2e.ts @@ -0,0 +1,8 @@ +import {expect} from '@playwright/test'; +import {test} from './utils_e2e.ts'; + +test('Contributor graph', async ({page}) => { + await page.goto('/user2/commits_search_test/activity/contributors'); + await page.getByRole('link', {name: '2 Commits'}).click(); + await expect(page.getByRole('cell', {name: 'Bob'})).toHaveCount(2); +}); From a6a9314bdb0dedc8480c37159f96183169d1d851 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Mon, 16 Dec 2024 09:13:14 +0100 Subject: [PATCH 3/3] Add copyright header and watch header --- tests/e2e/repo-activity-contributors.test.e2e.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/e2e/repo-activity-contributors.test.e2e.ts b/tests/e2e/repo-activity-contributors.test.e2e.ts index 7235d24b15..ece62cfaba 100644 --- a/tests/e2e/repo-activity-contributors.test.e2e.ts +++ b/tests/e2e/repo-activity-contributors.test.e2e.ts @@ -1,3 +1,12 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: GPL-3.0-or-later + +// @watch start +// web_src/js/features/contributors.js +// web_src/js/components/RepoContributors.vue +// templates/repo/* +// @watch end + import {expect} from '@playwright/test'; import {test} from './utils_e2e.ts';