@evanpurkhiser/tooling-personal 1.16.0 → 1.19.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 +22 -6
- package/dist/editor.js +8 -5
- 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,13 +80,21 @@ 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 () => {
|
|
86
|
-
|
|
87
|
+
const rebase = simple_git_1.default()
|
|
87
88
|
.env({ ...process.env, GIT_SEQUENCE_EDITOR: `echo "${rebaseContents}" >` })
|
|
88
89
|
.rebase(['--interactive', '--autostash', 'origin/master']);
|
|
90
|
+
try {
|
|
91
|
+
await rebase;
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
// Abort a failed rebase
|
|
95
|
+
await simple_git_1.default().rebase(['--abort']);
|
|
96
|
+
throw new Error(`Failed to rebase\n${error}`);
|
|
97
|
+
}
|
|
89
98
|
};
|
|
90
99
|
const doPush = async () => {
|
|
91
100
|
const newCommits = await getCommits();
|
|
@@ -106,12 +115,19 @@ async function pr() {
|
|
|
106
115
|
// Cork stdout to avoid listr output polluting vim. We'll uncork after we
|
|
107
116
|
// close vim
|
|
108
117
|
process.stdout.cork();
|
|
109
|
-
const rebaseAndPush = rebaseAndPushTask.run();
|
|
110
|
-
const { title, body } = await editor_1.editPullRequest(targetCommit);
|
|
111
118
|
// 05. Open an editor to write the pull request
|
|
119
|
+
const { editor, editorResult } = await editor_1.editPullRequest(targetCommit);
|
|
120
|
+
const rebaseAndPush = rebaseAndPushTask.run();
|
|
121
|
+
rebaseAndPush.catch(() => editor.kill());
|
|
122
|
+
const { title, body } = await editorResult;
|
|
112
123
|
// XXX: We cork stdout here to avoid listr from corrupting vims output
|
|
113
124
|
process.stdout.uncork();
|
|
114
|
-
|
|
125
|
+
try {
|
|
126
|
+
await rebaseAndPush;
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
115
131
|
if (title.length === 0) {
|
|
116
132
|
console.log(chalk_1.default.red `Missing PR title, aborting`);
|
|
117
133
|
process.exit(1);
|
package/dist/editor.js
CHANGED
|
@@ -18,10 +18,13 @@ async function editPullRequest(commit) {
|
|
|
18
18
|
shell: true,
|
|
19
19
|
stdio: 'inherit',
|
|
20
20
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
async function getResult() {
|
|
22
|
+
await new Promise(resolve => editor.on('close', resolve));
|
|
23
|
+
const prContents = await promises_1.default.readFile(pullEditFile).then(b => b.toString());
|
|
24
|
+
const [title, ...bodyParts] = prContents.split('\n');
|
|
25
|
+
const body = bodyParts.join('\n').trim();
|
|
26
|
+
return { title, body };
|
|
27
|
+
}
|
|
28
|
+
return { editor, editorResult: getResult() };
|
|
26
29
|
}
|
|
27
30
|
exports.editPullRequest = editPullRequest;
|
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