Skip to content

Commit c444b4f

Browse files
committed
feat(settings): lift the settings file
1 parent d50470c commit c444b4f

11 files changed

+155
-18
lines changed

README.md

+12-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ The settings file generated by this tool assumes that it is extending an
9292

9393
```javascript
9494
import any from '@travi/any';
95-
import {scaffold, test} from '@form8ion/github';
95+
import {scaffold, test, lift} from '@form8ion/github';
9696
```
9797

9898
#### Execute
@@ -104,10 +104,19 @@ await scaffold({
104104
projectRoot,
105105
name: 'foo',
106106
owner: 'travi',
107-
visibility: any.fromList(['Public', 'Private'])
107+
visibility: any.fromList(['Public', 'Private']),
108+
description: any.sentence()
108109
});
109110

110-
await test({projectRoot});
111+
if (await test({projectRoot})) {
112+
await lift({
113+
projectRoot,
114+
results: {
115+
projectDetails: {homepage: any.url()},
116+
tags: any.listOf(any.word)
117+
}
118+
});
119+
}
111120
```
112121

113122
## Contributing

example.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import {resolve} from 'path';
44
import stubbedFs from 'mock-fs';
55
import any from '@travi/any';
6-
import {scaffold, test} from './lib/index.js';
6+
import {scaffold, test, lift} from './lib/index.js';
77

88
// remark-usage-ignore-next
99
stubbedFs({node_modules: stubbedFs.load(resolve('node_modules'))});
@@ -16,7 +16,16 @@ await scaffold({
1616
projectRoot,
1717
name: 'foo',
1818
owner: 'travi',
19-
visibility: any.fromList(['Public', 'Private'])
19+
visibility: any.fromList(['Public', 'Private']),
20+
description: any.sentence()
2021
});
2122

22-
await test({projectRoot});
23+
if (await test({projectRoot})) {
24+
await lift({
25+
projectRoot,
26+
results: {
27+
projectDetails: {homepage: any.url()},
28+
tags: any.listOf(any.word)
29+
}
30+
});
31+
}

package-lock.json

+11-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
},
8686
"dependencies": {
8787
"@form8ion/core": "^4.3.0",
88-
"@form8ion/repository-settings": "^1.0.1",
88+
"@form8ion/repository-settings": "^1.1.2",
8989
"@octokit/rest": "^20.0.0",
9090
"@travi/cli-messages": "^1.1.1",
9191
"octokit-auth-netrc": "^3.1.1"

src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export {default as scaffold} from './scaffolder.js';
22
export {default as test} from './tester.js';
3+
export {default as lift} from './lifter.js';

src/lifter.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {test as repositoryMaintainedWithRepositorySettings, lift as liftSettings} from '@form8ion/repository-settings';
2+
3+
export default async function ({projectRoot, results}) {
4+
if (await repositoryMaintainedWithRepositorySettings({projectRoot})) {
5+
return liftSettings({projectRoot, results});
6+
}
7+
8+
return {};
9+
}

src/lifter.test.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {lift as liftSettings, test as repositoryMaintainedWithRepositorySettings} from '@form8ion/repository-settings';
2+
3+
import any from '@travi/any';
4+
import {when} from 'jest-when';
5+
import {describe, expect, it, vi} from 'vitest';
6+
7+
import lift from './lifter.js';
8+
9+
vi.mock('@form8ion/repository-settings');
10+
11+
describe('lifter', () => {
12+
const projectRoot = any.string();
13+
const results = any.simpleObject();
14+
15+
it('should apply the settings lifter if the project is managed with the settings app', async () => {
16+
const settingsResult = any.simpleObject();
17+
when(repositoryMaintainedWithRepositorySettings).calledWith({projectRoot}).mockResolvedValue(true);
18+
when(liftSettings).calledWith({projectRoot, results}).mockResolvedValue(settingsResult);
19+
20+
expect(await lift({projectRoot, results})).toEqual(settingsResult);
21+
});
22+
23+
it('should apply not the settings lifter if the project is not managed with the settings app', async () => {
24+
when(repositoryMaintainedWithRepositorySettings).calledWith({projectRoot}).mockResolvedValue(false);
25+
26+
expect(await lift({projectRoot, results})).toEqual({});
27+
});
28+
});
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Feature: Lift
2+
3+
Scenario: lift settings
4+
Given the project is versioned on GitHub
5+
And the repository settings are managed by the settings app
6+
When the scaffolder results are processed
7+
Then properties are updated in the settings file
8+
9+
Scenario: lift but settings not managed by the repository-settings app
10+
Given the project is versioned on GitHub
11+
But the repository settings are not managed by the settings app
12+
When the scaffolder results are processed
13+
Then no settings file exists
14+
15+
Scenario: non-GitHub project
16+
Given the project is not versioned on GitHub
17+
When the scaffolder results are processed
18+
Then no settings file exists

test/integration/features/step_definitions/common-steps.js

+27-2
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ import {After, Before, When} from '@cucumber/cucumber';
55
import stubbedFs from 'mock-fs';
66
import any from '@travi/any';
77
import debugTest from 'debug';
8+
import yaml from 'js-yaml';
89

910
const debug = debugTest('test');
1011
const __dirname = dirname(fileURLToPath(import.meta.url)); // eslint-disable-line no-underscore-dangle
1112
const stubbedNodeModules = stubbedFs.load(resolve(__dirname, '..', '..', '..', '..', 'node_modules'));
1213

13-
let scaffold;
14+
let scaffold, test, lift;
1415

1516
Before(async function () {
1617
// eslint-disable-next-line import/no-extraneous-dependencies,import/no-unresolved
17-
({scaffold} = await import('@form8ion/github'));
18+
({scaffold, test, lift} = await import('@form8ion/github'));
1819

1920
this.projectName = any.word();
2021
this.projectRoot = process.cwd();
@@ -42,3 +43,27 @@ When('the project is scaffolded', async function () {
4243
this.scaffoldError = err;
4344
}
4445
});
46+
47+
When('the scaffolder results are processed', async function () {
48+
this.tags = any.listOf(any.word);
49+
this.existingSettingsContent = {...any.simpleObject(), repository: any.simpleObject()};
50+
51+
stubbedFs({
52+
...this.github && {
53+
'.github': {
54+
...this.settingsApp && {'settings.yml': yaml.dump(this.existingSettingsContent)}
55+
}
56+
},
57+
node_modules: stubbedNodeModules
58+
});
59+
60+
if (await test({projectRoot: this.projectRoot})) {
61+
await lift({
62+
projectRoot: this.projectRoot,
63+
results: {
64+
projectDetails: this.projectDetails,
65+
tags: this.tags
66+
}
67+
});
68+
}
69+
});

test/integration/features/step_definitions/repository-steps.js

+8
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ Given('a repository already exists for the {string} on GitHub', async function (
115115
}
116116
});
117117

118+
Given('the project is versioned on GitHub', async function () {
119+
this.github = true;
120+
});
121+
122+
Given('the project is not versioned on GitHub', async function () {
123+
this.github = false;
124+
});
125+
118126
Then('repository details are returned', async function () {
119127
assert.equal(this.result.sshUrl, sshUrl);
120128
assert.equal(this.result.htmlUrl, htmlUrl);

test/integration/features/step_definitions/settings-steps.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import {promises as fs} from 'node:fs';
22
import yaml from 'js-yaml';
3+
import {fileExists} from '@form8ion/core';
34

45
import assert from 'node:assert';
5-
import {Then} from '@cucumber/cucumber';
6+
import {Given, Then} from '@cucumber/cucumber';
7+
8+
Given('the repository settings are managed by the settings app', async function () {
9+
this.settingsApp = true;
10+
});
11+
12+
Given('the repository settings are not managed by the settings app', async function () {
13+
this.settingsApp = false;
14+
});
615

716
Then('repository settings are configured', async function () {
817
const settings = yaml.load(await fs.readFile(`${process.cwd()}/.github/settings.yml`));
@@ -21,3 +30,21 @@ Then('repository settings are configured', async function () {
2130
}
2231
);
2332
});
33+
34+
Then('properties are updated in the settings file', async function () {
35+
assert.deepEqual(
36+
yaml.load(await fs.readFile(`${this.projectRoot}/.github/settings.yml`, 'utf-8')),
37+
{
38+
...this.existingSettingsContent,
39+
repository: {
40+
...this.existingSettingsContent.repository,
41+
...this.homepage && {homepage: this.homepage},
42+
topics: this.tags.join(', ')
43+
}
44+
}
45+
);
46+
});
47+
48+
Then('no settings file exists', async function () {
49+
assert.equal(await fileExists(`${this.projectRoot}/.github/settings.yml`), false);
50+
});

0 commit comments

Comments
 (0)