@evanpurkhiser/tooling-personal 1.27.0 → 1.29.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 CHANGED
@@ -3,6 +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.pr = void 0;
6
7
  const chalk_1 = __importDefault(require("chalk"));
7
8
  const listr2_1 = require("listr2");
8
9
  const open_1 = __importDefault(require("open"));
@@ -18,26 +19,34 @@ function getCommits(to) {
18
19
  async function pr() {
19
20
  const username = await utils_1.getEmailUsername();
20
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
+ }
21
29
  const rendererOptions = { showTimer: true };
22
30
  const collectInfoTask = new listr2_1.Listr([], {
23
31
  concurrent: true,
24
32
  rendererOptions,
25
33
  });
26
34
  collectInfoTask.add({
27
- title: 'Fetching repsotiry ID',
35
+ title: 'Fetching repository info',
28
36
  task: async (ctx, task) => {
29
- const repoId = await pulls_1.getGithubRepoId(repo);
30
- if (repoId === null) {
37
+ const details = await pulls_1.getRepoInfo(repo);
38
+ if (details === null) {
31
39
  throw new Error('Failed to get repository ID');
32
40
  }
33
- task.title = 'Found repository ID';
34
- ctx.repoId = repoId;
41
+ task.title = 'Found repository';
42
+ ctx.repoId = details.repoId;
43
+ ctx.defaultBranch = details.defaultBranch;
35
44
  },
36
45
  });
37
46
  collectInfoTask.add({
38
47
  title: 'Getting unpublished commits',
39
48
  task: async (ctx, task) => {
40
- const commits = await getCommits('origin/master');
49
+ const commits = await getCommits(origin);
41
50
  if (commits.total === 0) {
42
51
  throw new Error('No commits to push');
43
52
  }
@@ -52,7 +61,7 @@ async function pr() {
52
61
  task.title = `Found ${ctx.prs.length} existing PRs`;
53
62
  },
54
63
  });
55
- const { repoId, commits, prs } = await collectInfoTask.run();
64
+ const { repoId, defaultBranch, commits, prs } = await collectInfoTask.run();
56
65
  const selectCommits = () => fzf_1.fzfSelect({
57
66
  prompt: 'Select commit(s) for PR:',
58
67
  genValues: addOption => commits.all.forEach(commit => {
@@ -88,7 +97,7 @@ async function pr() {
88
97
  const doRebase = async () => {
89
98
  const rebase = simple_git_1.default()
90
99
  .env({ ...process.env, GIT_SEQUENCE_EDITOR: `echo "${rebaseContents}" >` })
91
- .rebase(['--interactive', '--autostash', 'origin/master']);
100
+ .rebase(['--interactive', '--autostash', origin]);
92
101
  try {
93
102
  await rebase;
94
103
  }
@@ -99,7 +108,7 @@ async function pr() {
99
108
  }
100
109
  };
101
110
  const doPush = async () => {
102
- const newCommits = await getCommits('origin/master');
111
+ const newCommits = await getCommits(origin);
103
112
  const commitIdx = newCommits.all.length - selectedCommits.length;
104
113
  const rebaseTargetCommit = newCommits.all[commitIdx];
105
114
  const refSpec = `${rebaseTargetCommit.hash}:refs/heads/${branchName}`;
@@ -136,7 +145,7 @@ async function pr() {
136
145
  }
137
146
  // 06. Create a Pull Request
138
147
  const pr = pulls_1.createPull({
139
- baseRefName: 'master',
148
+ baseRefName: defaultBranch,
140
149
  headRefName: branchName,
141
150
  repositoryId: repoId,
142
151
  title,
@@ -159,4 +168,4 @@ async function pr() {
159
168
  // 08. Open in browser
160
169
  open_1.default(createPullRequest.pullRequest.url);
161
170
  }
162
- exports.default = pr;
171
+ exports.pr = pr;
@@ -3,11 +3,14 @@ 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.selectCommit = void 0;
6
7
  const chalk_1 = __importDefault(require("chalk"));
7
8
  const simple_git_1 = __importDefault(require("simple-git"));
8
9
  const fzf_1 = require("../fzf");
10
+ const utils_1 = require("../utils");
9
11
  async function selectCommit() {
10
- const commits = await simple_git_1.default().log({ from: 'HEAD', to: 'origin/master' });
12
+ const { origin } = await utils_1.getBranchNames();
13
+ const commits = await simple_git_1.default().log({ from: 'HEAD', to: origin });
11
14
  const selected = await fzf_1.fzfSelect({
12
15
  prompt: 'Select commit(s):',
13
16
  genValues: addOption => commits.all.forEach(commit => {
@@ -19,4 +22,4 @@ async function selectCommit() {
19
22
  const commitHashes = selected.map(commit => commit.hash);
20
23
  console.log(commitHashes.join('\n'));
21
24
  }
22
- exports.default = selectCommit;
25
+ exports.selectCommit = selectCommit;
package/dist/fzf.js CHANGED
@@ -13,11 +13,19 @@ async function fzfSelect({ prompt, genValues, }) {
13
13
  ], { shell: true, stdio: ['pipe', 'pipe', 'inherit'] });
14
14
  fzf.stdin.setDefaultEncoding('utf-8');
15
15
  const options = {};
16
- await genValues(option => {
16
+ const valuesDone = genValues(option => {
17
+ if (fzf.stdin.destroyed) {
18
+ return;
19
+ }
17
20
  options[option.id] = option;
18
21
  fzf.stdin.write(`${option.id}\t${option.label.trim()}\n`);
19
22
  });
20
- fzf.stdin.end();
23
+ if (valuesDone instanceof Promise) {
24
+ valuesDone.then(() => fzf.stdin.end());
25
+ }
26
+ else {
27
+ fzf.stdin.end();
28
+ }
21
29
  const output = await new Promise(resolve => fzf.stdout.once('data', d => resolve(d.toString())));
22
30
  return output
23
31
  .split('\n')
package/dist/index.js CHANGED
@@ -6,8 +6,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const yargs_1 = __importDefault(require("yargs"));
9
- const pr_1 = __importDefault(require("./cmd/pr"));
10
- const select_commit_1 = __importDefault(require("./cmd/select-commit"));
9
+ const pr_1 = require("./cmd/pr");
10
+ const select_commit_1 = require("./cmd/select-commit");
11
11
  yargs_1.default(process.argv.slice(2))
12
12
  .option('color', {
13
13
  boolean: true,
@@ -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.default)
22
- .command('select-commit', 'Select a commit hash', select_commit_1.default)
21
+ .command('pr', 'Create and update PRs', pr_1.pr)
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.getGithubRepoId = void 0;
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 getGithubRepoId(repo) {
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
- const resp = await graphql_1.request(repoGql, { ...repo });
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.getGithubRepoId = getGithubRepoId;
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().raw('config', '--get', 'remote.origin.url');
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evanpurkhiser/tooling-personal",
3
- "version": "1.27.0",
3
+ "version": "1.29.0",
4
4
  "description": "Evan Purkhiser's personal tooling",
5
5
  "repository": "https://github.com/evanpurkhiser/tooling-personal",
6
6
  "author": "Evan Purkhiser",
@@ -27,7 +27,7 @@
27
27
  "yargs": "^17.0.1"
28
28
  },
29
29
  "devDependencies": {
30
- "@evanpurkhiser/eslint-config": "^0.17.0",
30
+ "@evanpurkhiser/eslint-config": "^0.20.0",
31
31
  "@tsconfig/node16": "^1.0.1",
32
32
  "eslint": "^8.45.0",
33
33
  "prettier": "^3.0.0",