[ci] Add branch to failed test reporter github comments (#113860)
This commit is contained in:
parent
7ad30eda15
commit
5216442d6c
|
@ -26,7 +26,8 @@ describe('createFailureIssue()', () => {
|
||||||
time: '2018-01-01T01:00:00Z',
|
time: '2018-01-01T01:00:00Z',
|
||||||
likelyIrrelevant: false,
|
likelyIrrelevant: false,
|
||||||
},
|
},
|
||||||
api
|
api,
|
||||||
|
'main'
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(api.createIssue).toMatchInlineSnapshot(`
|
expect(api.createIssue).toMatchInlineSnapshot(`
|
||||||
|
@ -40,7 +41,7 @@ describe('createFailureIssue()', () => {
|
||||||
this is the failure text
|
this is the failure text
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
First failure: [CI Build](https://build-url)
|
First failure: [CI Build - main](https://build-url)
|
||||||
|
|
||||||
<!-- kibanaCiData = {\\"failed-test\\":{\\"test.class\\":\\"some.classname\\",\\"test.name\\":\\"test name\\",\\"test.failCount\\":1}} -->",
|
<!-- kibanaCiData = {\\"failed-test\\":{\\"test.class\\":\\"some.classname\\",\\"test.name\\":\\"test name\\",\\"test.failCount\\":1}} -->",
|
||||||
Array [
|
Array [
|
||||||
|
@ -74,7 +75,8 @@ describe('updateFailureIssue()', () => {
|
||||||
<!-- kibanaCiData = {"failed-test":{"test.failCount":10}} -->"
|
<!-- kibanaCiData = {"failed-test":{"test.failCount":10}} -->"
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
api
|
api,
|
||||||
|
'main'
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(api.editIssueBodyAndEnsureOpen).toMatchInlineSnapshot(`
|
expect(api.editIssueBodyAndEnsureOpen).toMatchInlineSnapshot(`
|
||||||
|
@ -100,7 +102,7 @@ describe('updateFailureIssue()', () => {
|
||||||
"calls": Array [
|
"calls": Array [
|
||||||
Array [
|
Array [
|
||||||
1234,
|
1234,
|
||||||
"New failure: [CI Build](https://build-url)",
|
"New failure: [CI Build - main](https://build-url)",
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
"results": Array [
|
"results": Array [
|
||||||
|
|
|
@ -10,7 +10,12 @@ import { TestFailure } from './get_failures';
|
||||||
import { GithubIssueMini, GithubApi } from './github_api';
|
import { GithubIssueMini, GithubApi } from './github_api';
|
||||||
import { getIssueMetadata, updateIssueMetadata } from './issue_metadata';
|
import { getIssueMetadata, updateIssueMetadata } from './issue_metadata';
|
||||||
|
|
||||||
export async function createFailureIssue(buildUrl: string, failure: TestFailure, api: GithubApi) {
|
export async function createFailureIssue(
|
||||||
|
buildUrl: string,
|
||||||
|
failure: TestFailure,
|
||||||
|
api: GithubApi,
|
||||||
|
branch: string
|
||||||
|
) {
|
||||||
const title = `Failing test: ${failure.classname} - ${failure.name}`;
|
const title = `Failing test: ${failure.classname} - ${failure.name}`;
|
||||||
|
|
||||||
const body = updateIssueMetadata(
|
const body = updateIssueMetadata(
|
||||||
|
@ -21,7 +26,7 @@ export async function createFailureIssue(buildUrl: string, failure: TestFailure,
|
||||||
failure.failure,
|
failure.failure,
|
||||||
'```',
|
'```',
|
||||||
'',
|
'',
|
||||||
`First failure: [CI Build](${buildUrl})`,
|
`First failure: [CI Build - ${branch}](${buildUrl})`,
|
||||||
].join('\n'),
|
].join('\n'),
|
||||||
{
|
{
|
||||||
'test.class': failure.classname,
|
'test.class': failure.classname,
|
||||||
|
@ -33,7 +38,12 @@ export async function createFailureIssue(buildUrl: string, failure: TestFailure,
|
||||||
return await api.createIssue(title, body, ['failed-test']);
|
return await api.createIssue(title, body, ['failed-test']);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateFailureIssue(buildUrl: string, issue: GithubIssueMini, api: GithubApi) {
|
export async function updateFailureIssue(
|
||||||
|
buildUrl: string,
|
||||||
|
issue: GithubIssueMini,
|
||||||
|
api: GithubApi,
|
||||||
|
branch: string
|
||||||
|
) {
|
||||||
// Increment failCount
|
// Increment failCount
|
||||||
const newCount = getIssueMetadata(issue.body, 'test.failCount', 0) + 1;
|
const newCount = getIssueMetadata(issue.body, 'test.failCount', 0) + 1;
|
||||||
const newBody = updateIssueMetadata(issue.body, {
|
const newBody = updateIssueMetadata(issue.body, {
|
||||||
|
@ -41,7 +51,7 @@ export async function updateFailureIssue(buildUrl: string, issue: GithubIssueMin
|
||||||
});
|
});
|
||||||
|
|
||||||
await api.editIssueBodyAndEnsureOpen(issue.number, newBody);
|
await api.editIssueBodyAndEnsureOpen(issue.number, newBody);
|
||||||
await api.addIssueComment(issue.number, `New failure: [CI Build](${buildUrl})`);
|
await api.addIssueComment(issue.number, `New failure: [CI Build - ${branch}](${buildUrl})`);
|
||||||
|
|
||||||
return newCount;
|
return newCount;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,8 @@ export function runFailedTestsReporterCli() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let branch: string = '';
|
||||||
if (updateGithub) {
|
if (updateGithub) {
|
||||||
let branch: string = '';
|
|
||||||
let isPr = false;
|
let isPr = false;
|
||||||
|
|
||||||
if (process.env.BUILDKITE === 'true') {
|
if (process.env.BUILDKITE === 'true') {
|
||||||
|
@ -139,7 +139,12 @@ export function runFailedTestsReporterCli() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (existingIssue) {
|
if (existingIssue) {
|
||||||
const newFailureCount = await updateFailureIssue(buildUrl, existingIssue, githubApi);
|
const newFailureCount = await updateFailureIssue(
|
||||||
|
buildUrl,
|
||||||
|
existingIssue,
|
||||||
|
githubApi,
|
||||||
|
branch
|
||||||
|
);
|
||||||
const url = existingIssue.html_url;
|
const url = existingIssue.html_url;
|
||||||
pushMessage(`Test has failed ${newFailureCount - 1} times on tracked branches: ${url}`);
|
pushMessage(`Test has failed ${newFailureCount - 1} times on tracked branches: ${url}`);
|
||||||
if (updateGithub) {
|
if (updateGithub) {
|
||||||
|
@ -148,7 +153,7 @@ export function runFailedTestsReporterCli() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newIssue = await createFailureIssue(buildUrl, failure, githubApi);
|
const newIssue = await createFailureIssue(buildUrl, failure, githubApi, branch);
|
||||||
pushMessage('Test has not failed recently on tracked branches');
|
pushMessage('Test has not failed recently on tracked branches');
|
||||||
if (updateGithub) {
|
if (updateGithub) {
|
||||||
pushMessage(`Created new issue: ${newIssue.html_url}`);
|
pushMessage(`Created new issue: ${newIssue.html_url}`);
|
||||||
|
|
Loading…
Reference in a new issue