chore: restore pr title in html report (#34937)
This commit is contained in:
parent
a803e6053a
commit
58db3f7e3f
|
@ -61,8 +61,8 @@ const InnerMetadataView: React.FC<{ metadata: Metadata }> = params => {
|
|||
if (!hasMetadata)
|
||||
return;
|
||||
return <div className='metadata-view'>
|
||||
{commitInfo.ci && <CiInfoView info={commitInfo.ci}/>}
|
||||
{commitInfo.gitCommit && <GitCommitInfoView link={commitInfo.ci?.commitHref} info={commitInfo.gitCommit}/>}
|
||||
{commitInfo.ci && !commitInfo.gitCommit && <CiInfoView info={commitInfo.ci}/>}
|
||||
{commitInfo.gitCommit && <GitCommitInfoView ci={commitInfo.ci} commit={commitInfo.gitCommit}/>}
|
||||
{otherEntries.length > 0 && (commitInfo.gitCommit || commitInfo.ci) && <div className='metadata-separator' />}
|
||||
<div className='metadata-section metadata-properties' role='list'>
|
||||
{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 <div className='metadata-section' role='list'>
|
||||
<div role='listitem'>
|
||||
<a href={link} target='_blank' rel='noopener noreferrer' title={link}>
|
||||
{link}
|
||||
</a>
|
||||
<a href={link} target='_blank' rel='noopener noreferrer' title={title}>{title}</a>
|
||||
</div>
|
||||
</div>;
|
||||
};
|
||||
|
||||
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 <div className='metadata-section' role='list'>
|
||||
<div role='listitem'>
|
||||
{link ? (
|
||||
<a href={link} target='_blank' rel='noopener noreferrer' title={subject}>
|
||||
{subject}
|
||||
</a>
|
||||
) : <span title={subject}>
|
||||
{subject}
|
||||
</span>}
|
||||
{link && <a href={link} target='_blank' rel='noopener noreferrer' title={title}>{title}</a>}
|
||||
{!link && <span title={title}>{title}</span>}
|
||||
</div>
|
||||
<div role='listitem' className='hbox'>
|
||||
<span className='mr-1'>{author}</span>
|
||||
|
|
|
@ -34,6 +34,8 @@ export type GitCommitInfo = {
|
|||
|
||||
export type CIInfo = {
|
||||
commitHref: string;
|
||||
prHref?: string;
|
||||
prTitle?: string;
|
||||
buildHref?: string;
|
||||
commitHash?: string;
|
||||
baseHash?: string;
|
||||
|
|
|
@ -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<CIInfo | undefined> {
|
||||
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,
|
||||
|
|
|
@ -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 <shakespeare@example.local>/
|
||||
- list:
|
||||
- listitem: "foo : value1"
|
||||
- listitem: "bar : {\\"prop\\":\\"value2\\"}"
|
||||
|
|
Loading…
Reference in New Issue