Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gitlab-ci): ref add logic for updating non top level
include
s (#…
…16819) Co-authored-by: Fred Rondina <fred.rondina@daveramsey.com> Co-authored-by: Michael Kriese <michael.kriese@visualon.de> Co-authored-by: Rhys Arkins <rhys@arkins.net>
- Loading branch information
1 parent
24691ac
commit 21ff27d
Showing
9 changed files
with
237 additions
and
30 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
lib/modules/manager/gitlabci-include/__fixtures__/gitlab-ci.4.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
include: | ||
- project: mikebryant/include-source-example | ||
file: /template.yaml | ||
ref: 1.0.0 | ||
|
||
trigger-my-job: | ||
extends: .extend-trigger-job | ||
trigger: | ||
include: | ||
- project: mikebryant/include-source-example | ||
file: /template.yaml | ||
ref: master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { load } from 'js-yaml'; | ||
import { Fixtures } from '../../../../test/fixtures'; | ||
import type { GitlabPipeline } from '../gitlabci/types'; | ||
import { replaceReferenceTags } from '../gitlabci/utils'; | ||
import { | ||
filterIncludeFromGitlabPipeline, | ||
isGitlabIncludeLocal, | ||
isGitlabIncludeProject, | ||
isNonEmptyObject, | ||
} from './common'; | ||
|
||
const yamlFileMultiConfig = Fixtures.get('gitlab-ci.1.yaml'); | ||
const pipeline = load( | ||
replaceReferenceTags(yamlFileMultiConfig) | ||
) as GitlabPipeline; | ||
const includeLocal = { local: 'something' }; | ||
const includeProject = { project: 'something' }; | ||
|
||
describe('modules/manager/gitlabci-include/common', () => { | ||
describe('filterIncludeFromGitlabPipeline()', () => { | ||
it('returns GitlabPipeline without top level include key', () => { | ||
expect(pipeline).toHaveProperty('include'); | ||
const filtered_pipeline = filterIncludeFromGitlabPipeline(pipeline); | ||
expect(filtered_pipeline).not.toHaveProperty('include'); | ||
expect(filtered_pipeline).toEqual({ | ||
script: [null, null], | ||
}); | ||
}); | ||
}); | ||
|
||
describe('isGitlabIncludeLocal()', () => { | ||
it('returns true if GitlabInclude is GitlabIncludeLocal', () => { | ||
expect(isGitlabIncludeLocal(includeLocal)).toBe(true); | ||
}); | ||
|
||
it('returns false if GitlabInclude is not GitlabIncludeLocal', () => { | ||
expect(isGitlabIncludeLocal(includeProject)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('isGitlabIncludeProject()', () => { | ||
it('returns true if GitlabInclude is GitlabIncludeProject', () => { | ||
expect(isGitlabIncludeProject(includeProject)).toBe(true); | ||
}); | ||
|
||
it('returns false if GitlabInclude is not GitlabIncludeProject', () => { | ||
expect(isGitlabIncludeProject(includeLocal)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('isNonEmptyObject()', () => { | ||
it('returns true if not empty', () => { | ||
expect(isNonEmptyObject({ attribute1: 1 })).toBe(true); | ||
}); | ||
|
||
it('returns false if empty', () => { | ||
expect(isNonEmptyObject({})).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import is from '@sindresorhus/is'; | ||
import type { | ||
GitlabInclude, | ||
GitlabIncludeLocal, | ||
GitlabIncludeProject, | ||
GitlabPipeline, | ||
} from '../gitlabci/types'; | ||
|
||
export function isNonEmptyObject(obj: any): boolean { | ||
return is.object(obj) && Object.keys(obj).length !== 0; | ||
} | ||
|
||
export function filterIncludeFromGitlabPipeline( | ||
pipeline: GitlabPipeline | ||
): GitlabPipeline { | ||
const pipeline_without_include = {} as GitlabPipeline; | ||
for (const key of Object.keys(pipeline).filter((key) => key !== 'include')) { | ||
const pipeline_key = key as keyof typeof pipeline; | ||
pipeline_without_include[pipeline_key] = pipeline[pipeline_key]; | ||
} | ||
return pipeline_without_include; | ||
} | ||
|
||
export function isGitlabIncludeProject( | ||
include: GitlabInclude | ||
): include is GitlabIncludeProject { | ||
return !is.undefined((include as GitlabIncludeProject).project); | ||
} | ||
|
||
export function isGitlabIncludeLocal( | ||
include: GitlabInclude | ||
): include is GitlabIncludeLocal { | ||
return !is.undefined((include as GitlabIncludeLocal).local); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { isGitlabIncludeLocal } from './common'; | ||
|
||
const includeLocal = { local: 'something' }; | ||
const includeProject = { project: 'something' }; | ||
|
||
describe('modules/manager/gitlabci/common', () => { | ||
describe('isGitlabIncludeLocal()', () => { | ||
it('returns true if GitlabInclude is GitlabIncludeLocal', () => { | ||
expect(isGitlabIncludeLocal(includeLocal)).toBe(true); | ||
}); | ||
|
||
it('returns false if GitlabInclude is not GitlabIncludeLocal', () => { | ||
expect(isGitlabIncludeLocal(includeProject)).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import is from '@sindresorhus/is'; | ||
import type { GitlabInclude, GitlabIncludeLocal } from '../gitlabci/types'; | ||
|
||
export function isGitlabIncludeLocal( | ||
include: GitlabInclude | ||
): include is GitlabIncludeLocal { | ||
return !is.undefined((include as GitlabIncludeLocal).local); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters