Skip to content

Commit

Permalink
feat: Add some columns to test_table
Browse files Browse the repository at this point in the history
  • Loading branch information
Kesin11 committed Jul 21, 2020
1 parent 528bc59 commit 9a4bed1
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 41 deletions.
3 changes: 3 additions & 0 deletions src/analyzer/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export type TestReport = {
workflowRunId: string
buildNumber: number
workflowName: string
createdAt: Date,
branch: string,
service: string,
testSuites: TestSuites
status: TestStatus // = testSuites.failures > 0: 'FAILURE', else: 'SUCCESS'
successCount: 0 | 1 // = testSuites.failures > 0: 1, else: 1. For create average success rate in dashboard
Expand Down
37 changes: 17 additions & 20 deletions src/analyzer/circleci_analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,7 @@ export class CircleciAnalyzer implements Analyzer {
}
}

async createTestReports( workflowRun: WorkflowRun, jobs: SingleBuildResponse[], tests: TestResponse[]): Promise<TestReport[]> {
const sortedJobs = sortBy(jobs, 'build_num')
const firstJob = first(sortedJobs)!
const lastJob = last(sortedJobs)!
const repository = `${firstJob.username}/${firstJob.reponame}`
const { workflowName, workflowId, buildNumber, workflowRunId }
= this.createWorkflowParams(workflowRun.workflow_name, repository, lastJob.build_num)

async createTestReports( workflowReport: WorkflowReport, jobs: SingleBuildResponse[], tests: TestResponse[]): Promise<TestReport[]> {
const testSuiteList: TestSuite[] = tests
.filter((test) => test.tests.length > 0)
.map((test) => {
Expand All @@ -168,31 +161,35 @@ export class CircleciAnalyzer implements Analyzer {
skipped: (test.result === 'skipped') ? [{ message: test.message }] : undefined,
}
})
const testJob = jobs.find((job) => job.build_num === test.run_id)
return {
name: jobs.find((job) => job.build_num === test.run_id)?.workflows.job_name ?? '',
name: testJob?.workflows.job_name ?? '',
time: secRound(sumBy(testCases, 'time')),
tests: testCases.length,
failures: testCases.filter((testcase) => testcase.failure !== undefined).length,
skipped: testCases.filter((testcase) => testcase.skipped !== undefined).length,
timestamp: firstJob.start_time,
timestamp: testJob?.start_time,
testcase: testCases,
}
})

if (testSuiteList.length === 0 ) return []

const testSuites = {
name: workflowName,
time: secRound(sumBy(testSuiteList, 'time')),
tests: sumBy(testSuiteList, 'tests'),
failures: sumBy(testSuiteList, 'failures'),
testsuite: testSuiteList,
}
name: workflowReport.workflowName,
time: secRound(sumBy(testSuiteList, 'time')),
tests: sumBy(testSuiteList, 'tests'),
failures: sumBy(testSuiteList, 'failures'),
testsuite: testSuiteList,
}
return [{
workflowId,
workflowRunId,
buildNumber,
workflowName,
workflowId: workflowReport.workflowId,
workflowRunId: workflowReport.workflowRunId,
buildNumber: workflowReport.buildNumber,
workflowName: workflowReport.workflowName,
createdAt: workflowReport.createdAt,
branch: workflowReport.branch,
service: workflowReport.service,
testSuites,
status: (testSuites.failures > 0) ? 'FAILURE' : 'SUCCESS',
successCount: (testSuites.failures > 0) ? 0 : 1,
Expand Down
18 changes: 9 additions & 9 deletions src/analyzer/github_analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ export class GithubAnalyzer implements Analyzer {
}
}

async createTestReports(workflowName: string, workflow: WorkflowRunsItem, junitArtifacts: Artifact[]): Promise<TestReport[]> {
const { workflowId, buildNumber, workflowRunId }
= this.createWorkflowParams(workflowName, workflow)

async createTestReports(workflowReport: WorkflowReport, junitArtifacts: Artifact[]): Promise<TestReport[]> {
const testReports: TestReport[] = []
for (const artifact of junitArtifacts) {
const xmlString = Buffer.from(artifact.data).toString('utf8')
Expand All @@ -157,18 +154,21 @@ export class GithubAnalyzer implements Analyzer {
const testSuites = ('testsuite' in result) ? result : {
// Fill in testsuites property with testsuit values.
testsuite: [result],
name: workflowId,
name: workflowReport.workflowId,
time: result.time,
tests: result.tests,
failures: result.failures,
errors: result.errors,
}

testReports.push({
workflowId,
workflowRunId,
buildNumber,
workflowName,
workflowId: workflowReport.workflowId,
workflowRunId: workflowReport.workflowRunId,
buildNumber: workflowReport.buildNumber,
workflowName: workflowReport.workflowName,
createdAt: workflowReport.createdAt,
branch: workflowReport.branch,
service: workflowReport.service,
testSuites,
status: (testSuites.failures && testSuites.failures > 0) ? 'FAILURE' : 'SUCCESS',
successCount: (testSuites.failures && testSuites.failures > 0) ? 0 : 1,
Expand Down
18 changes: 9 additions & 9 deletions src/analyzer/jenkins_analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@ export class JenkinsAnalyzer implements Analyzer {
}
}

async createTestReports(jobName: string, run: WfapiRunResponse, junitArtifacts: Artifact[]): Promise<TestReport[]> {
const { workflowName, workflowId, buildNumber, workflowRunId }
= this.createWorkflowParams(jobName, run.id)

async createTestReports(workflowReport: WorkflowReport, junitArtifacts: Artifact[]): Promise<TestReport[]> {
const testReports: TestReport[] = []
for (const artifact of junitArtifacts) {
const xmlString = Buffer.from(artifact.data).toString('utf8')
Expand All @@ -149,18 +146,21 @@ export class JenkinsAnalyzer implements Analyzer {
const testSuites = ('testsuite' in result) ? result : {
// Fill in testsuites property with testsuit values.
testsuite: [result],
name: workflowId,
name: workflowReport.workflowId,
time: result.time,
tests: result.tests,
failures: result.failures,
errors: result.errors,
}

testReports.push({
workflowId,
workflowRunId,
buildNumber,
workflowName,
workflowId: workflowReport.workflowId,
workflowRunId: workflowReport.workflowRunId,
buildNumber: workflowReport.buildNumber,
workflowName: workflowReport.workflowName,
createdAt: workflowReport.createdAt,
branch: workflowReport.branch,
service: workflowReport.service,
testSuites,
status: (testSuites.failures && testSuites.failures > 0) ? 'FAILURE' : 'SUCCESS',
successCount: (testSuites.failures && testSuites.failures > 0) ? 0 : 1,
Expand Down
2 changes: 1 addition & 1 deletion src/runner/circleci_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class CircleciRunner implements Runner {
)
}))
const workflowReport = this.analyzer.createWorkflowReport(workflowRun, jobs, tagMap)
const testReports = await this.analyzer.createTestReports(workflowRun, jobs, tests)
const testReports = await this.analyzer.createTestReports(workflowReport, jobs, tests)

repoWorkflowReports.push(workflowReport)
repoTestReports = repoTestReports.concat(testReports)
Expand Down
2 changes: 1 addition & 1 deletion src/runner/github_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class GithubRunner implements Runner {
const jobs = await this.client.fetchJobs(repo.owner, repo.repo, workflowRun.run.id)
const tests = await this.client.fetchTests(repo.owner, repo.repo, workflowRun.run.id, repo.testGlob)
const workflowReport = this.analyzer.createWorkflowReport(workflowRun.name, workflowRun.run, jobs, tagMap)
const testReports = await this.analyzer.createTestReports(workflowRun.name, workflowRun.run, tests)
const testReports = await this.analyzer.createTestReports(workflowReport, tests)

repoWorkflowReports.push(workflowReport)
repoTestReports = repoTestReports.concat(testReports)
Expand Down
2 changes: 1 addition & 1 deletion src/runner/jenkins_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class JenkinsRunner implements Runner {
const build = await this.client.fetchBuild(configJob.name, Number(run.id))
const tests = await this.client.fetchTests(build, configJob.testGlob)
const report = this.analyzer.createWorkflowReport(configJob.name, run, build)
const testReports = await this.analyzer.createTestReports(configJob.name, run, tests)
const testReports = await this.analyzer.createTestReports(report, tests)

jobReports.push(report)
jobTestReports = jobTestReports.concat(testReports)
Expand Down

0 comments on commit 9a4bed1

Please sign in to comment.