2023-03-04 22:38:38 +05:30
import { CI _CONFIG _STATUS _INVALID , CI _CONFIG _STATUS _VALID } from '~/ci/pipeline_editor/constants' ;
2021-03-08 18:12:59 +05:30
import { unwrapStagesWithNeeds } from '~/pipelines/components/unwrapping_utils' ;
export const mockProjectNamespace = 'user1' ;
export const mockProjectPath = 'project1' ;
export const mockProjectFullPath = ` ${ mockProjectNamespace } / ${ mockProjectPath } ` ;
2021-06-08 01:23:25 +05:30
export const mockDefaultBranch = 'main' ;
2021-09-04 01:27:46 +05:30
export const mockNewBranch = 'new-branch' ;
2021-02-22 17:27:13 +05:30
export const mockNewMergeRequestPath = '/-/merge_requests/new' ;
2022-08-13 15:12:31 +05:30
export const mockCiLintPath = '/-/ci/lint' ;
2021-03-08 18:12:59 +05:30
export const mockCommitSha = 'aabbccdd' ;
export const mockCommitNextSha = 'eeffgghh' ;
2022-07-16 23:28:13 +05:30
export const mockIncludesHelpPagePath = '/-/includes/help' ;
2021-03-08 18:12:59 +05:30
export const mockLintHelpPagePath = '/-/lint-help' ;
2022-03-02 08:16:31 +05:30
export const mockLintUnavailableHelpPagePath = '/-/pipeline-editor/troubleshoot' ;
2022-08-13 15:12:31 +05:30
export const mockSimulatePipelineHelpPagePath = '/-/simulate-pipeline-help' ;
2021-03-08 18:12:59 +05:30
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-12-11 22:18:48 +05:30
export const mockCiTemplateQueryResponse = {
data : {
project : {
2022-01-26 12:08:38 +05:30
id : 'project-1' ,
2021-12-11 22:18:48 +05:30
ciTemplate : {
content : mockCiYml ,
} ,
} ,
} ,
} ;
2021-09-30 23:02:18 +05:30
export const mockBlobContentQueryResponse = {
data : {
2022-01-26 12:08:38 +05:30
project : {
id : 'project-1' ,
repository : { blobs : { nodes : [ { id : 'blob-1' , rawBlob : mockCiYml } ] } } ,
} ,
2021-09-30 23:02:18 +05:30
} ,
} ;
export const mockBlobContentQueryResponseNoCiFile = {
data : {
2022-01-26 12:08:38 +05:30
project : { id : 'project-1' , repository : { blobs : { nodes : [ ] } } } ,
2021-09-30 23:02:18 +05:30
} ,
} ;
export const mockBlobContentQueryResponseEmptyCiFile = {
data : {
2022-01-26 12:08:38 +05:30
project : { id : 'project-1' , repository : { blobs : { nodes : [ { rawBlob : '' } ] } } } ,
2021-09-30 23:02:18 +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' ,
} ;
2022-07-16 23:28:13 +05:30
export const mockIncludesWithBlob = {
location : 'test-include.yml' ,
type : 'local' ,
blob :
'http://gdk.test:3000/root/upstream/-/blob/dd54f00bb3645f8ddce7665d2ffb3864540399cb/test-include.yml' ,
raw :
'http://gdk.test:3000/root/upstream/-/raw/dd54f00bb3645f8ddce7665d2ffb3864540399cb/test-include.yml' ,
_ _typename : 'CiConfigInclude' ,
} ;
export const mockDefaultIncludes = {
location : 'npm.gitlab-ci.yml' ,
type : 'template' ,
blob : null ,
raw :
'https://gitlab.com/gitlab-org/gitlab/-/raw/master/lib/gitlab/ci/templates/npm.gitlab-ci.yml' ,
_ _typename : 'CiConfigInclude' ,
} ;
export const mockIncludes = [
mockDefaultIncludes ,
mockIncludesWithBlob ,
{
location : 'a_really_really_long_name_for_includes_file.yml' ,
type : 'local' ,
blob :
'http://gdk.test:3000/root/upstream/-/blob/dd54f00bb3645f8ddce7665d2ffb3864540399cb/a_really_really_long_name_for_includes_file.yml' ,
raw :
'http://gdk.test:3000/root/upstream/-/raw/dd54f00bb3645f8ddce7665d2ffb3864540399cb/a_really_really_long_name_for_includes_file.yml' ,
_ _typename : 'CiConfigInclude' ,
} ,
] ;
2021-03-08 18:12:59 +05:30
// Mock result of the graphql query at:
2023-03-04 22:38:38 +05:30
// app/assets/javascripts/ci/pipeline_editor/graphql/queries/ci_config.graphql
2021-02-22 17:27:13 +05:30
export const mockCiConfigQueryResponse = {
data : {
ciConfig : {
errors : [ ] ,
2022-07-16 23:28:13 +05:30
includes : mockIncludes ,
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 : [
{
2022-01-26 12:08:38 +05:30
id : 'group-1' ,
2021-03-08 18:12:59 +05:30
name : 'job_test_1' ,
size : 1 ,
jobs : {
nodes : [
{
name : 'job_test_1' ,
script : [ 'echo "test 1"' ] ,
... mockJobFields ,
} ,
] ,
_ _typename : 'CiConfigJobConnection' ,
} ,
_ _typename : 'CiConfigGroup' ,
} ,
{
2022-01-26 12:08:38 +05:30
id : 'group-2' ,
2021-03-08 18:12:59 +05:30
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-11-11 11:23:49 +05:30
export const mockCommitShaResults = {
2021-09-30 23:02:18 +05:30
data : {
project : {
2022-01-26 12:08:38 +05:30
id : '1' ,
2021-11-11 11:23:49 +05:30
repository : {
tree : {
lastCommit : {
2022-01-26 12:08:38 +05:30
id : 'commit-1' ,
2021-11-11 11:23:49 +05:30
sha : mockCommitSha ,
2021-09-30 23:02:18 +05:30
} ,
2021-11-11 11:23:49 +05:30
} ,
} ,
} ,
} ,
} ;
export const mockNewCommitShaResults = {
data : {
project : {
2022-01-26 12:08:38 +05:30
id : '1' ,
2021-11-11 11:23:49 +05:30
repository : {
tree : {
lastCommit : {
2022-01-26 12:08:38 +05:30
id : 'commit-1' ,
2021-11-11 11:23:49 +05:30
sha : 'eeff1122' ,
2021-09-30 23:02:18 +05:30
} ,
2021-11-11 11:23:49 +05:30
} ,
} ,
} ,
} ,
} ;
export const mockEmptyCommitShaResults = {
data : {
project : {
2022-01-26 12:08:38 +05:30
id : '1' ,
2021-11-11 11:23:49 +05:30
repository : {
tree : {
lastCommit : {
2022-01-26 12:08:38 +05:30
id : 'commit-1' ,
2021-11-11 11:23:49 +05:30
sha : '' ,
2021-09-30 23:02:18 +05:30
} ,
2021-11-11 11:23:49 +05:30
} ,
2021-09-30 23:02:18 +05:30
} ,
} ,
} ,
} ;
2021-04-29 21:17:54 +05:30
export const mockProjectBranches = {
2021-06-08 01:23:25 +05:30
data : {
project : {
2022-01-26 12:08:38 +05:30
id : '1' ,
2021-06-08 01:23:25 +05:30
repository : {
branchNames : [
'main' ,
'develop' ,
'production' ,
'test' ,
'better-feature' ,
'feature-abc' ,
'update-ci' ,
'mock-feature' ,
'test-merge-request' ,
'staging' ,
] ,
} ,
} ,
2021-04-29 21:17:54 +05:30
} ,
} ;
2021-06-08 01:23:25 +05:30
export const mockTotalBranchResults =
mockProjectBranches . data . project . repository . branchNames . length ;
export const mockSearchBranches = {
data : {
project : {
2022-01-26 12:08:38 +05:30
id : '1' ,
2021-06-08 01:23:25 +05:30
repository : {
branchNames : [ 'test' , 'better-feature' , 'update-ci' , 'test-merge-request' ] ,
} ,
} ,
} ,
} ;
export const mockTotalSearchResults = mockSearchBranches . data . project . repository . branchNames . length ;
export const mockEmptySearchBranches = {
data : {
project : {
2022-01-26 12:08:38 +05:30
id : '1' ,
2021-06-08 01:23:25 +05:30
repository : {
branchNames : [ ] ,
} ,
} ,
} ,
} ;
export const mockBranchPaginationLimit = 10 ;
export const mockTotalBranches = 20 ; // must be greater than mockBranchPaginationLimit to test pagination
2021-11-18 22:05:49 +05:30
export const mockProjectPipeline = ( { hasStages = true } = { } ) => {
const stages = hasStages
? {
edges : [
{
node : {
id : 'gid://gitlab/Ci::Stage/605' ,
name : 'prepare' ,
status : 'success' ,
detailedStatus : {
detailsPath : '/root/sample-ci-project/-/pipelines/268#prepare' ,
group : 'success' ,
hasDetails : true ,
icon : 'status_success' ,
id : 'success-605-605' ,
label : 'passed' ,
text : 'passed' ,
tooltip : 'passed' ,
} ,
} ,
} ,
] ,
}
: null ;
return {
2022-01-26 12:08:38 +05:30
id : '1' ,
2021-11-18 22:05:49 +05:30
pipeline : {
id : 'gid://gitlab/Ci::Pipeline/118' ,
iid : '28' ,
shortSha : mockCommitSha ,
status : 'SUCCESS' ,
2021-12-11 22:18:48 +05:30
commit : {
2022-01-26 12:08:38 +05:30
id : 'commit-1' ,
2021-12-11 22:18:48 +05:30
title : 'Update .gitlabe-ci.yml' ,
webPath : '/-/commit/aabbccdd' ,
} ,
2021-11-18 22:05:49 +05:30
detailedStatus : {
2022-01-26 12:08:38 +05:30
id : 'status-1' ,
2021-11-18 22:05:49 +05:30
detailsPath : '/root/sample-ci-project/-/pipelines/118' ,
group : 'success' ,
icon : 'status_success' ,
text : 'passed' ,
} ,
stages ,
2021-04-17 20:07:23 +05:30
} ,
2021-11-18 22:05:49 +05:30
} ;
2021-04-17 20:07:23 +05:30
} ;
2021-12-11 22:18:48 +05:30
export const mockLinkedPipelines = ( { hasDownstream = true , hasUpstream = true } = { } ) => {
let upstream = null ;
let downstream = {
nodes : [ ] ,
_ _typename : 'PipelineConnection' ,
} ;
if ( hasDownstream ) {
downstream = {
nodes : [
{
id : 'gid://gitlab/Ci::Pipeline/612' ,
path : '/root/job-log-sections/-/pipelines/612' ,
2023-04-23 21:23:45 +05:30
project : {
id : 'gid://gitlab/Project/21' ,
name : 'job-log-sections' ,
_ _typename : 'Project' ,
} ,
detailedStatus : {
id : 'success-612-612' ,
group : 'success' ,
icon : 'status_success' ,
label : 'passed' ,
_ _typename : 'DetailedStatus' ,
} ,
sourceJob : {
id : 'gid://gitlab/Ci::Bridge/532' ,
retried : false ,
} ,
_ _typename : 'Pipeline' ,
} ,
{
id : 'gid://gitlab/Ci::Pipeline/611' ,
path : '/root/job-log-sections/-/pipelines/611' ,
project : {
id : 'gid://gitlab/Project/21' ,
name : 'job-log-sections' ,
_ _typename : 'Project' ,
} ,
2021-12-11 22:18:48 +05:30
detailedStatus : {
2023-04-23 21:23:45 +05:30
id : 'success-611-611' ,
2021-12-11 22:18:48 +05:30
group : 'success' ,
icon : 'status_success' ,
label : 'passed' ,
_ _typename : 'DetailedStatus' ,
} ,
2023-04-23 21:23:45 +05:30
sourceJob : {
id : 'gid://gitlab/Ci::Bridge/531' ,
retried : true ,
} ,
_ _typename : 'Pipeline' ,
} ,
{
id : 'gid://gitlab/Ci::Pipeline/609' ,
path : '/root/job-log-sections/-/pipelines/609' ,
project : {
id : 'gid://gitlab/Project/21' ,
name : 'job-log-sections' ,
_ _typename : 'Project' ,
} ,
detailedStatus : {
id : 'success-609-609' ,
group : 'success' ,
icon : 'status_success' ,
label : 'passed' ,
_ _typename : 'DetailedStatus' ,
} ,
sourceJob : {
id : 'gid://gitlab/Ci::Bridge/530' ,
retried : true ,
} ,
2021-12-11 22:18:48 +05:30
_ _typename : 'Pipeline' ,
} ,
] ,
_ _typename : 'PipelineConnection' ,
} ;
}
if ( hasUpstream ) {
upstream = {
id : 'gid://gitlab/Ci::Pipeline/610' ,
path : '/root/trigger-downstream/-/pipelines/610' ,
2023-04-23 21:23:45 +05:30
project : {
id : 'gid://gitlab/Project/21' ,
name : 'trigger-downstream' ,
_ _typename : 'Project' ,
} ,
2021-12-11 22:18:48 +05:30
detailedStatus : {
2023-04-23 21:23:45 +05:30
id : 'success-610-610' ,
2021-12-11 22:18:48 +05:30
group : 'success' ,
icon : 'status_success' ,
label : 'passed' ,
_ _typename : 'DetailedStatus' ,
} ,
_ _typename : 'Pipeline' ,
} ;
}
return {
data : {
project : {
2023-04-23 21:23:45 +05:30
id : 'gid://gitlab/Project/21' ,
2021-12-11 22:18:48 +05:30
pipeline : {
2023-04-23 21:23:45 +05:30
id : 'gid://gitlab/Ci::Pipeline/790' ,
2021-12-11 22:18:48 +05:30
path : '/root/ci-project/-/pipelines/790' ,
downstream ,
upstream ,
} ,
_ _typename : 'Project' ,
} ,
} ,
} ;
} ;
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 ,
2021-06-08 01:23:25 +05:30
except : { refs : [ 'main@gitlab-org/gitlab' , '/^release/.*$/@gitlab-org/gitlab' ] } ,
2021-02-22 17:27:13 +05:30
} ,
{
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-06-08 01:23:25 +05:30
except : { refs : [ 'main@gitlab-org/gitlab' , '/^release/.*$/@gitlab-org/gitlab' ] } ,
2021-02-22 17:27:13 +05:30
} ,
] ,
} ;
2021-12-11 22:18:48 +05:30
export const mockLintResponseWithoutMerged = {
valid : false ,
status : CI _CONFIG _STATUS _INVALID ,
errors : [ 'error' ] ,
warnings : [ ] ,
jobs : [ ] ,
} ;
2021-02-22 17:27:13 +05:30
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-06-08 01:23:25 +05:30
except : { refs : [ 'main@gitlab-org/gitlab' , '/^release/.*$/@gitlab-org/gitlab' ] } ,
2021-02-22 17:27:13 +05:30
} ,
] ;
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"' ,
] ;
2022-01-26 12:08:38 +05:30
export const mockCommitCreateResponse = {
data : {
commitCreate : {
_ _typename : 'CommitCreatePayload' ,
errors : [ ] ,
commit : {
_ _typename : 'Commit' ,
id : 'commit-1' ,
sha : mockCommitNextSha ,
} ,
commitPipelinePath : '' ,
} ,
} ,
} ;
export const mockCommitCreateResponseNewEtag = {
data : {
commitCreate : {
_ _typename : 'CommitCreatePayload' ,
errors : [ ] ,
commit : {
_ _typename : 'Commit' ,
id : 'commit-2' ,
sha : mockCommitNextSha ,
} ,
commitPipelinePath : '/api/graphql:pipelines/sha/550ceace1acd373c84d02bd539cb9d4614f786db' ,
} ,
} ,
} ;