Skip to content

Commit

Permalink
fix: Add support for upper case variables (projen#1721)
Browse files Browse the repository at this point in the history
Fixing the issue of job variables rendering as snake case and don't respecting the original format

closes projen#1693 

---
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • Loading branch information
marciocadev authored Apr 6, 2022
1 parent dd13a19 commit d1465dc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/gitlab/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ function snakeCaseKeys<T = unknown>(obj: T): T {

const result: Record<string, unknown> = {};
for (let [k, v] of Object.entries(obj)) {
if (typeof v === "object" && v != null) {
if (typeof v === "object" && v != null && k !== "variables") {
v = snakeCaseKeys(v);
}
result[snake(k)] = v;
Expand Down
37 changes: 36 additions & 1 deletion test/gitlab/configuration.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CiConfiguration } from "../../src/gitlab";
import { TestProject } from "../util";
import { synthSnapshot, TestProject } from "../util";

test("throws when adding an existing service with same name and alias", () => {
// GIVEN
Expand Down Expand Up @@ -92,3 +92,38 @@ test("throws when adding an existing includes", () => {
/already contains one or more templates specified in/
);
});

test("respected the original format when variables are added to jobs", () => {
// GIVEN
const p = new TestProject({
stale: true,
});
new CiConfiguration(p, "foo", {
jobs: {
build: {
variables: { AWS_REGION: "eu-central-1" },
},
},
});
const snapshot = synthSnapshot(p);
// THEN
expect(snapshot[".gitlab/ci-templates/foo.yml"]).toContain(
"AWS_REGION: eu-central-1"
);
});

test("respect the original format when adding global variables", () => {
// GIVEN
const p = new TestProject({
stale: true,
});
const c = new CiConfiguration(p, "foo", {});
c.addGlobalVariables({
AWS_REGION: "eu-central-1",
});
const snapshot = synthSnapshot(p);
// THEN
expect(snapshot[".gitlab/ci-templates/foo.yml"]).toContain(
"AWS_REGION: eu-central-1"
);
});

0 comments on commit d1465dc

Please sign in to comment.