@evanpurkhiser/tooling-personal 1.13.0 → 1.17.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
@@ -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);
@@ -71,12 +72,15 @@ async function pr() {
71
72
  // the end of the list.
72
73
  const rebaseContents = [
73
74
  ...selectedShas,
74
- ...commits.all.filter(c => !selectedShas.includes(c.hash)).map(c => c.hash),
75
+ ...commits.all
76
+ .filter(c => !selectedShas.includes(c.hash))
77
+ .map(c => c.hash)
78
+ .reverse(),
75
79
  ]
76
80
  .map(sha => `pick ${sha}`)
77
81
  .join('\n');
78
82
  const targetCommit = selectedCommits[selectedCommits.length - 1];
79
- const branchName = utils_1.branchFromMessage(targetCommit.message);
83
+ const branchName = utils_1.branchFromMessage(username, targetCommit.message);
80
84
  const willOpenPr = prs.some(pr => pr.headRefName === branchName);
81
85
  // 03. Rebase and push the selected commits
82
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,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.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"));
@@ -24,6 +24,14 @@ async function getRepoKey() {
24
24
  return repoKey;
25
25
  }
26
26
  exports.getRepoKey = getRepoKey;
27
+ /**
28
+ * Get the git username from email
29
+ */
30
+ async function getEmailUsername() {
31
+ const email = await simple_git_1.default().raw('config', '--get', 'user.email');
32
+ return email.split('@')[0].toLowerCase();
33
+ }
34
+ exports.getEmailUsername = getEmailUsername;
27
35
  /**
28
36
  * Get's the absolute path to the current git repo
29
37
  */
@@ -44,7 +52,7 @@ exports.getHubToken = getHubToken;
44
52
  /**
45
53
  * Generates a consistent branch name from a commit message
46
54
  */
47
- function branchFromMessage(commitMessage) {
55
+ function branchFromMessage(prefix, commitMessage) {
48
56
  const branch = commitMessage
49
57
  .toLowerCase()
50
58
  .replaceAll(/[^0-9a-zA-Z]/g, '-')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evanpurkhiser/tooling-personal",
3
- "version": "1.13.0",
3
+ "version": "1.17.0",
4
4
  "description": "Evan Purkhiser's personal tooling",
5
5
  "repository": "https://github.com/EvanPurkhiser/tooling-personal",
6
6
  "author": "Evan Purkhiser",