fix: show GitLab MR checks in sidebar (#3858)
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { gitLabPipelineJobsToPRChecks } from './gitlab-pipeline-checks'
|
||||
import type { GitLabPipelineJob } from './types'
|
||||
|
||||
describe('gitLabPipelineJobsToPRChecks', () => {
|
||||
it('maps GitLab pipeline jobs into right-panel check rows', () => {
|
||||
const jobs: GitLabPipelineJob[] = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'unit',
|
||||
stage: 'test',
|
||||
status: 'failed',
|
||||
webUrl: 'https://gitlab.com/acme/orca/-/jobs/1',
|
||||
duration: 12
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'deploy',
|
||||
stage: 'deploy',
|
||||
status: 'manual',
|
||||
webUrl: '',
|
||||
duration: null
|
||||
}
|
||||
]
|
||||
|
||||
expect(gitLabPipelineJobsToPRChecks(jobs)).toEqual([
|
||||
{
|
||||
name: 'test: unit',
|
||||
status: 'completed',
|
||||
conclusion: 'failure',
|
||||
url: 'https://gitlab.com/acme/orca/-/jobs/1'
|
||||
},
|
||||
{
|
||||
name: 'deploy: deploy',
|
||||
status: 'completed',
|
||||
conclusion: 'neutral',
|
||||
url: null
|
||||
}
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,56 @@
|
||||
import type { GitLabPipelineJob } from './gitlab-types'
|
||||
import type { PRCheckDetail } from './types'
|
||||
|
||||
export function mapGitLabPipelineJobStatusToCheckStatus(status: string): PRCheckDetail['status'] {
|
||||
const s = status.toLowerCase()
|
||||
if (s === 'created' || s === 'pending' || s === 'waiting_for_resource' || s === 'preparing') {
|
||||
return 'queued'
|
||||
}
|
||||
if (s === 'running') {
|
||||
return 'in_progress'
|
||||
}
|
||||
return 'completed'
|
||||
}
|
||||
|
||||
export function mapGitLabPipelineJobStatusToConclusion(
|
||||
status: string
|
||||
): PRCheckDetail['conclusion'] {
|
||||
const s = status.toLowerCase()
|
||||
if (s === 'success') {
|
||||
return 'success'
|
||||
}
|
||||
if (s === 'failed') {
|
||||
return 'failure'
|
||||
}
|
||||
if (s === 'canceled' || s === 'canceling') {
|
||||
return 'cancelled'
|
||||
}
|
||||
if (s === 'skipped') {
|
||||
return 'skipped'
|
||||
}
|
||||
// Why: manual GitLab jobs are intentionally waiting for a human trigger;
|
||||
// treating them as pending would make the Checks tab look stuck forever.
|
||||
if (s === 'manual') {
|
||||
return 'neutral'
|
||||
}
|
||||
if (
|
||||
s === 'created' ||
|
||||
s === 'pending' ||
|
||||
s === 'running' ||
|
||||
s === 'waiting_for_resource' ||
|
||||
s === 'preparing' ||
|
||||
s === 'scheduled'
|
||||
) {
|
||||
return 'pending'
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export function gitLabPipelineJobsToPRChecks(jobs: GitLabPipelineJob[]): PRCheckDetail[] {
|
||||
return jobs.map((job) => ({
|
||||
name: job.stage ? `${job.stage}: ${job.name}` : job.name,
|
||||
status: mapGitLabPipelineJobStatusToCheckStatus(job.status),
|
||||
conclusion: mapGitLabPipelineJobStatusToConclusion(job.status),
|
||||
url: job.webUrl || null
|
||||
}))
|
||||
}
|
||||
Reference in New Issue
Block a user