2021-03-08 18:12:59 +05:30
import { CI _CONFIG _STATUS _VALID } from '~/pipeline_editor/constants' ;
import { unwrapStagesWithNeeds } from '~/pipelines/components/unwrapping_utils' ;
export const mockProjectNamespace = 'user1' ;
export const mockProjectPath = 'project1' ;
export const mockProjectFullPath = ` ${ mockProjectNamespace } / ${ mockProjectPath } ` ;
2021-01-29 00:20:46 +05:30
export const mockDefaultBranch = 'master' ;
2021-02-22 17:27:13 +05:30
export const mockNewMergeRequestPath = '/-/merge_requests/new' ;
2021-03-08 18:12:59 +05:30
export const mockCommitSha = 'aabbccdd' ;
export const mockCommitNextSha = 'eeffgghh' ;
export const mockLintHelpPagePath = '/-/lint-help' ;
export const mockYmlHelpPagePath = '/-/yml-help' ;
2021-02-22 17:27:13 +05:30
export const mockCommitMessage = 'My commit message' ;
2021-01-29 00:20:46 +05:30
export const mockCiConfigPath = '.gitlab-ci.yml' ;
export const mockCiYml = `
2021-03-08 18:12:59 +05:30
stages :
- test
- build
job _test _1 :
2021-01-29 00:20:46 +05:30
stage : test
2021-03-08 18:12:59 +05:30
script :
- echo "test 1"
job _test _2 :
stage : test
script :
- echo "test 2"
job _build :
stage : build
script :
- echo "build"
needs : [ "job_test_2" ]
2021-01-29 00:20:46 +05:30
` ;
2021-02-22 17:27:13 +05:30
2021-03-08 18:12:59 +05:30
const mockJobFields = {
beforeScript : [ ] ,
afterScript : [ ] ,
environment : null ,
allowFailure : false ,
tags : [ ] ,
when : 'on_success' ,
only : { refs : [ 'branches' , 'tags' ] , _ _typename : 'CiJobLimitType' } ,
except : null ,
needs : { nodes : [ ] , _ _typename : 'CiConfigNeedConnection' } ,
_ _typename : 'CiConfigJob' ,
} ;
// Mock result of the graphql query at:
// app/assets/javascripts/pipeline_editor/graphql/queries/ci_config.graphql
2021-02-22 17:27:13 +05:30
export const mockCiConfigQueryResponse = {
data : {
ciConfig : {
errors : [ ] ,
2021-03-11 19:13:27 +05:30
mergedYaml : mockCiYml ,
2021-03-08 18:12:59 +05:30
status : CI _CONFIG _STATUS _VALID ,
stages : {
_ _typename : 'CiConfigStageConnection' ,
nodes : [
{
name : 'test' ,
groups : {
nodes : [
{
name : 'job_test_1' ,
size : 1 ,
jobs : {
nodes : [
{
name : 'job_test_1' ,
script : [ 'echo "test 1"' ] ,
... mockJobFields ,
} ,
] ,
_ _typename : 'CiConfigJobConnection' ,
} ,
_ _typename : 'CiConfigGroup' ,
} ,
{
name : 'job_test_2' ,
size : 1 ,
jobs : {
nodes : [
{
name : 'job_test_2' ,
script : [ 'echo "test 2"' ] ,
... mockJobFields ,
} ,
] ,
_ _typename : 'CiConfigJobConnection' ,
} ,
_ _typename : 'CiConfigGroup' ,
} ,
] ,
_ _typename : 'CiConfigGroupConnection' ,
} ,
_ _typename : 'CiConfigStage' ,
} ,
{
name : 'build' ,
groups : {
nodes : [
{
name : 'job_build' ,
size : 1 ,
jobs : {
nodes : [
{
name : 'job_build' ,
script : [ 'echo "build"' ] ,
... mockJobFields ,
} ,
] ,
_ _typename : 'CiConfigJobConnection' ,
} ,
_ _typename : 'CiConfigGroup' ,
} ,
] ,
_ _typename : 'CiConfigGroupConnection' ,
} ,
_ _typename : 'CiConfigStage' ,
} ,
] ,
} ,
_ _typename : 'CiConfig' ,
2021-02-22 17:27:13 +05:30
} ,
} ,
} ;
2021-03-08 18:12:59 +05:30
export const mergeUnwrappedCiConfig = ( mergedConfig ) => {
const { ciConfig } = mockCiConfigQueryResponse . data ;
return {
... ciConfig ,
stages : unwrapStagesWithNeeds ( ciConfig . stages . nodes ) ,
... mergedConfig ,
} ;
} ;
2021-02-22 17:27:13 +05:30
export const mockLintResponse = {
valid : true ,
2021-03-11 19:13:27 +05:30
mergedYaml : mockCiYml ,
status : CI _CONFIG _STATUS _VALID ,
2021-02-22 17:27:13 +05:30
errors : [ ] ,
warnings : [ ] ,
jobs : [
{
name : 'job_1' ,
stage : 'test' ,
before _script : [ "echo 'before script 1'" ] ,
script : [ "echo 'script 1'" ] ,
after _script : [ "echo 'after script 1" ] ,
tag _list : [ 'tag 1' ] ,
environment : 'prd' ,
when : 'on_success' ,
allow _failure : false ,
only : null ,
except : { refs : [ 'master@gitlab-org/gitlab' , '/^release/.*$/@gitlab-org/gitlab' ] } ,
} ,
{
name : 'job_2' ,
stage : 'test' ,
before _script : [ "echo 'before script 2'" ] ,
script : [ "echo 'script 2'" ] ,
after _script : [ "echo 'after script 2" ] ,
tag _list : [ 'tag 2' ] ,
environment : 'stg' ,
when : 'on_success' ,
allow _failure : true ,
only : { refs : [ 'web' , 'chat' , 'pushes' ] } ,
except : { refs : [ 'master@gitlab-org/gitlab' , '/^release/.*$/@gitlab-org/gitlab' ] } ,
} ,
] ,
} ;
export const mockJobs = [
{
name : 'job_1' ,
stage : 'build' ,
beforeScript : [ ] ,
script : [ "echo 'Building'" ] ,
afterScript : [ ] ,
tagList : [ ] ,
environment : null ,
when : 'on_success' ,
allowFailure : true ,
only : { refs : [ 'web' , 'chat' , 'pushes' ] } ,
except : null ,
} ,
{
name : 'multi_project_job' ,
stage : 'test' ,
beforeScript : [ ] ,
script : [ ] ,
afterScript : [ ] ,
tagList : [ ] ,
environment : null ,
when : 'on_success' ,
allowFailure : false ,
only : { refs : [ 'branches' , 'tags' ] } ,
except : null ,
} ,
{
name : 'job_2' ,
stage : 'test' ,
beforeScript : [ "echo 'before script'" ] ,
script : [ "echo 'script'" ] ,
afterScript : [ "echo 'after script" ] ,
tagList : [ ] ,
environment : null ,
when : 'on_success' ,
allowFailure : false ,
only : { refs : [ 'branches@gitlab-org/gitlab' ] } ,
except : { refs : [ 'master@gitlab-org/gitlab' , '/^release/.*$/@gitlab-org/gitlab' ] } ,
} ,
] ;
export const mockErrors = [
'"job_1 job: chosen stage does not exist; available stages are .pre, build, test, deploy, .post"' ,
] ;
export const mockWarnings = [
'"jobs:multi_project_job may allow multiple pipelines to run for a single action due to `rules:when` clause with no `workflow:rules` - read more: https://docs.gitlab.com/ee/ci/troubleshooting.html#pipeline-warnings"' ,
] ;