@evanpurkhiser/tooling-personal 1.28.0 → 1.30.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 +20 -11
- package/dist/cmd/select-commit.js +3 -1
- package/dist/index.js +1 -1
- package/dist/pulls.js +12 -5
- package/dist/utils.js +23 -2
- package/package.json +1 -1
package/dist/cmd/pr.js
CHANGED
|
@@ -16,29 +16,37 @@ const utils_1 = require("../utils");
|
|
|
16
16
|
function getCommits(to) {
|
|
17
17
|
return simple_git_1.default().log({ from: 'HEAD', to });
|
|
18
18
|
}
|
|
19
|
-
async function pr() {
|
|
19
|
+
async function pr(argv) {
|
|
20
20
|
const username = await utils_1.getEmailUsername();
|
|
21
21
|
const repo = await utils_1.getRepoKey();
|
|
22
|
+
const { head, origin } = await utils_1.getBranchNames();
|
|
23
|
+
if (head === null) {
|
|
24
|
+
throw new Error('Cannot determine HEAD branch name');
|
|
25
|
+
}
|
|
26
|
+
if (origin === null) {
|
|
27
|
+
throw new Error('Cannot determine upstream HEAD branch name');
|
|
28
|
+
}
|
|
22
29
|
const rendererOptions = { showTimer: true };
|
|
23
30
|
const collectInfoTask = new listr2_1.Listr([], {
|
|
24
31
|
concurrent: true,
|
|
25
32
|
rendererOptions,
|
|
26
33
|
});
|
|
27
34
|
collectInfoTask.add({
|
|
28
|
-
title: 'Fetching
|
|
35
|
+
title: 'Fetching repository info',
|
|
29
36
|
task: async (ctx, task) => {
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
37
|
+
const details = await pulls_1.getRepoInfo(repo);
|
|
38
|
+
if (details === null) {
|
|
32
39
|
throw new Error('Failed to get repository ID');
|
|
33
40
|
}
|
|
34
|
-
task.title = 'Found repository
|
|
35
|
-
ctx.repoId = repoId;
|
|
41
|
+
task.title = 'Found repository';
|
|
42
|
+
ctx.repoId = details.repoId;
|
|
43
|
+
ctx.defaultBranch = details.defaultBranch;
|
|
36
44
|
},
|
|
37
45
|
});
|
|
38
46
|
collectInfoTask.add({
|
|
39
47
|
title: 'Getting unpublished commits',
|
|
40
48
|
task: async (ctx, task) => {
|
|
41
|
-
const commits = await getCommits(
|
|
49
|
+
const commits = await getCommits(origin);
|
|
42
50
|
if (commits.total === 0) {
|
|
43
51
|
throw new Error('No commits to push');
|
|
44
52
|
}
|
|
@@ -53,7 +61,7 @@ async function pr() {
|
|
|
53
61
|
task.title = `Found ${ctx.prs.length} existing PRs`;
|
|
54
62
|
},
|
|
55
63
|
});
|
|
56
|
-
const { repoId, commits, prs } = await collectInfoTask.run();
|
|
64
|
+
const { repoId, defaultBranch, commits, prs } = await collectInfoTask.run();
|
|
57
65
|
const selectCommits = () => fzf_1.fzfSelect({
|
|
58
66
|
prompt: 'Select commit(s) for PR:',
|
|
59
67
|
genValues: addOption => commits.all.forEach(commit => {
|
|
@@ -89,7 +97,7 @@ async function pr() {
|
|
|
89
97
|
const doRebase = async () => {
|
|
90
98
|
const rebase = simple_git_1.default()
|
|
91
99
|
.env({ ...process.env, GIT_SEQUENCE_EDITOR: `echo "${rebaseContents}" >` })
|
|
92
|
-
.rebase(['--interactive', '--autostash',
|
|
100
|
+
.rebase(['--interactive', '--autostash', origin]);
|
|
93
101
|
try {
|
|
94
102
|
await rebase;
|
|
95
103
|
}
|
|
@@ -100,7 +108,7 @@ async function pr() {
|
|
|
100
108
|
}
|
|
101
109
|
};
|
|
102
110
|
const doPush = async () => {
|
|
103
|
-
const newCommits = await getCommits(
|
|
111
|
+
const newCommits = await getCommits(origin);
|
|
104
112
|
const commitIdx = newCommits.all.length - selectedCommits.length;
|
|
105
113
|
const rebaseTargetCommit = newCommits.all[commitIdx];
|
|
106
114
|
const refSpec = `${rebaseTargetCommit.hash}:refs/heads/${branchName}`;
|
|
@@ -137,9 +145,10 @@ async function pr() {
|
|
|
137
145
|
}
|
|
138
146
|
// 06. Create a Pull Request
|
|
139
147
|
const pr = pulls_1.createPull({
|
|
140
|
-
baseRefName:
|
|
148
|
+
baseRefName: defaultBranch,
|
|
141
149
|
headRefName: branchName,
|
|
142
150
|
repositoryId: repoId,
|
|
151
|
+
draft: argv.draft,
|
|
143
152
|
title,
|
|
144
153
|
body,
|
|
145
154
|
});
|
|
@@ -7,8 +7,10 @@ exports.selectCommit = void 0;
|
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const simple_git_1 = __importDefault(require("simple-git"));
|
|
9
9
|
const fzf_1 = require("../fzf");
|
|
10
|
+
const utils_1 = require("../utils");
|
|
10
11
|
async function selectCommit() {
|
|
11
|
-
const
|
|
12
|
+
const { origin } = await utils_1.getBranchNames();
|
|
13
|
+
const commits = await simple_git_1.default().log({ from: 'HEAD', to: origin });
|
|
12
14
|
const selected = await fzf_1.fzfSelect({
|
|
13
15
|
prompt: 'Select commit(s):',
|
|
14
16
|
genValues: addOption => commits.all.forEach(commit => {
|
package/dist/index.js
CHANGED
|
@@ -18,7 +18,7 @@ yargs_1.default(process.argv.slice(2))
|
|
|
18
18
|
chalk_1.default.level = args.color ? 3 : 0;
|
|
19
19
|
}
|
|
20
20
|
}, true)
|
|
21
|
-
.command('pr', 'Create and update PRs', pr_1.pr)
|
|
21
|
+
.command('pr', 'Create and update PRs', y => y.option('draft', { alias: 'd', boolean: true, desc: 'Create PR as a draft' }), pr_1.pr)
|
|
22
22
|
.command('select-commit', 'Select a commit hash', select_commit_1.selectCommit)
|
|
23
23
|
.demandCommand(1, '')
|
|
24
24
|
.parse();
|
package/dist/pulls.js
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requestReview = exports.createPull = exports.getPulls = exports.
|
|
3
|
+
exports.requestReview = exports.createPull = exports.getPulls = exports.getRepoInfo = void 0;
|
|
4
4
|
const graphql_request_1 = require("graphql-request");
|
|
5
5
|
const graphql_1 = require("./graphql");
|
|
6
|
-
async function
|
|
6
|
+
async function getRepoInfo(repo) {
|
|
7
7
|
const repoGql = graphql_request_1.gql `
|
|
8
8
|
query repo($owner: String!, $repo: String!) {
|
|
9
9
|
repository(owner: $owner, name: $repo) {
|
|
10
10
|
id
|
|
11
|
+
defaultBranchRef {
|
|
12
|
+
name
|
|
13
|
+
}
|
|
11
14
|
}
|
|
12
15
|
}
|
|
13
16
|
`;
|
|
17
|
+
let resp = null;
|
|
14
18
|
try {
|
|
15
|
-
|
|
16
|
-
return resp.repository.id;
|
|
19
|
+
resp = await graphql_1.request(repoGql, { ...repo });
|
|
17
20
|
}
|
|
18
21
|
catch {
|
|
19
22
|
return null;
|
|
20
23
|
}
|
|
24
|
+
return {
|
|
25
|
+
repoId: resp.repository.id,
|
|
26
|
+
defaultBranch: resp.repository.defaultBranchRef.name,
|
|
27
|
+
};
|
|
21
28
|
}
|
|
22
|
-
exports.
|
|
29
|
+
exports.getRepoInfo = getRepoInfo;
|
|
23
30
|
/**
|
|
24
31
|
* Get your open pull requests for this repo
|
|
25
32
|
*/
|
package/dist/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.getAccessToken = exports.getRepoPath = exports.getEmailUsername = exports.getRepoKey = void 0;
|
|
6
|
+
exports.branchFromMessage = exports.getAccessToken = exports.getBranchNames = 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"));
|
|
@@ -13,7 +13,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
13
13
|
* Get's the current repo information
|
|
14
14
|
*/
|
|
15
15
|
async function getRepoKey() {
|
|
16
|
-
const url = await simple_git_1.default().
|
|
16
|
+
const url = await simple_git_1.default().listRemote(['--get-url', 'origin']);
|
|
17
17
|
const repo = git_url_parse_1.default(url);
|
|
18
18
|
const repoKey = {
|
|
19
19
|
owner: repo.owner,
|
|
@@ -39,6 +39,27 @@ async function getRepoPath() {
|
|
|
39
39
|
return path.trim();
|
|
40
40
|
}
|
|
41
41
|
exports.getRepoPath = getRepoPath;
|
|
42
|
+
/**
|
|
43
|
+
* Get's the "default" head and origin branch names
|
|
44
|
+
*/
|
|
45
|
+
async function getBranchNames() {
|
|
46
|
+
let head = null;
|
|
47
|
+
let origin = null;
|
|
48
|
+
try {
|
|
49
|
+
head = await simple_git_1.default().revparse(['--abbrev-ref', 'HEAD']);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// null
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
origin = await simple_git_1.default().revparse(['--abbrev-ref', '@{upstream}']);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// null
|
|
59
|
+
}
|
|
60
|
+
return { head, origin };
|
|
61
|
+
}
|
|
62
|
+
exports.getBranchNames = getBranchNames;
|
|
42
63
|
/**
|
|
43
64
|
* Get's the GitHub Oauth token from the hub config
|
|
44
65
|
*/
|
package/package.json
CHANGED