@evanpurkhiser/tooling-personal 1.14.0 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cmd/pr.js +3 -2
- package/dist/cmd/select-commit.js +22 -0
- package/dist/index.js +12 -0
- package/dist/utils.js +11 -4
- package/package.json +1 -1
package/dist/cmd/pr.js
CHANGED
|
@@ -14,6 +14,7 @@ const pulls_1 = require("../pulls");
|
|
|
14
14
|
const utils_1 = require("../utils");
|
|
15
15
|
const getCommits = () => simple_git_1.default().log({ from: 'HEAD', to: 'origin/master' });
|
|
16
16
|
async function pr() {
|
|
17
|
+
const username = await utils_1.getEmailUsername();
|
|
17
18
|
const repo = await utils_1.getRepoKey();
|
|
18
19
|
const rendererOptions = { showTimer: true };
|
|
19
20
|
const collectInfoTask = new listr2_1.Listr([], {
|
|
@@ -53,7 +54,7 @@ async function pr() {
|
|
|
53
54
|
const selectCommits = () => fzf_1.fzfSelect({
|
|
54
55
|
prompt: 'Select commit(s) for PR:',
|
|
55
56
|
genValues: addOption => commits.all.forEach(commit => {
|
|
56
|
-
const branchName = utils_1.branchFromMessage(commit.message);
|
|
57
|
+
const branchName = utils_1.branchFromMessage(username, commit.message);
|
|
57
58
|
const pr = prs.find(pr => pr.headRefName === branchName);
|
|
58
59
|
const existingPrLabel = pr !== undefined ? chalk_1.default.yellowBright `(updates #${pr.number})` : '';
|
|
59
60
|
const shortHash = commit.hash.slice(0, 8);
|
|
@@ -79,7 +80,7 @@ async function pr() {
|
|
|
79
80
|
.map(sha => `pick ${sha}`)
|
|
80
81
|
.join('\n');
|
|
81
82
|
const targetCommit = selectedCommits[selectedCommits.length - 1];
|
|
82
|
-
const branchName = utils_1.branchFromMessage(targetCommit.message);
|
|
83
|
+
const branchName = utils_1.branchFromMessage(username, targetCommit.message);
|
|
83
84
|
const willOpenPr = prs.some(pr => pr.headRefName === branchName);
|
|
84
85
|
// 03. Rebase and push the selected commits
|
|
85
86
|
const doRebase = async () => {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
7
|
+
const simple_git_1 = __importDefault(require("simple-git"));
|
|
8
|
+
const fzf_1 = require("../fzf");
|
|
9
|
+
async function selectCommit() {
|
|
10
|
+
const commits = await simple_git_1.default().log({ from: 'HEAD', to: 'origin/master' });
|
|
11
|
+
const selected = await fzf_1.fzfSelect({
|
|
12
|
+
prompt: 'Select commit(s) for PR:',
|
|
13
|
+
genValues: addOption => commits.all.forEach(commit => {
|
|
14
|
+
const shortHash = commit.hash.slice(0, 8);
|
|
15
|
+
const label = chalk_1.default `{red ${shortHash}} {blue [${commit.author_name}]} {white ${commit.message}}`;
|
|
16
|
+
addOption({ label, id: commit.hash, ...commit });
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
const commitHashes = selected.map(commit => commit.hash);
|
|
20
|
+
console.log(commitHashes.join('\n'));
|
|
21
|
+
}
|
|
22
|
+
exports.default = selectCommit;
|
package/dist/index.js
CHANGED
|
@@ -4,9 +4,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
7
8
|
const yargs_1 = __importDefault(require("yargs"));
|
|
8
9
|
const pr_1 = __importDefault(require("./cmd/pr"));
|
|
10
|
+
const select_commit_1 = __importDefault(require("./cmd/select-commit"));
|
|
9
11
|
yargs_1.default(process.argv.slice(2))
|
|
12
|
+
.option('color', {
|
|
13
|
+
boolean: true,
|
|
14
|
+
desc: 'Use colored output (default: auto-detect)',
|
|
15
|
+
})
|
|
16
|
+
.middleware(args => {
|
|
17
|
+
if (args.color !== undefined) {
|
|
18
|
+
chalk_1.default.level = args.color ? 3 : 0;
|
|
19
|
+
}
|
|
20
|
+
}, true)
|
|
10
21
|
.command('pr', 'Create and update PRs', pr_1.default)
|
|
22
|
+
.command('select-commit', 'Select a commit hash', select_commit_1.default)
|
|
11
23
|
.demandCommand(1, '')
|
|
12
24
|
.parse();
|
package/dist/utils.js
CHANGED
|
@@ -3,13 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.branchFromMessage = exports.getHubToken = exports.getRepoPath = exports.getRepoKey = void 0;
|
|
6
|
+
exports.branchFromMessage = exports.getHubToken = exports.getRepoPath = exports.getEmailUsername = exports.getRepoKey = void 0;
|
|
7
7
|
const git_url_parse_1 = __importDefault(require("git-url-parse"));
|
|
8
8
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
9
9
|
const simple_git_1 = __importDefault(require("simple-git"));
|
|
10
10
|
const fs_1 = require("fs");
|
|
11
11
|
const path_1 = __importDefault(require("path"));
|
|
12
|
-
const BRANCH_PREFIX = 'evanpurkhiser/';
|
|
13
12
|
/**
|
|
14
13
|
* Get's the current repo information
|
|
15
14
|
*/
|
|
@@ -24,6 +23,14 @@ async function getRepoKey() {
|
|
|
24
23
|
return repoKey;
|
|
25
24
|
}
|
|
26
25
|
exports.getRepoKey = getRepoKey;
|
|
26
|
+
/**
|
|
27
|
+
* Get the git username from email
|
|
28
|
+
*/
|
|
29
|
+
async function getEmailUsername() {
|
|
30
|
+
const email = await simple_git_1.default().raw('config', '--get', 'user.email');
|
|
31
|
+
return email.split('@')[0].toLowerCase();
|
|
32
|
+
}
|
|
33
|
+
exports.getEmailUsername = getEmailUsername;
|
|
27
34
|
/**
|
|
28
35
|
* Get's the absolute path to the current git repo
|
|
29
36
|
*/
|
|
@@ -44,12 +51,12 @@ exports.getHubToken = getHubToken;
|
|
|
44
51
|
/**
|
|
45
52
|
* Generates a consistent branch name from a commit message
|
|
46
53
|
*/
|
|
47
|
-
function branchFromMessage(commitMessage) {
|
|
54
|
+
function branchFromMessage(prefix, commitMessage) {
|
|
48
55
|
const branch = commitMessage
|
|
49
56
|
.toLowerCase()
|
|
50
57
|
.replaceAll(/[^0-9a-zA-Z]/g, '-')
|
|
51
58
|
.replaceAll(/-+/g, '-')
|
|
52
59
|
.slice(0, 255);
|
|
53
|
-
return
|
|
60
|
+
return `${prefix}/${branch}`;
|
|
54
61
|
}
|
|
55
62
|
exports.branchFromMessage = branchFromMessage;
|
package/package.json
CHANGED