Skip to content

Commit 59c2a3a

Browse files
committed
feat(predicate): enable detecting use of github to version the project
1 parent 98e75e4 commit 59c2a3a

7 files changed

+65
-14
lines changed

README.md

+24-2
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,46 @@ for [octokit](https://github.com/octokit/rest.js/). Be sure to
5656
[add your personal access token](https://github.com/travi/octokit-auth-netrc#defining-your-token)
5757
to leverage the GitHub API integration benefits of this plugin.
5858

59+
### Enabling repository configuration with `repository-settings/app`
60+
61+
* Be sure to [install](https://github.com/apps/settings) for the user or
62+
organization account that you are scaffolding the new project for.
63+
* Enable the settings app for all repositories in the account
64+
65+
#### Account-level settings
66+
67+
The settings file generated by this tool assumes that it is extending an
68+
[account level config](https://github.com/probot/probot-config#recipes)
69+
70+
* Ensure that you have created a `.github` repository in your account
71+
* Create an [account-level settings file](https://github.com/probot/settings#inheritance)
72+
in the `.github` repository at the location `.github/settings.yml` within the
73+
repository
74+
* for an organization account, [this is a good example](https://github.com/form8ion/.github/blob/master/.github/settings.yml)
75+
* for a user account, [this is a good example](https://github.com/travi/.github/blob/master/.github/settings.yml)
76+
5977
### Example
6078

6179
#### Import
6280

6381
```javascript
64-
import {scaffold} from '@form8ion/github';
6582
import any from '@travi/any';
83+
import {scaffold, test} from '@form8ion/github';
6684
```
6785

6886
#### Execute
6987

7088
```javascript
89+
const projectRoot = process.cwd();
90+
7191
await scaffold({
72-
projectRoot: process.cwd(),
92+
projectRoot,
7393
name: 'foo',
7494
owner: 'travi',
7595
visibility: any.fromList(['Public', 'Private'])
7696
});
97+
98+
await test({projectRoot});
7799
```
78100

79101
## Contributing

example.js

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

88
// remark-usage-ignore-next
99
stubbedFs({node_modules: stubbedFs.load(resolve('node_modules'))});
1010

1111
// #### Execute
1212

13+
const projectRoot = process.cwd();
14+
1315
await scaffold({
14-
projectRoot: process.cwd(),
16+
projectRoot,
1517
name: 'foo',
1618
owner: 'travi',
1719
visibility: any.fromList(['Public', 'Private'])
1820
});
21+
22+
await test({projectRoot});

package-lock.json

+3-9
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
@@ -56,7 +56,6 @@
5656
"devDependencies": {
5757
"@cucumber/cucumber": "10.8.0",
5858
"@form8ion/commitlint-config": "1.0.76",
59-
"@form8ion/core": "4.3.0",
6059
"@form8ion/eslint-config": "7.0.9",
6160
"@form8ion/eslint-config-cucumber": "1.4.1",
6261
"@form8ion/remark-lint-preset": "6.0.3",
@@ -85,6 +84,7 @@
8584
"vitest": "1.6.0"
8685
},
8786
"dependencies": {
87+
"@form8ion/core": "^4.3.0",
8888
"@octokit/rest": "^20.0.0",
8989
"@travi/cli-messages": "^1.1.1",
9090
"octokit-auth-netrc": "^3.1.1"

src/index.js

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

src/tester.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {directoryExists} from '@form8ion/core';
2+
3+
export default function ({projectRoot}) {
4+
return directoryExists(`${projectRoot}/.github`);
5+
}

src/tester.test.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {directoryExists} from '@form8ion/core';
2+
3+
import any from '@travi/any';
4+
import {when} from 'jest-when';
5+
import {describe, expect, it, vi} from 'vitest';
6+
7+
import projectIsVersionedOnGithub from './tester.js';
8+
9+
vi.mock('@form8ion/core');
10+
11+
describe('github predicate', () => {
12+
const projectRoot = any.string();
13+
14+
it('should return `true` when the `.github` directory is present', async () => {
15+
when(directoryExists).calledWith(`${projectRoot}/.github`).mockResolvedValue(true);
16+
17+
expect(await projectIsVersionedOnGithub({projectRoot})).toBe(true);
18+
});
19+
20+
it('should return `false` when the `.github` directory is not present', async () => {
21+
when(directoryExists).calledWith(`${projectRoot}/.github`).mockResolvedValue(false);
22+
23+
expect(await projectIsVersionedOnGithub({projectRoot})).toBe(false);
24+
});
25+
});

0 commit comments

Comments
 (0)