@evanpurkhiser/tooling-personal 1.28.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
@@ -19,26 +19,34 @@ function getCommits(to) {
19
19
  async function pr() {
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 repsotiry ID',
35
+ title: 'Fetching repository info',
29
36
  task: async (ctx, task) => {
30
- const repoId = await pulls_1.getGithubRepoId(repo);
31
- if (repoId === null) {
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 ID';
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('origin/master');
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', 'origin/master']);
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('origin/master');
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,7 +145,7 @@ async function pr() {
137
145
  }
138
146
  // 06. Create a Pull Request
139
147
  const pr = pulls_1.createPull({
140
- baseRefName: 'master',
148
+ baseRefName: defaultBranch,
141
149
  headRefName: branchName,
142
150
  repositoryId: repoId,
143
151
  title,
@@ -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 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 });
12
14
  const selected = await fzf_1.fzfSelect({
13
15
  prompt: 'Select commit(s):',
14
16
  genValues: addOption => commits.all.forEach(commit => {
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.28.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",