mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[7.6] [failed-test-report] if one test fails twice don't creat… (#59161)
* [failed-test-report] if one test fails twice don't create two issues * fix type check error Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
0e06f3266d
commit
d2fcbb42ca
4 changed files with 36 additions and 11 deletions
|
@ -33,6 +33,15 @@ export interface GithubIssue {
|
|||
body: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimal GithubIssue type that can be easily replicated by dry-run helpers
|
||||
*/
|
||||
export interface GithubIssueMini {
|
||||
number: GithubIssue['number'];
|
||||
body: GithubIssue['body'];
|
||||
html_url: GithubIssue['html_url'];
|
||||
}
|
||||
|
||||
type RequestOptions = AxiosRequestConfig & {
|
||||
safeForDryRun?: boolean;
|
||||
maxAttempts?: number;
|
||||
|
@ -162,7 +171,7 @@ export class GithubApi {
|
|||
}
|
||||
|
||||
async createIssue(title: string, body: string, labels?: string[]) {
|
||||
const resp = await this.request(
|
||||
const resp = await this.request<GithubIssueMini>(
|
||||
{
|
||||
method: 'POST',
|
||||
url: Url.resolve(BASE_URL, 'issues'),
|
||||
|
@ -173,11 +182,13 @@ export class GithubApi {
|
|||
},
|
||||
},
|
||||
{
|
||||
body,
|
||||
number: 999,
|
||||
html_url: 'https://dryrun',
|
||||
}
|
||||
);
|
||||
|
||||
return resp.data.html_url;
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
private async request<T>(
|
||||
|
|
|
@ -78,9 +78,7 @@ describe('updateFailureIssue()', () => {
|
|||
'https://build-url',
|
||||
{
|
||||
html_url: 'https://github.com/issues/1234',
|
||||
labels: ['some-label'],
|
||||
number: 1234,
|
||||
title: 'issue title',
|
||||
body: dedent`
|
||||
# existing issue body
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
import { TestFailure } from './get_failures';
|
||||
import { GithubIssue, GithubApi } from './github_api';
|
||||
import { GithubIssueMini, GithubApi } from './github_api';
|
||||
import { getIssueMetadata, updateIssueMetadata } from './issue_metadata';
|
||||
|
||||
export async function createFailureIssue(buildUrl: string, failure: TestFailure, api: GithubApi) {
|
||||
|
@ -44,7 +44,7 @@ export async function createFailureIssue(buildUrl: string, failure: TestFailure,
|
|||
return await api.createIssue(title, body, ['failed-test']);
|
||||
}
|
||||
|
||||
export async function updateFailureIssue(buildUrl: string, issue: GithubIssue, api: GithubApi) {
|
||||
export async function updateFailureIssue(buildUrl: string, issue: GithubIssueMini, api: GithubApi) {
|
||||
// Increment failCount
|
||||
const newCount = getIssueMetadata(issue.body, 'test.failCount', 0) + 1;
|
||||
const newBody = updateIssueMetadata(issue.body, {
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
import { REPO_ROOT, run, createFailError, createFlagError } from '@kbn/dev-utils';
|
||||
import globby from 'globby';
|
||||
|
||||
import { getFailures } from './get_failures';
|
||||
import { GithubApi } from './github_api';
|
||||
import { getFailures, TestFailure } from './get_failures';
|
||||
import { GithubApi, GithubIssueMini } from './github_api';
|
||||
import { updateFailureIssue, createFailureIssue } from './report_failure';
|
||||
import { getIssueMetadata } from './issue_metadata';
|
||||
import { readTestReport } from './test_report';
|
||||
|
@ -73,6 +73,11 @@ export function runFailedTestsReporterCli() {
|
|||
absolute: true,
|
||||
});
|
||||
|
||||
const newlyCreatedIssues: Array<{
|
||||
failure: TestFailure;
|
||||
newIssue: GithubIssueMini;
|
||||
}> = [];
|
||||
|
||||
for (const reportPath of reportPaths) {
|
||||
const report = await readTestReport(reportPath);
|
||||
const messages = Array.from(getReportMessageIter(report));
|
||||
|
@ -94,12 +99,22 @@ export function runFailedTestsReporterCli() {
|
|||
continue;
|
||||
}
|
||||
|
||||
const existingIssue = await githubApi.findFailedTestIssue(
|
||||
let existingIssue: GithubIssueMini | undefined = await githubApi.findFailedTestIssue(
|
||||
i =>
|
||||
getIssueMetadata(i.body, 'test.class') === failure.classname &&
|
||||
getIssueMetadata(i.body, 'test.name') === failure.name
|
||||
);
|
||||
|
||||
if (!existingIssue) {
|
||||
const newlyCreated = newlyCreatedIssues.find(
|
||||
({ failure: f }) => f.classname === failure.classname && f.name === failure.name
|
||||
);
|
||||
|
||||
if (newlyCreated) {
|
||||
existingIssue = newlyCreated.newIssue;
|
||||
}
|
||||
}
|
||||
|
||||
if (existingIssue) {
|
||||
const newFailureCount = await updateFailureIssue(buildUrl, existingIssue, githubApi);
|
||||
const url = existingIssue.html_url;
|
||||
|
@ -110,11 +125,12 @@ export function runFailedTestsReporterCli() {
|
|||
continue;
|
||||
}
|
||||
|
||||
const newIssueUrl = await createFailureIssue(buildUrl, failure, githubApi);
|
||||
const newIssue = await createFailureIssue(buildUrl, failure, githubApi);
|
||||
pushMessage('Test has not failed recently on tracked branches');
|
||||
if (updateGithub) {
|
||||
pushMessage(`Created new issue: ${newIssueUrl}`);
|
||||
pushMessage(`Created new issue: ${newIssue.html_url}`);
|
||||
}
|
||||
newlyCreatedIssues.push({ failure, newIssue });
|
||||
}
|
||||
|
||||
// mutates report to include messages and writes updated report to disk
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue