Skip to content

Commit 4419e59

Browse files
authored
test: use konn & bring back system tests (#138)
1 parent 0217dd2 commit 4419e59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1509
-577
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@ jobs:
2323
runs-on: ubuntu-latest
2424
strategy:
2525
matrix:
26-
node-version: [12.x, 14.x]
26+
node-version: [14.x, 16.x]
2727
steps:
2828
- uses: actions/checkout@v2
2929
- name: Use Node.js ${{ matrix.node-version }}
3030
uses: actions/setup-node@v1
3131
with:
3232
node-version: ${{ matrix.node-version }}
33-
- run: yarn --frozen-lockfile
33+
- run: yarn --immutable
3434
- run: yarn test:unit # todo system tests on ci
3535

3636
publish:
3737
needs: test
3838
runs-on: ubuntu-latest
3939
steps:
4040
- uses: actions/checkout@v2
41-
- name: Get all git commits and tags
42-
run: git fetch --prune --unshallow --tags
43-
- uses: actions/setup-node@v1
4441
with:
45-
node-version: 12.x
46-
- run: yarn --frozen-lockfile
42+
fetch-depth: 0
43+
- uses: actions/setup-node@v2
44+
with:
45+
node-version: 16.x
46+
- run: yarn --immutable
4747
- run: yarn dripip preview-or-pr
4848
env:
4949
NPM_TOKEN: ${{secrets.NPM_TOKEN}}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ typings/
6262

6363
# app
6464
dist-*
65-
.vscode
6665
.swc
6766

6867
# Yarn 2

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"]
3+
}

.vscode/settings.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"search.exclude": {
3+
"**/dist-cjs": true,
4+
"**/dist-esm": true,
5+
"**/__snapshots__": true,
6+
"**/.yarn": true,
7+
"yarn.lock": true
8+
},
9+
"typescript.tsdk": "node_modules/typescript/lib",
10+
"typescript.enablePromptUseWorkspaceTsdk": true,
11+
"editor.codeActionsOnSave": {
12+
"source.addMissingImports": true,
13+
"source.fixAll.eslint": true,
14+
// Disable this because it will conflict with ESLint based import organizing.
15+
"source.organizeImports": false
16+
}
17+
}

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ jobs:
149149
runs-on: ubuntu-latest
150150
steps:
151151
- uses: actions/checkout@v2
152-
- name: Get all git commits and tags
153-
run: git fetch --prune --unshallow --tags
154-
- uses: actions/setup-node@v1
155-
- run: yarn --frozen-lockfile
152+
with:
153+
fetch-depth: 0
154+
- uses: actions/setup-node@v2
155+
- run: yarn --immutable
156156
- run: yarn dripip preview-or-pr
157157
env:
158158
NPM_TOKEN: ${{secrets.NPM_TOKEN}}

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"@types/parse-github-url": "^1.0.0",
4343
"chaindown": "^0.1.0-next.2",
4444
"chalk": "^4.1.0",
45-
"common-tags": "^1.8.0",
46-
"debug": "^4.3.1",
45+
"common-tags": "^1.8.2",
46+
"debug": "^4.3.3",
4747
"execa": "5",
4848
"fs-jetpack": "^4.3.1",
4949
"isomorphic-git": "^1.8.0",
@@ -56,17 +56,17 @@
5656
},
5757
"devDependencies": {
5858
"@prisma-labs/prettier-config": "0.1.0",
59-
"@swc/core": "^1.2.148",
59+
"@swc/core": "^1.2.151",
6060
"@swc/helpers": "^0.3.6",
6161
"@swc/jest": "^0.2.20",
6262
"@tsconfig/node14": "^1.0.1",
6363
"@types/common-tags": "1.8.1",
64-
"@types/eslint": "^8",
64+
"@types/eslint": "^8.4.1",
6565
"@types/jest": "27.4.1",
6666
"@types/node": "17.0.21",
6767
"@types/tmp": "0.2.3",
68-
"@typescript-eslint/eslint-plugin": "^5.13.0",
69-
"@typescript-eslint/parser": "^5.13.0",
68+
"@typescript-eslint/eslint-plugin": "^5.14.0",
69+
"@typescript-eslint/parser": "^5.14.0",
7070
"doctoc": "1.4.0",
7171
"eslint": "^8.10.0",
7272
"eslint-config-prettier": "^8.5.0",
@@ -80,11 +80,12 @@
8080
"jest-watch-suspend": "1.1.2",
8181
"jest-watch-toggle-config": "2.0.1",
8282
"jest-watch-typeahead": "1.0.0",
83+
"konn": "^0.7.0",
8384
"prettier": "2.5.1",
8485
"strip-ansi": "6.0.0",
8586
"tmp": "0.2.1",
8687
"ts-jest": "27.1.3",
87-
"ts-node": "10.6.0",
88+
"ts-node": "10.7.0",
8889
"tsconfig-paths": "^3.13.0",
8990
"type-fest": "2.12.0",
9091
"typescript": "4.6.2",

src/cli/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ yargs(process.argv.slice(2))
196196
description: `skip the step of publishing the package to npm`,
197197
},
198198
}),
199+
// eslint-disable-next-line
199200
async (flags) => {
200201
const context = await getLocationContext({ octokit })
201202

src/lib/git.ts

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,60 @@ import parseGitConfig from 'parse-git-config'
77
import parseGitHubURL from 'parse-github-url'
88
import doCreateGit from 'simple-git/promise'
99

10+
/**
11+
* Extract the github repo name and owner from the git config. If anything goes
12+
* wrong during extraction a specific error about it will be thrown.
13+
*/
14+
export const parseGitHubRepoInfoFromGitConfig = async (params?: {
15+
cwd?: string
16+
}): Promise<BasicGitHubRepoInfo> => {
17+
const { cwd = process.cwd() } = params ?? {}
18+
// Inspiration from how `$ hub pr show` works
19+
// https://github.com/github/hub/blob/a5fbf29be61a36b86c7f0ff9e9fd21090304c01f/commands/pr.go#L327
20+
21+
const gitConfig = await parseGitConfig({ path: `${cwd}/.git/config` })
22+
if (gitConfig === null) {
23+
throw new Error(`Could not parse your git config`)
24+
}
25+
26+
const gitOrigin = gitConfig[`remote "origin"`]
27+
if (gitOrigin === undefined) {
28+
throw new Error(`Could not find a configured origin in your git config`)
29+
}
30+
31+
const gitOriginURL: string = gitOrigin[`url`]
32+
if (gitOriginURL === undefined) {
33+
throw new Error(`Could not find a URL in your remote origin config in your git config`)
34+
}
35+
36+
const githubRepoURL = parseGitHubURL(gitOriginURL)
37+
if (githubRepoURL === null) {
38+
throw new Error(`Could not parse the URL in your remote origin config in your git config`)
39+
}
40+
if (githubRepoURL.owner === null) {
41+
throw new Error(
42+
`Could not parse out the GitHub owner from the URL in your remote origin config in your git config`
43+
)
44+
}
45+
if (githubRepoURL.name === null) {
46+
throw new Error(
47+
`Could not parse out the GitHub repo name from the URL in your remote origin config in your git config`
48+
)
49+
}
50+
51+
return {
52+
name: githubRepoURL.name,
53+
owner: githubRepoURL.owner,
54+
}
55+
}
56+
1057
export type Simple = ReturnType<typeof doCreateGit>
1158

12-
export function createGit(): Simple {
59+
export const createGit = (): Simple => {
1360
return doCreateGit()
1461
}
1562

16-
function parseGitTags(tagsString: null | string): string[] {
63+
const parseGitTags = (tagsString: null | string): string[] => {
1764
if (tagsString === null) return []
1865
const tags = tagsString
1966
.trim()
@@ -62,7 +109,7 @@ export async function gitReset(git: Simple): Promise<void> {
62109
*/
63110
export async function gitResetToInitialCommit(git: Simple): Promise<void> {
64111
await git.raw([`clean`, `-d`, `-x`, `-f`])
65-
const trunkBranch = `master`
112+
const trunkBranch = `main`
66113
await git.raw(`checkout ${trunkBranch}`.split(` `))
67114
await git.raw(`rev-list --max-parents=0 HEAD`.split(` `)).then((initialCommitSHA) => {
68115
git.raw([`reset`, `--hard`, initialCommitSHA.trim()])
@@ -160,7 +207,7 @@ export async function gitDeleteAllTagsInRepo(git: Simple): Promise<void> {
160207
// }
161208
// }
162209
//
163-
// const githubRepo = await parseGitHubRepoInfoFromGitConfig()
210+
// const githubRepo = await pars eGitHubRepoInfoFromGitConfig()
164211

165212
// // TODO Refactor this to have instance passed as arg.
166213
// const octoOps = {} as Octokit.Options
@@ -230,59 +277,15 @@ export interface BasicGitHubRepoInfo {
230277
owner: string
231278
}
232279

233-
/**
234-
* Extract the github repo name and owner from the git config. If anything goes
235-
* wrong during extraction a specific error about it will be thrown.
236-
*/
237-
export async function parseGitHubRepoInfoFromGitConfig(): Promise<BasicGitHubRepoInfo> {
238-
// Inspiration from how `$ hub pr show` works
239-
// https://github.com/github/hub/blob/a5fbf29be61a36b86c7f0ff9e9fd21090304c01f/commands/pr.go#L327
240-
241-
const gitConfig = await parseGitConfig()
242-
if (gitConfig === null) {
243-
throw new Error(`Could not parse your git config`)
244-
}
245-
246-
const gitOrigin = gitConfig[`remote "origin"`]
247-
if (gitOrigin === undefined) {
248-
throw new Error(`Could not find a configured origin in your git config`)
249-
}
250-
251-
const gitOriginURL: string = gitOrigin[`url`]
252-
if (gitOriginURL === undefined) {
253-
throw new Error(`Could not find a URL in your remote origin config in your git config`)
254-
}
255-
256-
const githubRepoURL = parseGitHubURL(gitOriginURL)
257-
if (githubRepoURL === null) {
258-
throw new Error(`Could not parse the URL in your remote origin config in your git config`)
259-
}
260-
if (githubRepoURL.owner === null) {
261-
throw new Error(
262-
`Could not parse out the GitHub owner from the URL in your remote origin config in your git config`
263-
)
264-
}
265-
if (githubRepoURL.name === null) {
266-
throw new Error(
267-
`Could not parse out the GitHub repo name from the URL in your remote origin config in your git config`
268-
)
269-
}
270-
271-
return {
272-
name: githubRepoURL.name,
273-
owner: githubRepoURL.owner,
274-
}
275-
}
276-
277280
/**
278281
* Determine if the current branch is trunk or not. Currently a simple check
279-
* against if current branch is master or not but TODO in the future will
282+
* against if current branch is main or not but TODO in the future will
280283
* account for checking against the remote Git repo for if the so-called `base`
281-
* branch of the repo is set to something else than `master`.
284+
* branch of the repo is set to something else than `main`.
282285
*/
283286
export async function isTrunk(git: Simple): Promise<boolean> {
284287
const branchSummary = await git.branch({})
285-
return branchSummary.current === `master`
288+
return branchSummary.current === `main`
286289
}
287290

288291
/**

src/lib/git2.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,28 @@ class Git2 {
2121
* Get the name of the currently checked out branch.
2222
*/
2323
getCurrentBranchName() {
24-
return isogit.currentBranch({ fs: this.fs, dir: this.dir })
24+
return isogit.currentBranch({
25+
fs: this.fs,
26+
dir: this.dir,
27+
})
2528
}
2629
/**
2730
* Check how the local branch is not in sync or is with the remote.
2831
* Ref: https://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git
2932
*/
3033
async checkSyncStatus(input: { branchName: string }): Promise<GitSyncStatus> {
31-
let remoteUrl: string = await isogit.getConfig({
34+
const maybeRemoteUrl: unknown = await isogit.getConfig({
3235
fs: this.fs,
3336
dir: this.dir,
3437
path: `remote.origin.url`,
3538
})
3639

40+
if (!maybeRemoteUrl) {
41+
throw new Error(`Could not find remoteUrl from the git config.`)
42+
}
43+
44+
let remoteUrl = maybeRemoteUrl as string
45+
3746
if (remoteUrl.startsWith(`git@github.com:`)) {
3847
remoteUrl = remoteUrl.replace(`git@github.com:`, `https://github.com/`)
3948
}

0 commit comments

Comments
 (0)