Skip to content

Commit 5c870cc

Browse files
committed
Add support for artifacts.reports.annotations property with string | string[] type.
1 parent d1602ed commit 5c870cc

File tree

10 files changed

+58
-8
lines changed

10 files changed

+58
-8
lines changed

.changeset/annotations-support.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@noxify/gitlab-ci-builder": patch
3+
---
4+
5+
Add support for `artifacts.reports.annotations` property with `string | string[]` type. Import now intelligently normalizes single-element arrays to strings for cleaner generated code.

.changeset/fancy-socks-watch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@noxify/gitlab-ci-builder": patch
33
---
44

5-
string support for `extends`
5+
Add support for `extends` as both `string` and `string[]`. Single extends are optimized to string format in generated code for better readability.

.changeset/floppy-ants-tell.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@noxify/gitlab-ci-builder": patch
33
---
44

5-
exclude anchor definitions without a valid job definition
5+
Improve YAML anchor handling by filtering out anchor definitions that don't contain valid job objects. This prevents type errors when importing GitLab CI files with pure anchor arrays.

.changeset/gentle-olives-retire.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@noxify/gitlab-ci-builder": patch
33
---
44

5-
support `string` and `string[]` in `artifacts.reports.dotenv`
5+
Add support for `artifacts.reports.dotenv` property with `string | string[]` type. Import now intelligently normalizes single-element arrays to strings for cleaner generated code.

.changeset/lovely-showers-film.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@noxify/gitlab-ci-builder": patch
33
---
44

5-
support also `string[]` in `rules.exists`
5+
Add support for `rules.exists` property with `string | string[]` type to match GitLab CI specification.

.changeset/plenty-tigers-cheat.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@noxify/gitlab-ci-builder": patch
33
---
44

5-
fixed issue in the generated ts code for the importer
5+
Fix import code generation to properly handle single-element arrays for properties like `extends`, optimizing output format for better code readability.

.changeset/tough-rings-laugh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@noxify/gitlab-ci-builder": patch
33
---
44

5-
add missing `optional` prop for `needs:`
5+
Add missing `optional` property to `needs` definitions (both job and pipeline needs) to match GitLab CI specification.

src/import.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,10 @@ function formatValue(value: unknown, indentLevel: number): string {
178178
const props = entries.map(([k, v]) => {
179179
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(k) ? k : JSON.stringify(k)
180180

181-
// Special handling for extends: if it's an array with single element, format as string
182-
if (k === "extends" && Array.isArray(v) && v.length === 1) {
181+
// Special handling for properties that should be strings but might be single-element arrays
182+
// These properties accept string | string[] but single values are more common
183+
const singleValueProperties = ["extends", "annotations", "dotenv"]
184+
if (singleValueProperties.includes(k) && Array.isArray(v) && v.length === 1) {
183185
return `${indent}${key}: ${formatValue(v[0], indentLevel + 1)}`
184186
}
185187

src/types/artifacts.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ interface ArtifactsDefinition {
3838
* @see https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html#artifactsreportsdotenv
3939
*/
4040
dotenv?: string | string[]
41+
/**
42+
* @see https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportsannotations
43+
*/
44+
annotations?: string | string[]
4145
/**
4246
* @see https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html#artifactsreportscobertura
4347
*/

tests/import.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,5 +426,44 @@ deploy:
426426
expect(ts).toContain("optional: true")
427427
expect(ts).toContain('job: "unit_tests"')
428428
})
429+
430+
it("should handle artifacts.reports.annotations as single string", () => {
431+
const yaml = `
432+
test:
433+
script:
434+
- npm test
435+
artifacts:
436+
reports:
437+
annotations:
438+
- branding.json
439+
`
440+
441+
const ts = fromYaml(yaml)
442+
443+
expect(ts).toContain('config.job("test",')
444+
expect(ts).toContain("artifacts:")
445+
expect(ts).toContain("reports:")
446+
expect(ts).toContain('annotations: "branding.json"')
447+
})
448+
449+
it("should handle artifacts.reports.annotations as array", () => {
450+
const yaml = `
451+
test:
452+
script:
453+
- npm test
454+
artifacts:
455+
reports:
456+
annotations:
457+
- file1.json
458+
- file2.json
459+
`
460+
461+
const ts = fromYaml(yaml)
462+
463+
expect(ts).toContain('config.job("test",')
464+
expect(ts).toContain("artifacts:")
465+
expect(ts).toContain("reports:")
466+
expect(ts).toContain('annotations: ["file1.json", "file2.json"]')
467+
})
429468
})
430469
})

0 commit comments

Comments
 (0)