2020-12-22 15:09:51 +00:00
import { CI _CONFIG _STATUS _VALID } from '~/pipeline_editor/constants' ;
2021-01-06 21:10:18 +00:00
import { unwrapStagesWithNeeds } from '~/pipelines/components/unwrapping_utils' ;
2020-12-22 15:09:51 +00:00
2021-01-09 00:10:30 +00:00
export const mockProjectNamespace = 'user1' ;
export const mockProjectPath = 'project1' ;
export const mockProjectFullPath = ` ${ mockProjectNamespace } / ${ mockProjectPath } ` ;
2021-05-04 18:10:03 +00:00
export const mockDefaultBranch = 'main' ;
2021-06-15 18:09:57 +00:00
export const mockNewBranch = 'new-branch' ;
2020-11-20 21:09:12 +00:00
export const mockNewMergeRequestPath = '/-/merge_requests/new' ;
2020-12-22 12:10:09 +00:00
export const mockCommitSha = 'aabbccdd' ;
export const mockCommitNextSha = 'eeffgghh' ;
2020-12-22 15:09:51 +00:00
export const mockLintHelpPagePath = '/-/lint-help' ;
2021-01-06 21:10:18 +00:00
export const mockYmlHelpPagePath = '/-/yml-help' ;
2020-11-20 21:09:12 +00:00
export const mockCommitMessage = 'My commit message' ;
2020-10-30 21:08:52 +00:00
export const mockCiConfigPath = '.gitlab-ci.yml' ;
export const mockCiYml = `
2020-12-22 15:09:51 +00:00
stages :
- test
- build
job _test _1 :
2020-10-30 21:08:52 +00:00
stage : test
2020-12-22 15:09:51 +00:00
script :
- echo "test 1"
job _test _2 :
stage : test
script :
- echo "test 2"
job _build :
stage : build
2021-01-14 12:10:54 +00:00
script :
2020-12-22 15:09:51 +00:00
- echo "build"
needs : [ "job_test_2" ]
2020-10-30 21:08:52 +00:00
` ;
2021-06-23 18:07:10 +00:00
export const mockBlobContentQueryResponse = {
data : {
project : { repository : { blobs : { nodes : [ { rawBlob : mockCiYml } ] } } } ,
} ,
} ;
export const mockBlobContentQueryResponseNoCiFile = {
data : {
project : { repository : { blobs : { nodes : [ ] } } } ,
} ,
} ;
export const mockBlobContentQueryResponseEmptyCiFile = {
data : {
project : { repository : { blobs : { nodes : [ { rawBlob : '' } ] } } } ,
} ,
} ;
2020-11-27 12:09:14 +00:00
2021-01-13 15:10:40 +00:00
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
2020-12-08 21:10:06 +00:00
export const mockCiConfigQueryResponse = {
data : {
ciConfig : {
errors : [ ] ,
2021-02-12 18:08:59 +00:00
mergedYaml : mockCiYml ,
2020-12-22 15:09:51 +00:00
status : CI _CONFIG _STATUS _VALID ,
stages : {
_ _typename : 'CiConfigStageConnection' ,
nodes : [
{
name : 'test' ,
groups : {
nodes : [
{
name : 'job_test_1' ,
2021-01-12 21:10:47 +00:00
size : 1 ,
2020-12-22 15:09:51 +00:00
jobs : {
nodes : [
{
name : 'job_test_1' ,
2021-01-13 15:10:40 +00:00
script : [ 'echo "test 1"' ] ,
... mockJobFields ,
2020-12-22 15:09:51 +00:00
} ,
] ,
_ _typename : 'CiConfigJobConnection' ,
} ,
_ _typename : 'CiConfigGroup' ,
} ,
{
name : 'job_test_2' ,
2021-01-12 21:10:47 +00:00
size : 1 ,
2020-12-22 15:09:51 +00:00
jobs : {
nodes : [
{
name : 'job_test_2' ,
2021-01-13 15:10:40 +00:00
script : [ 'echo "test 2"' ] ,
... mockJobFields ,
2020-12-22 15:09:51 +00:00
} ,
] ,
_ _typename : 'CiConfigJobConnection' ,
} ,
_ _typename : 'CiConfigGroup' ,
} ,
] ,
_ _typename : 'CiConfigGroupConnection' ,
} ,
_ _typename : 'CiConfigStage' ,
} ,
{
name : 'build' ,
groups : {
nodes : [
{
name : 'job_build' ,
2021-01-12 21:10:47 +00:00
size : 1 ,
2020-12-22 15:09:51 +00:00
jobs : {
nodes : [
{
name : 'job_build' ,
2021-01-13 15:10:40 +00:00
script : [ 'echo "build"' ] ,
... mockJobFields ,
2020-12-22 15:09:51 +00:00
} ,
] ,
_ _typename : 'CiConfigJobConnection' ,
} ,
_ _typename : 'CiConfigGroup' ,
} ,
] ,
_ _typename : 'CiConfigGroupConnection' ,
} ,
_ _typename : 'CiConfigStage' ,
} ,
] ,
} ,
_ _typename : 'CiConfig' ,
2020-12-08 21:10:06 +00:00
} ,
} ,
} ;
2021-01-06 21:10:18 +00:00
export const mergeUnwrappedCiConfig = ( mergedConfig ) => {
const { ciConfig } = mockCiConfigQueryResponse . data ;
return {
... ciConfig ,
stages : unwrapStagesWithNeeds ( ciConfig . stages . nodes ) ,
... mergedConfig ,
} ;
} ;
2021-08-20 12:09:31 +00:00
export const mockCommitShaResults = {
2021-07-12 12:09:39 +00:00
data : {
project : {
pipelines : {
nodes : [
{
id : 'gid://gitlab/Ci::Pipeline/1' ,
2021-08-20 12:09:31 +00:00
sha : mockCommitSha ,
2021-07-12 12:09:39 +00:00
path : ` / ${ mockProjectFullPath } /-/pipelines/488 ` ,
2021-08-26 03:09:01 +00:00
commitPath : ` / ${ mockProjectFullPath } /-/commit/d0d56d363d8a3f67a8ab9fc00207d468f30032ca ` ,
} ,
] ,
} ,
} ,
} ,
} ;
export const mockNewCommitShaResults = {
data : {
project : {
pipelines : {
nodes : [
{
id : 'gid://gitlab/Ci::Pipeline/2' ,
sha : 'eeff1122' ,
path : ` / ${ mockProjectFullPath } /-/pipelines/489 ` ,
commitPath : ` / ${ mockProjectFullPath } /-/commit/bb1abcfe3d8a3f67a8ab9fc00207d468f3022bee ` ,
} ,
{
id : 'gid://gitlab/Ci::Pipeline/1' ,
sha : mockCommitSha ,
path : ` / ${ mockProjectFullPath } /-/pipelines/488 ` ,
2021-07-12 12:09:39 +00:00
commitPath : ` / ${ mockProjectFullPath } /-/commit/d0d56d363d8a3f67a8ab9fc00207d468f30032ca ` ,
} ,
] ,
} ,
} ,
} ,
} ;
2021-08-20 12:09:31 +00:00
export const mockEmptyCommitShaResults = {
data : {
project : {
pipelines : {
nodes : [ ] ,
} ,
} ,
} ,
} ;
2021-04-09 18:09:24 +00:00
export const mockProjectBranches = {
2021-05-13 18:10:32 +00:00
data : {
project : {
repository : {
branchNames : [
'main' ,
'develop' ,
'production' ,
'test' ,
'better-feature' ,
'feature-abc' ,
'update-ci' ,
'mock-feature' ,
'test-merge-request' ,
'staging' ,
] ,
} ,
} ,
2021-04-09 18:09:24 +00:00
} ,
} ;
2021-05-13 18:10:32 +00:00
export const mockTotalBranchResults =
mockProjectBranches . data . project . repository . branchNames . length ;
export const mockSearchBranches = {
data : {
project : {
repository : {
branchNames : [ 'test' , 'better-feature' , 'update-ci' , 'test-merge-request' ] ,
} ,
} ,
} ,
} ;
export const mockTotalSearchResults = mockSearchBranches . data . project . repository . branchNames . length ;
export const mockEmptySearchBranches = {
data : {
project : {
repository : {
branchNames : [ ] ,
} ,
} ,
} ,
} ;
export const mockBranchPaginationLimit = 10 ;
export const mockTotalBranches = 20 ; // must be greater than mockBranchPaginationLimit to test pagination
2021-02-18 12:09:34 +00:00
export const mockProjectPipeline = {
pipeline : {
commitPath : '/-/commit/aabbccdd' ,
id : 'gid://gitlab/Ci::Pipeline/118' ,
iid : '28' ,
shortSha : mockCommitSha ,
status : 'SUCCESS' ,
detailedStatus : {
detailsPath : '/root/sample-ci-project/-/pipelines/118"' ,
group : 'success' ,
icon : 'status_success' ,
text : 'passed' ,
} ,
} ,
} ;
2020-11-27 12:09:14 +00:00
export const mockLintResponse = {
valid : true ,
2021-02-12 18:08:59 +00:00
mergedYaml : mockCiYml ,
status : CI _CONFIG _STATUS _VALID ,
2020-11-27 12:09:14 +00:00
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 ,
2021-05-04 18:10:03 +00:00
except : { refs : [ 'main@gitlab-org/gitlab' , '/^release/.*$/@gitlab-org/gitlab' ] } ,
2020-11-27 12:09:14 +00:00
} ,
{
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' ] } ,
2021-05-04 18:10:03 +00:00
except : { refs : [ 'main@gitlab-org/gitlab' , '/^release/.*$/@gitlab-org/gitlab' ] } ,
2020-11-27 12:09:14 +00:00
} ,
] ,
} ;
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' ] } ,
2021-05-04 18:10:03 +00:00
except : { refs : [ 'main@gitlab-org/gitlab' , '/^release/.*$/@gitlab-org/gitlab' ] } ,
2020-11-27 12:09:14 +00:00
} ,
] ;
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"' ,
] ;