diff --git a/packages/html-reporter/src/metadataView.tsx b/packages/html-reporter/src/metadataView.tsx index b210e844c8..dcc27acb25 100644 --- a/packages/html-reporter/src/metadataView.tsx +++ b/packages/html-reporter/src/metadataView.tsx @@ -61,8 +61,8 @@ const InnerMetadataView: React.FC<{ metadata: Metadata }> = params => { if (!hasMetadata) return; return
- {commitInfo.ci && } - {commitInfo.gitCommit && } + {commitInfo.ci && !commitInfo.gitCommit && } + {commitInfo.gitCommit && } {otherEntries.length > 0 && (commitInfo.gitCommit || commitInfo.ci) &&
}
{otherEntries.map(([propertyName, value]) => { @@ -82,32 +82,27 @@ const InnerMetadataView: React.FC<{ metadata: Metadata }> = params => { }; const CiInfoView: React.FC<{ info: CIInfo }> = ({ info }) => { - const link = info.commitHref; + const title = info.prTitle || `Commit ${info.commitHash}`; + const link = info.prHref || info.commitHref; return ; }; -const GitCommitInfoView: React.FC<{ link?: string, info: GitCommitInfo }> = ({ link, info }) => { - const subject = info.subject; - const email = ` <${info.author.email}>`; - const author = `${info.author.name}${email}`; - const shortTimestamp = Intl.DateTimeFormat(undefined, { dateStyle: 'medium' }).format(info.committer.time); - const longTimestamp = Intl.DateTimeFormat(undefined, { dateStyle: 'full', timeStyle: 'long' }).format(info.committer.time); +const GitCommitInfoView: React.FC<{ ci?: CIInfo, commit: GitCommitInfo }> = ({ ci, commit }) => { + const title = ci?.prTitle || commit.subject; + const link = ci?.prHref || ci?.commitHref; + const email = ` <${commit.author.email}>`; + const author = `${commit.author.name}${email}`; + const shortTimestamp = Intl.DateTimeFormat(undefined, { dateStyle: 'medium' }).format(commit.committer.time); + const longTimestamp = Intl.DateTimeFormat(undefined, { dateStyle: 'full', timeStyle: 'long' }).format(commit.committer.time); return
- {link ? ( - - {subject} - - ) : - {subject} - } + {link && {title}} + {!link && {title}}
{author} diff --git a/packages/playwright/src/isomorphic/types.d.ts b/packages/playwright/src/isomorphic/types.d.ts index 2f0b85e1f0..cbdb01cc52 100644 --- a/packages/playwright/src/isomorphic/types.d.ts +++ b/packages/playwright/src/isomorphic/types.d.ts @@ -34,6 +34,8 @@ export type GitCommitInfo = { export type CIInfo = { commitHref: string; + prHref?: string; + prTitle?: string; buildHref?: string; commitHash?: string; baseHash?: string; diff --git a/packages/playwright/src/plugins/gitCommitInfoPlugin.ts b/packages/playwright/src/plugins/gitCommitInfoPlugin.ts index a80ef3b705..bba2acfb73 100644 --- a/packages/playwright/src/plugins/gitCommitInfoPlugin.ts +++ b/packages/playwright/src/plugins/gitCommitInfoPlugin.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +import * as fs from 'fs'; + import { spawnAsync } from 'playwright-core/lib/utils'; import type { TestRunnerPlugin } from './'; @@ -37,7 +39,7 @@ export const gitCommitInfoPlugin = (options?: GitCommitInfoPluginOptions): TestR setup: async (config: FullConfig, configDir: string) => { const metadata = config.metadata as UserMetadataWithCommitInfo; - const ci = ciInfo(); + const ci = await ciInfo(); if (!metadata.ci && ci) metadata.ci = ci; @@ -62,10 +64,19 @@ export const gitCommitInfoPlugin = (options?: GitCommitInfoPluginOptions): TestR }; }; -function ciInfo(): CIInfo | undefined { +async function ciInfo(): Promise { if (process.env.GITHUB_ACTIONS) { + let pr: { title: string, number: number } | undefined; + try { + const json = JSON.parse(await fs.promises.readFile(process.env.GITHUB_EVENT_PATH!, 'utf8')); + pr = { title: json.pull_request.title, number: json.pull_request.number }; + } catch { + } + return { commitHref: `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/commit/${process.env.GITHUB_SHA}`, + prHref: pr ? `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/pull/${pr.number}` : undefined, + prTitle: pr ? pr.title : undefined, buildHref: `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`, commitHash: process.env.GITHUB_SHA, baseHash: process.env.GITHUB_BASE_REF, @@ -76,6 +87,7 @@ function ciInfo(): CIInfo | undefined { if (process.env.GITLAB_CI) { return { commitHref: `${process.env.CI_PROJECT_URL}/-/commit/${process.env.CI_COMMIT_SHA}`, + prHref: process.env.CI_MERGE_REQUEST_IID ? `${process.env.CI_PROJECT_URL}/-/merge_requests/${process.env.CI_MERGE_REQUEST_IID}` : undefined, buildHref: process.env.CI_JOB_URL, commitHash: process.env.CI_COMMIT_SHA, baseHash: process.env.CI_COMMIT_BEFORE_SHA, diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts index 22f0064eac..3d3a927b04 100644 --- a/tests/playwright-test/reporter-html.spec.ts +++ b/tests/playwright-test/reporter-html.spec.ts @@ -1297,7 +1297,8 @@ for (const useIntermediateMergeReport of [true, false] as const) { await expect(page.locator('.metadata-view')).toMatchAriaSnapshot(` - list: - listitem: - - link "https://playwright.dev/microsoft/playwright-example-for-test/commit/example-sha" + - link "My PR" + - listitem: /William / - list: - listitem: "foo : value1" - listitem: "bar : {\\"prop\\":\\"value2\\"}"