@evanpurkhiser/tooling-personal 1.47.0 → 1.48.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.
@@ -50,9 +50,6 @@ async function resolveReviewers(repo, slugs) {
50
50
  return found;
51
51
  }
52
52
  async function prCreate(argv) {
53
- if (!argv.title && !argv.updateOnly) {
54
- throw new Error('--title is required when creating a PR');
55
- }
56
53
  const username = await (0, utils_1.getEmailUsername)();
57
54
  const repo = await (0, utils_1.getRepoKey)();
58
55
  const { head, origin } = await (0, utils_1.getBranchNames)();
@@ -78,22 +75,15 @@ async function prCreate(argv) {
78
75
  }
79
76
  const branchName = (0, utils_1.branchFromMessage)(username, commit.message);
80
77
  const existingPr = prs.find(p => p.headRefName === branchName);
81
- if (argv.updateOnly && !existingPr) {
82
- throw new Error(`No existing PR for branch ${branchName}`);
78
+ if (existingPr) {
79
+ throw new Error(`PR already exists for branch ${branchName} (#${existingPr.number}). Use 'pr-update' to push changes.`);
83
80
  }
84
81
  const reviewerSlugs = parseSlugs(argv.reviewer);
85
- // Reviewers only apply on PR creation (matches `pt pr` behavior).
86
- const reviewers = existingPr ? [] : await resolveReviewers(repo, reviewerSlugs);
82
+ const reviewers = await resolveReviewers(repo, reviewerSlugs);
87
83
  console.error(chalk_1.default.gray(`Cherry-picking ${commit.hash.slice(0, 8)} onto ${origin}`));
88
84
  const newSha = await (0, cherry_pick_1.cherryPickOnto)(commit.hash, origin);
89
85
  console.error(chalk_1.default.gray(`Pushing ${branchName}`));
90
86
  await (0, simple_git_1.default)().push(['--force', 'origin', `${newSha}:refs/heads/${branchName}`]);
91
- if (existingPr) {
92
- const url = `https://github.com/${repo.fullName}/pull/${existingPr.number}`;
93
- console.error(chalk_1.default.green(`Updated existing PR #${existingPr.number}: ${existingPr.title}`));
94
- console.log(url);
95
- return;
96
- }
97
87
  console.error(chalk_1.default.gray('Creating Pull Request'));
98
88
  const { createPullRequest } = await (0, pulls_1.createPull)({
99
89
  baseRefName: repoDetails.defaultBranch,
@@ -0,0 +1,40 @@
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
+ exports.prUpdate = prUpdate;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const simple_git_1 = __importDefault(require("simple-git"));
9
+ const cherry_pick_1 = require("../cherry-pick");
10
+ const pulls_1 = require("../pulls");
11
+ const utils_1 = require("../utils");
12
+ async function prUpdate(argv) {
13
+ const username = await (0, utils_1.getEmailUsername)();
14
+ const repo = await (0, utils_1.getRepoKey)();
15
+ const { head, origin } = await (0, utils_1.getBranchNames)();
16
+ if (head === null) {
17
+ throw new Error('Cannot determine HEAD branch name');
18
+ }
19
+ if (origin === null) {
20
+ throw new Error('Cannot determine upstream HEAD branch name');
21
+ }
22
+ const unpublished = (0, simple_git_1.default)().log({ from: 'HEAD', to: origin });
23
+ const [commits, prs] = await Promise.all([unpublished, (0, pulls_1.getPulls)(repo)]);
24
+ const commit = commits.all.find(c => c.hash.startsWith(argv.sha));
25
+ if (!commit) {
26
+ throw new Error(`Commit ${argv.sha} not found in unpublished commits`);
27
+ }
28
+ const branchName = (0, utils_1.branchFromMessage)(username, commit.message);
29
+ const existingPr = prs.find(p => p.headRefName === branchName);
30
+ if (!existingPr) {
31
+ throw new Error(`No existing PR for branch ${branchName}. Use 'pr-create' to open one.`);
32
+ }
33
+ console.error(chalk_1.default.gray(`Cherry-picking ${commit.hash.slice(0, 8)} onto ${origin}`));
34
+ const newSha = await (0, cherry_pick_1.cherryPickOnto)(commit.hash, origin);
35
+ console.error(chalk_1.default.gray(`Pushing ${branchName}`));
36
+ await (0, simple_git_1.default)().push(['--force', 'origin', `${newSha}:refs/heads/${branchName}`]);
37
+ const url = `https://github.com/${repo.fullName}/pull/${existingPr.number}`;
38
+ console.error(chalk_1.default.green(`Updated existing PR #${existingPr.number}: ${existingPr.title}`));
39
+ console.log(url);
40
+ }
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ const chalk_1 = __importDefault(require("chalk"));
8
8
  const yargs_1 = __importDefault(require("yargs"));
9
9
  const pr_1 = require("./cmd/pr");
10
10
  const pr_create_1 = require("./cmd/pr-create");
11
+ const pr_update_1 = require("./cmd/pr-update");
11
12
  const select_commit_1 = require("./cmd/select-commit");
12
13
  const suggest_assignees_1 = require("./cmd/suggest-assignees");
13
14
  (0, yargs_1.default)(process.argv.slice(2))
@@ -31,7 +32,7 @@ const suggest_assignees_1 = require("./cmd/suggest-assignees");
31
32
  boolean: true,
32
33
  desc: 'Enable auto merge for the PR',
33
34
  }), pr_1.pr)
34
- .command('pr-create <sha>', 'Non-interactively create or update a PR for a single commit. Body is read from stdin.', y => y
35
+ .command('pr-create <sha>', 'Non-interactively create a PR for a single commit. Body is read from stdin.', y => y
35
36
  .positional('sha', {
36
37
  type: 'string',
37
38
  demandOption: true,
@@ -55,15 +56,16 @@ const suggest_assignees_1 = require("./cmd/suggest-assignees");
55
56
  alias: 'm',
56
57
  boolean: true,
57
58
  desc: 'Enable auto merge for the PR',
58
- })
59
- .option('updateOnly', {
60
- boolean: true,
61
- desc: 'Only update an existing PR; fail if none exists for the generated branch',
62
59
  })
63
60
  .option('noOpen', {
64
61
  boolean: true,
65
62
  desc: 'Do not open the PR in the browser after creation',
66
63
  }), pr_create_1.prCreate)
64
+ .command('pr-update <sha>', 'Non-interactively push an amended commit to its existing PR branch.', y => y.positional('sha', {
65
+ type: 'string',
66
+ demandOption: true,
67
+ desc: 'Commit SHA (full or prefix) whose PR branch should be updated',
68
+ }), pr_update_1.prUpdate)
67
69
  .command('suggest-assignees', 'Suggest reviewers for current diff based on blame ownership', y => y
68
70
  .option('commit', {
69
71
  type: 'string',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@evanpurkhiser/tooling-personal",
4
- "version": "1.47.0",
4
+ "version": "1.48.0",
5
5
  "description": "Evan Purkhiser's personal tooling",
6
6
  "license": "MIT",
7
7
  "author": "Evan Purkhiser",