Skip to content

Commit 4b08176

Browse files
committed
feat: initial adaption
1 parent 0959a49 commit 4b08176

File tree

8 files changed

+1024
-6
lines changed

8 files changed

+1024
-6
lines changed

package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
"url": "https://github.com/seek-oss/skuba.git"
4040
},
4141
"devDependencies": {
42-
"@changesets/cli": "2.18.0",
4342
"@changesets/get-github-info": "0.5.0",
43+
"@changesets/types": "4.0.1",
4444
"@types/concurrently": "6.3.0",
4545
"@types/ejs": "3.1.0",
4646
"@types/express": "4.17.13",
@@ -59,6 +59,10 @@
5959
"type-fest": "2.5.2"
6060
},
6161
"dependencies": {
62+
"@changesets/cli": "^2.18.0",
63+
"@changesets/pre": "^1.0.7",
64+
"@changesets/read": "^0.5.1",
65+
"@manypkg/get-packages": "^1.1.3",
6266
"@octokit/rest": "^18.12.0",
6367
"@octokit/types": "^6.34.0",
6468
"@types/jest": "^27.0.1",
@@ -79,13 +83,16 @@
7983
"jest": "^27.1.0",
8084
"latest-version": "^5.1.0",
8185
"lodash.mergewith": "^4.6.2",
86+
"mdast-util-to-string": "^3.1.0",
8287
"module-alias": "^2.2.2",
8388
"normalize-package-data": "^3.0.0",
8489
"npm-run-path": "^4.0.1",
8590
"npm-which": "^3.0.1",
8691
"picomatch": "^2.2.2",
8792
"prettier": "~2.4.1",
8893
"read-pkg-up": "^7.0.1",
94+
"remark-parse": "^10.0.0",
95+
"remark-stringify": "^10.0.1",
8996
"runtypes": "^6.0.0",
9097
"semantic-release": "^17.4.7",
9198
"serialize-error": "^8.0.1",
@@ -95,7 +102,8 @@
95102
"ts-node": "^9.1.1",
96103
"ts-node-dev": "^1.1.8",
97104
"tsconfig-seek": "1.0.2",
98-
"typescript": "~4.4.4"
105+
"typescript": "~4.4.4",
106+
"unified": "^10.1.0"
99107
},
100108
"peerDependencies": {
101109
"skuba-dive": "1"

src/cli/changeset/changeset.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const changeset = () => {
2+
const argv = process.argv.slice(2);
3+
};

src/cli/changeset/gitUtils.ts

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Adapted from https://github.com/changesets/action/blob/21240c3cd1d2efa2672d64e0235a03cf139b83e6/src/utils.ts
2+
3+
import { exec } from 'utils/exec';
4+
5+
import { execWithOutput } from './utils';
6+
7+
const getBotName = () => 'buildkite';
8+
9+
export const setupUser = async () => {
10+
await exec('git', ...['config', '--global', 'user.name', getBotName()]);
11+
await exec(
12+
'git',
13+
...[
14+
'config',
15+
'--global',
16+
'user.email',
17+
`${getBotName()}@users.noreply.github.com`,
18+
],
19+
);
20+
};
21+
22+
export const pullBranch = async (branch: string) => {
23+
await exec('git', ...['pull', 'origin', branch]);
24+
};
25+
26+
export const push = async (
27+
branch: string,
28+
{ force }: { force?: boolean } = {},
29+
) => {
30+
await exec(
31+
'git',
32+
...['push', 'origin', `HEAD:${branch}`, force && '--force'].filter<string>(
33+
Boolean as any,
34+
),
35+
);
36+
};
37+
38+
export const pushTags = async () => {
39+
await exec('git', ...['push', 'origin', '--tags']);
40+
};
41+
42+
export const switchToMaybeExistingBranch = async (branch: string) => {
43+
const { stderr } = await execWithOutput('git', ['checkout', branch], {
44+
ignoreReturnCode: true,
45+
});
46+
const isCreatingBranch = !(stderr as Error)
47+
.toString()
48+
.includes(`Switched to a new branch '${branch}'`);
49+
if (isCreatingBranch) {
50+
await exec('git', ...['checkout', '-b', branch]);
51+
}
52+
};
53+
54+
export const reset = async (
55+
pathSpec: string,
56+
mode: 'hard' | 'soft' | 'mixed' = 'hard',
57+
) => {
58+
await exec('git', ...['reset', `--${mode}`, pathSpec]);
59+
};
60+
61+
export const commitAll = async (message: string) => {
62+
await exec('git', ...['add', '.']);
63+
await exec('git', ...['commit', '-m', message]);
64+
};
65+
66+
export const checkIfClean = async (): Promise<boolean> => {
67+
const { stdout } = await execWithOutput('git', ['status', '--porcelain']);
68+
return !(stdout as Array<unknown>).length;
69+
};
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Adapted from https://github.com/changesets/action/blob/21240c3cd1d2efa2672d64e0235a03cf139b83e6/src/readChangesetState.ts
2+
3+
import { readPreState } from '@changesets/pre';
4+
import readChangesets from '@changesets/read';
5+
import type { NewChangeset, PreState } from '@changesets/types';
6+
7+
export type ChangesetState = {
8+
preState: PreState | undefined;
9+
changesets: NewChangeset[];
10+
};
11+
12+
export default async function readChangesetState(
13+
cwd: string = process.cwd(),
14+
): Promise<ChangesetState> {
15+
const preState = await readPreState(cwd);
16+
const isInPreMode = preState !== undefined && preState.mode === 'pre';
17+
18+
let changesets = await readChangesets(cwd);
19+
20+
if (isInPreMode) {
21+
const changesetsToFilter = new Set(preState.changesets);
22+
changesets = changesets.filter((x) => !changesetsToFilter.has(x.id));
23+
}
24+
25+
return {
26+
preState: isInPreMode ? preState : undefined,
27+
changesets,
28+
};
29+
}

0 commit comments

Comments
 (0)