зеркало из https://github.com/microsoft/beachball.git
This commit is contained in:
Родитель
a1be6f19ac
Коммит
9bbc8b4655
|
@ -1,2 +1,2 @@
|
|||
node_modules/
|
||||
lib/
|
||||
lib/
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
import prompts from 'prompts';
|
||||
import { getRecentCommitMessages } from './git';
|
||||
|
||||
export async function promptForChange() {
|
||||
const recentMessages = getRecentCommitMessages() || [];
|
||||
|
||||
const response = await prompts({
|
||||
type: 'autocomplete',
|
||||
name: 'description',
|
||||
message: 'Describe your changes',
|
||||
suggest: input => {
|
||||
return Promise.resolve(recentMessages.find(msg => msg.startsWith(input)) || input);
|
||||
}
|
||||
});
|
||||
|
||||
console.log(response); // => { value: 24 }
|
||||
}
|
||||
|
||||
promptForChange();
|
82
src/git.ts
82
src/git.ts
|
@ -1,5 +1,85 @@
|
|||
import { spawnSync } from 'child_process';
|
||||
|
||||
export function git(args: string[]) {
|
||||
return spawnSync('git', args);
|
||||
const results = spawnSync('git', args);
|
||||
|
||||
if (results.status === 0) {
|
||||
return {
|
||||
stderr: results.stderr.toString().trim(),
|
||||
stdout: results.stdout.toString().trim()
|
||||
};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function getUncommittedChanges() {
|
||||
try {
|
||||
const results = git(['status', '--porcelain']);
|
||||
|
||||
if (!results) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const changes = results.stdout;
|
||||
|
||||
if (changes.length == 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const lines = changes.split(/\n/) || [];
|
||||
|
||||
return lines.map(line => line.trim().split(/ /)[1]);
|
||||
} catch (e) {
|
||||
console.error('Cannot gather information about changes: ', e.message);
|
||||
}
|
||||
}
|
||||
|
||||
export function getForkPoint(targetBranch: string = 'origin/master') {
|
||||
try {
|
||||
const results = git(['git', 'merge-base', '--fork-point', targetBranch, 'HEAD']);
|
||||
if (!results) {
|
||||
return targetBranch;
|
||||
}
|
||||
|
||||
return results.stdout;
|
||||
} catch (e) {
|
||||
return targetBranch;
|
||||
}
|
||||
}
|
||||
|
||||
export function getChanges() {
|
||||
try {
|
||||
const forkPoint = getForkPoint();
|
||||
const results = git(['--no-pager', 'diff', '--name-only', forkPoint + '...']);
|
||||
|
||||
if (!results) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let changes = results.stdout;
|
||||
let lines = changes.split(/\n/) || [];
|
||||
|
||||
return lines.map(line => line.trim());
|
||||
} catch (e) {
|
||||
console.error('Cannot gather information about changes: ', e.message);
|
||||
}
|
||||
}
|
||||
|
||||
export function getRecentCommitMessages() {
|
||||
try {
|
||||
const forkPoint = getForkPoint();
|
||||
const results = git(['log', '--decorate', '--pretty=format:%s', '--reverse', forkPoint, 'HEAD']);
|
||||
|
||||
if (!results) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let changes = results.stdout;
|
||||
let lines = changes.split(/\n/) || [];
|
||||
|
||||
return lines.map(line => line.trim());
|
||||
} catch (e) {
|
||||
console.error('Cannot gather information about changes: ', e.message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,3 +43,8 @@ export function getChangeFilePath(cwd?: string) {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function isChildOf(child: string, parent: string) {
|
||||
const relativePath = path.relative(child, parent);
|
||||
return /^[.\/\\]+$/.test(relativePath);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче