@waron97/prbot 3.6.0 → 3.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waron97/prbot",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -1,5 +1,6 @@
1
1
  import { readFileSync } from 'fs';
2
2
  import fs from 'fs/promises';
3
+ import path from 'path';
3
4
  import search from '@inquirer/search';
4
5
  import inquirer from 'inquirer';
5
6
  import fetch from 'node-fetch';
@@ -218,6 +219,11 @@ async function autoprAmend(options) {
218
219
  }
219
220
 
220
221
  async function autopr(options) {
222
+ if (options.worktree && options.amend) {
223
+ throw new Error(
224
+ '--worktree cannot be combined with --amend (amend operates on the already-checked-out branch)'
225
+ );
226
+ }
221
227
  if (options.amend) return autoprAmend(options);
222
228
 
223
229
  const ADDONS_PATH = resolveAddonsPath(process.env.ADDONS_PATH);
@@ -263,9 +269,20 @@ async function autopr(options) {
263
269
  }
264
270
  }
265
271
 
266
- await execGit(['checkout', '-b', branch], ADDONS_PATH);
267
- log(`Branch created: ${branch}`);
268
- await execGit(['push', '-u', 'origin', branch], ADDONS_PATH);
272
+ let repoRoot = ADDONS_PATH;
273
+ if (options.worktree) {
274
+ const worktreePath =
275
+ typeof options.worktree === 'string'
276
+ ? path.resolve(options.worktree)
277
+ : path.join(path.dirname(ADDONS_PATH), `${path.basename(ADDONS_PATH)}-${branch}`);
278
+ await execGit(['worktree', 'add', worktreePath, '-b', branch], ADDONS_PATH);
279
+ log(`Worktree created: ${worktreePath}`);
280
+ repoRoot = worktreePath;
281
+ } else {
282
+ await execGit(['checkout', '-b', branch], ADDONS_PATH);
283
+ log(`Branch created: ${branch}`);
284
+ }
285
+ await execGit(['push', '-u', 'origin', branch], repoRoot);
269
286
 
270
287
  const prTitle = options.name ?? tasks[0]?.name ?? branch;
271
288
  const prDescription = buildPrDescription(ids, options.jira ?? []);
@@ -313,13 +330,17 @@ async function autopr(options) {
313
330
  lines.splice(endLine + 1, 0, newEntry);
314
331
  }
315
332
 
316
- await fs.writeFile(changelogPath, lines.join('\n'));
333
+ await fs.writeFile(`${repoRoot}/CHANGELOG.md`, lines.join('\n'));
317
334
  log('Changelog entry written');
318
335
 
319
- await execGit(['add', 'CHANGELOG.md'], ADDONS_PATH);
320
- await execGit(['commit', '-m', '[DOC][CHANGELOG] Changelog'], ADDONS_PATH);
321
- await execGit(['push'], ADDONS_PATH);
336
+ await execGit(['add', 'CHANGELOG.md'], repoRoot);
337
+ await execGit(['commit', '-m', '[DOC][CHANGELOG] Changelog'], repoRoot);
338
+ await execGit(['push'], repoRoot);
322
339
  log('Changelog committed and pushed');
340
+
341
+ if (repoRoot !== ADDONS_PATH) {
342
+ log(`\nContinue working in: ${repoRoot}`);
343
+ }
323
344
  }
324
345
 
325
346
  export { autopr };
@@ -73,6 +73,7 @@ function generateXml(templates) {
73
73
  <field name="subject">${escapeXml(t.subject)}</field>
74
74
  <field name="email_from">${escapeXml(t.email_from)}</field>
75
75
  <field name="email_to">${escapeXml(t.email_to)}</field>
76
+ <field name="lang">${escapeXml(t.lang)}</field>
76
77
  <field name="body_html" type="html">
77
78
  ${sanitizeBodyHtml(t.body_html)}
78
79
  </field>
@@ -23,7 +23,8 @@ async function init() {
23
23
  {
24
24
  type: 'input',
25
25
  name: 'ADDONS_PATH',
26
- message: 'Addons path:',
26
+ message:
27
+ "Addons path ('.' or blank = use the repo in the current directory, e.g. a worktree):",
27
28
  default: existing.ADDONS_PATH ?? '~/codebase/sorgenia/addons',
28
29
  },
29
30
  {
package/src/index.js CHANGED
@@ -136,6 +136,10 @@ program
136
136
  .option('-b, --branch <name>', 'Branch name (default: autopr_<taskId>)')
137
137
  .option('-n, --name <text>', 'PR title (default: task name from Odoo)')
138
138
  .option('--amend', 'Amend existing PR on current branch with new trident/jira refs')
139
+ .option(
140
+ '--worktree [path]',
141
+ 'Create the branch in a new git worktree instead of switching the current checkout; optional path overrides the default sibling directory'
142
+ )
139
143
  .action(async (opts) => {
140
144
  await autopr(opts);
141
145
  });
package/src/lib/addons.js CHANGED
@@ -1,8 +1,15 @@
1
- function resolveAddonsPath(addonsPath) {
2
- if (addonsPath.startsWith('~')) {
3
- return addonsPath.replace('~', process.env.HOME);
1
+ function resolveAddonsPath(addonsPath = process.env.ADDONS_PATH) {
2
+ const value = (addonsPath ?? '').trim();
3
+ // Unset, empty, or the explicit "." sentinel => operate on the repo in
4
+ // the current working directory (e.g. a git worktree), instead of a
5
+ // fixed global checkout.
6
+ if (value === '' || value === '.') {
7
+ return process.cwd();
4
8
  }
5
- return addonsPath;
9
+ if (value.startsWith('~')) {
10
+ return value.replace('~', process.env.HOME);
11
+ }
12
+ return value;
6
13
  }
7
14
 
8
15
  export { resolveAddonsPath };