-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: port read to typescript * fix: use @types/git-raw-commits * fix: adapt to latest master * refactor: unnest getEditFilePath * style: apply autoformatting
- Loading branch information
Showing
12 changed files
with
134 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import toplevel from '@commitlint/top-level'; | ||
import {getEditFilePath} from './get-edit-file-path'; | ||
|
||
const sander = require('@marionebl/sander'); | ||
|
||
// Get recently edited commit message | ||
export async function getEditCommit( | ||
cwd?: string, | ||
edit?: boolean | string | ||
): Promise<string[]> { | ||
const top = await toplevel(cwd); | ||
|
||
if (typeof top !== 'string') { | ||
throw new TypeError(`Could not find git root from ${cwd}`); | ||
} | ||
|
||
const editFilePath = await getEditFilePath(top, edit); | ||
|
||
const editFile: Buffer = await sander.readFile(editFilePath); | ||
return [`${editFile.toString('utf-8')}\n`]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import path from 'path'; | ||
import {Stats} from 'fs'; | ||
|
||
const sander = require('@marionebl/sander'); | ||
|
||
// Get path to recently edited commit message file | ||
export async function getEditFilePath( | ||
top: string, | ||
edit?: boolean | string | ||
): Promise<string> { | ||
if (typeof edit === 'string') { | ||
return path.resolve(top, edit); | ||
} | ||
|
||
const dotgitPath = path.join(top, '.git'); | ||
const dotgitStats: Stats = sander.lstatSync(dotgitPath); | ||
|
||
if (dotgitStats.isDirectory()) { | ||
return path.join(top, '.git/COMMIT_EDITMSG'); | ||
} | ||
|
||
const gitFile: string = await sander.readFile(dotgitPath, { | ||
encoding: 'utf-8' | ||
}); | ||
const relativeGitPath = gitFile.replace('gitdir: ', '').replace('\n', ''); | ||
return path.resolve(top, relativeGitPath, 'COMMIT_EDITMSG'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import gitRawCommits from 'git-raw-commits'; | ||
import {streamToPromise} from './stream-to-promise'; | ||
|
||
// Get commit messages from history | ||
export async function getHistoryCommits( | ||
options: {from?: string; to?: string}, | ||
opts: {cwd?: string} = {} | ||
): Promise<string[]> { | ||
return streamToPromise(gitRawCommits(options, {cwd: opts.cwd})); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {getHistoryCommits} from './get-history-commits'; | ||
import {getEditCommit} from './get-edit-commit'; | ||
|
||
interface GetCommitMessageOptions { | ||
cwd?: string; | ||
from?: string; | ||
to?: string; | ||
edit?: boolean | string; | ||
} | ||
|
||
// Get commit messages | ||
export default async function getCommitMessages( | ||
settings: GetCommitMessageOptions | ||
): Promise<string[]> { | ||
const {cwd, from, to, edit} = settings; | ||
|
||
if (edit) { | ||
return getEditCommit(cwd, edit); | ||
} | ||
|
||
return getHistoryCommits({from, to}, {cwd}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {Readable} from 'stream'; | ||
|
||
export function streamToPromise(stream: Readable): Promise<string[]> { | ||
const data: string[] = []; | ||
return new Promise((resolve, reject) => | ||
stream | ||
.on('data', chunk => data.push(chunk.toString('utf-8'))) | ||
.on('error', reject) | ||
.on('end', () => resolve(data)) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": "../../tsconfig.shared.json", | ||
"compilerOptions": { | ||
"composite": true, | ||
"rootDir": "./src", | ||
"outDir": "./lib" | ||
}, | ||
"include": [ | ||
"./src" | ||
], | ||
"exclude": [ | ||
"./src/**/*.test.ts", | ||
"./lib/**/*" | ||
], | ||
"references": [ | ||
{ "path": "../top-level" } | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -691,17 +691,6 @@ | |
js-levenshtein "^1.1.3" | ||
semver "^5.5.0" | ||
|
||
"@babel/[email protected]", "@babel/register@^7.7.7": | ||
version "7.7.7" | ||
resolved "https://registry.npmjs.org/@babel/register/-/register-7.7.7.tgz#46910c4d1926b9c6096421b23d1f9e159c1dcee1" | ||
integrity sha512-S2mv9a5dc2pcpg/ConlKZx/6wXaEwHeqfo7x/QbXsdCAZm+WJC1ekVvL1TVxNsedTs5y/gG63MhJTEsmwmjtiA== | ||
dependencies: | ||
find-cache-dir "^2.0.0" | ||
lodash "^4.17.13" | ||
make-dir "^2.1.0" | ||
pirates "^4.0.0" | ||
source-map-support "^0.5.16" | ||
|
||
"@babel/runtime@^7.0.0": | ||
version "7.7.7" | ||
resolved "https://registry.npmjs.org/@babel/runtime/-/runtime-7.7.7.tgz#194769ca8d6d7790ec23605af9ee3e42a0aa79cf" | ||
|
@@ -1837,6 +1826,13 @@ | |
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/git-raw-commits@^2.0.0": | ||
version "2.0.0" | ||
resolved "https://packages.atlassian.com/api/npm/npm-remote/@types/git-raw-commits/-/git-raw-commits-2.0.0.tgz#157e9e4709db0748fb1aa623f8927ddd4864bac6" | ||
integrity sha1-FX6eRwnbB0j7GqYj+JJ93UhkusY= | ||
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/glob@^7.1.1": | ||
version "7.1.1" | ||
resolved "https://registry.npmjs.org/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575" | ||
|
@@ -3163,11 +3159,6 @@ common-path-prefix@^1.0.0: | |
resolved "https://registry.npmjs.org/common-path-prefix/-/common-path-prefix-1.0.0.tgz#cd52f6f0712e0baab97d6f9732874f22f47752c0" | ||
integrity sha1-zVL28HEuC6q5fW+XModPIvR3UsA= | ||
|
||
commondir@^1.0.1: | ||
version "1.0.1" | ||
resolved "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" | ||
integrity sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs= | ||
|
||
compare-func@^1.3.1: | ||
version "1.3.2" | ||
resolved "https://registry.npmjs.org/compare-func/-/compare-func-1.3.2.tgz#99dd0ba457e1f9bc722b12c08ec33eeab31fa648" | ||
|
@@ -4415,15 +4406,6 @@ [email protected]: | |
statuses "~1.5.0" | ||
unpipe "~1.0.0" | ||
|
||
find-cache-dir@^2.0.0: | ||
version "2.1.0" | ||
resolved "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-2.1.0.tgz#8d0f94cd13fe43c6c7c261a0d86115ca918c05f7" | ||
integrity sha512-Tq6PixE0w/VMFfCgbONnkiQIVol/JJL7nRMi20fqzA4NRs9AfeqMGeRdPi3wIhYkxjeBaWh2rxwapn5Tu3IqOQ== | ||
dependencies: | ||
commondir "^1.0.1" | ||
make-dir "^2.0.0" | ||
pkg-dir "^3.0.0" | ||
|
||
[email protected]: | ||
version "2.0.0" | ||
resolved "https://registry.npmjs.org/find-node-modules/-/find-node-modules-2.0.0.tgz#5db1fb9e668a3d451db3d618cd167cdd59e41b69" | ||
|
@@ -6780,7 +6762,7 @@ make-dir@^1.0.0: | |
dependencies: | ||
pify "^3.0.0" | ||
|
||
make-dir@^2.0.0, make-dir@^2.1.0: | ||
make-dir@^2.1.0: | ||
version "2.1.0" | ||
resolved "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz#5f0310e18b8be898cc07009295a30ae41e91e6f5" | ||
integrity sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA== | ||
|
@@ -7998,7 +7980,7 @@ pinkie@^2.0.0: | |
resolved "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870" | ||
integrity sha1-clVrgM+g1IqXToDnckjoDtT3+HA= | ||
|
||
pirates@^4.0.0, pirates@^4.0.1: | ||
pirates@^4.0.1: | ||
version "4.0.1" | ||
resolved "https://registry.npmjs.org/pirates/-/pirates-4.0.1.tgz#643a92caf894566f91b2b986d2c66950a8e2fb87" | ||
integrity sha512-WuNqLTbMI3tmfef2TKxlQmAiLHKtFhlsCZnPIpuv2Ow0RDVO8lfy1Opf4NUzlMXLjPl+Men7AuVdX6TA+s+uGA== | ||
|
@@ -9108,7 +9090,7 @@ source-map-resolve@^0.5.0: | |
source-map-url "^0.4.0" | ||
urix "^0.1.0" | ||
|
||
source-map-support@^0.5.13, source-map-support@^0.5.16, source-map-support@^0.5.6: | ||
source-map-support@^0.5.13, source-map-support@^0.5.6: | ||
version "0.5.16" | ||
resolved "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.16.tgz#0ae069e7fe3ba7538c64c98515e35339eac5a042" | ||
integrity sha512-efyLRJDr68D9hBBNIPWFjhpFzURh+KJykQwvMyW5UiZzYwoF6l4YMMDIJJEyFWxWCqfyxLzz6tSfUFR+kXXsVQ== | ||
|