Skip to content

Commit

Permalink
fix: Gitlab NestedConfiguration addStages error (projen#1475)
Browse files Browse the repository at this point in the history
Creating a `NestedConfiguration` with a Job with stages throws ```TypeError: Cannot read properties of undefined (reading 'addStages')```. This is caused by the `parent` property (used in the overrided method) which gets set after the `super` call.

Fortunately, the overrided `addStages` method isn't necessary since the `GitlabConfiguration` [already handles](https://github.com/projen/projen/blob/main/src/gitlab/gitlab-configuration.ts#L37) adding stages in the `createNestedTemplate` method.

Sorry about that 😅

---
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • Loading branch information
dontirun authored Jan 3, 2022
1 parent 42a04f7 commit ee76669
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
16 changes: 0 additions & 16 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -5897,22 +5897,6 @@ Name | Type | Description
-----|------|-------------
**parent**🔹 | <code>[gitlab.GitlabConfiguration](#projen-gitlab-gitlabconfiguration)</code> | <span></span>

### Methods


#### addStages(...stages)🔹 <a id="projen-gitlab-nestedconfiguration-addstages"></a>

Add stages to the Nested configuration and the main CI file if not already present.

```ts
addStages(...stages: string[]): void
```

* **stages** (<code>string</code>) stages to add.






## class JavaProject 🔹 <a id="projen-java-javaproject"></a>
Expand Down
12 changes: 0 additions & 12 deletions src/gitlab/nested-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,4 @@ export class NestedConfiguration extends CiConfiguration {
super(project, name, options);
this.parent = parent;
}
/**
* Add stages to the Nested configuration and the main CI file if not already present.
* @param stages stages to add.
*/
public addStages(...stages: string[]) {
for (const stage of stages) {
if (!this.stages.includes(stage)) {
this.stages.push(stage);
}
this.parent.addStages(stage);
}
}
}
11 changes: 11 additions & 0 deletions test/gitlab/gitlab-configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ test("does not throw when adding an services with an existing nested template",
// THEN
expect(() => c.nestedTemplates.foo.addStages("baz")).not.toThrowError;
});

test("main configuration inherits child configuration stages", () => {
// GIVEN
const p = new TestProject({
stale: true,
});
const c = new GitlabConfiguration(p);
c.createNestedTemplates({ foo: { jobs: { bar: { stage: "baz" } } } });
// THEN
expect(c.stages).toContain("baz");
});

0 comments on commit ee76669

Please sign in to comment.