@bretwardjames/ghp-core 0.2.0-beta.1 → 0.2.0-beta.3

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/index.cjs CHANGED
@@ -38,6 +38,7 @@ __export(index_exports, {
38
38
  createBranch: () => createBranch,
39
39
  createWorktree: () => createWorktree,
40
40
  detectRepository: () => detectRepository,
41
+ extractIssueNumberFromBranch: () => extractIssueNumberFromBranch,
41
42
  fetchOrigin: () => fetchOrigin,
42
43
  formatConflict: () => formatConflict,
43
44
  generateBranchName: () => generateBranchName,
@@ -1340,6 +1341,25 @@ function generateBranchName(pattern, vars, maxLength = 60) {
1340
1341
  }
1341
1342
  return branch;
1342
1343
  }
1344
+ function extractIssueNumberFromBranch(branchName) {
1345
+ const patterns = [
1346
+ /\/(\d+)-/,
1347
+ // user/123-title
1348
+ /^(\d+)-/,
1349
+ // 123-title
1350
+ /-(\d+)-/,
1351
+ // feature-123-title
1352
+ /[/#](\d+)$/
1353
+ // ends with #123 or /123
1354
+ ];
1355
+ for (const pattern of patterns) {
1356
+ const match = branchName.match(pattern);
1357
+ if (match) {
1358
+ return parseInt(match[1], 10);
1359
+ }
1360
+ }
1361
+ return null;
1362
+ }
1343
1363
  async function getLocalBranches(options = {}) {
1344
1364
  try {
1345
1365
  const { stdout } = await execGit('git branch --format="%(refname:short)"', options);
@@ -1457,12 +1477,18 @@ async function worktreeExists(worktreePath, options = {}) {
1457
1477
  const worktrees = await listWorktrees(options);
1458
1478
  return worktrees.some((wt) => wt.path === worktreePath);
1459
1479
  }
1460
- function generateWorktreePath(basePath, repoName, identifier) {
1480
+ function generateWorktreePath(basePath, repoName, identifier, title) {
1461
1481
  const safeRepoName = sanitizeForPath(repoName);
1462
- const safeIdentifier = sanitizeForPath(String(identifier));
1482
+ let dirName;
1483
+ if (title && typeof identifier === "number") {
1484
+ const titleSlug = sanitizeForBranchName(title).substring(0, 35).replace(/-$/, "");
1485
+ dirName = `${identifier}-${titleSlug}`;
1486
+ } else {
1487
+ dirName = sanitizeForPath(String(identifier));
1488
+ }
1463
1489
  const expandedBase = basePath.startsWith("~") ? basePath.replace("~", (0, import_os.homedir)()) : basePath;
1464
1490
  const cleanBase = expandedBase.replace(/\/+$/, "");
1465
- return `${cleanBase}/${safeRepoName}/${safeIdentifier}`;
1491
+ return `${cleanBase}/${safeRepoName}/${dirName}`;
1466
1492
  }
1467
1493
 
1468
1494
  // src/sync.ts
@@ -1646,6 +1672,7 @@ function getDiffSummary(diff) {
1646
1672
  createBranch,
1647
1673
  createWorktree,
1648
1674
  detectRepository,
1675
+ extractIssueNumberFromBranch,
1649
1676
  fetchOrigin,
1650
1677
  formatConflict,
1651
1678
  generateBranchName,
package/dist/index.d.cts CHANGED
@@ -629,6 +629,16 @@ declare function generateBranchName(pattern: string, vars: {
629
629
  title: string;
630
630
  repo: string;
631
631
  }, maxLength?: number): string;
632
+ /**
633
+ * Extract issue number from a branch name.
634
+ * Supports common patterns:
635
+ * - user/123-feature-name
636
+ * - feature/123-something
637
+ * - 123-fix-bug
638
+ * - fix-123-something
639
+ * - ends with #123 or /123
640
+ */
641
+ declare function extractIssueNumberFromBranch(branchName: string): number | null;
632
642
  /**
633
643
  * Get all local branches
634
644
  */
@@ -692,13 +702,14 @@ declare function getWorktreeForBranch(branch: string, options?: GitOptions): Pro
692
702
  */
693
703
  declare function worktreeExists(worktreePath: string, options?: GitOptions): Promise<boolean>;
694
704
  /**
695
- * Generate a worktree path based on repo and branch info
705
+ * Generate a worktree path based on repo and issue info
696
706
  * @param basePath - Base directory for worktrees (e.g., ~/.ghp/worktrees)
697
707
  * @param repoName - Repository name
698
708
  * @param identifier - Issue number or branch name to use as identifier
709
+ * @param title - Optional title to create a descriptive directory name (e.g., "123-fix-auth-bug")
699
710
  * @returns Full path to the worktree directory
700
711
  */
701
- declare function generateWorktreePath(basePath: string, repoName: string, identifier: string | number): string;
712
+ declare function generateWorktreePath(basePath: string, repoName: string, identifier: string | number, title?: string): string;
702
713
 
703
714
  /**
704
715
  * URL parsing utilities for GitHub repositories and issues.
@@ -1042,4 +1053,4 @@ declare namespace queries {
1042
1053
  export { queries_ADD_COMMENT_MUTATION as ADD_COMMENT_MUTATION, queries_ADD_LABELS_MUTATION as ADD_LABELS_MUTATION, queries_ADD_TO_PROJECT_MUTATION as ADD_TO_PROJECT_MUTATION, queries_COLLABORATORS_QUERY as COLLABORATORS_QUERY, queries_CREATE_ISSUE_MUTATION as CREATE_ISSUE_MUTATION, queries_ISSUES_WITH_LABEL_QUERY as ISSUES_WITH_LABEL_QUERY, queries_ISSUE_AND_LABEL_QUERY as ISSUE_AND_LABEL_QUERY, queries_ISSUE_DETAILS_QUERY as ISSUE_DETAILS_QUERY, queries_ISSUE_FOR_UPDATE_QUERY as ISSUE_FOR_UPDATE_QUERY, queries_ISSUE_NODE_ID_QUERY as ISSUE_NODE_ID_QUERY, queries_ISSUE_TYPES_QUERY as ISSUE_TYPES_QUERY, queries_LABEL_EXISTS_QUERY as LABEL_EXISTS_QUERY, queries_PROJECT_FIELDS_QUERY as PROJECT_FIELDS_QUERY, queries_PROJECT_ITEMS_QUERY as PROJECT_ITEMS_QUERY, queries_PROJECT_VIEWS_QUERY as PROJECT_VIEWS_QUERY, queries_RECENT_ISSUES_QUERY as RECENT_ISSUES_QUERY, queries_REMOVE_LABELS_MUTATION as REMOVE_LABELS_MUTATION, queries_REPOSITORY_ID_QUERY as REPOSITORY_ID_QUERY, queries_REPOSITORY_PROJECTS_QUERY as REPOSITORY_PROJECTS_QUERY, queries_UPDATE_ISSUE_BODY_MUTATION as UPDATE_ISSUE_BODY_MUTATION, queries_UPDATE_ISSUE_MUTATION as UPDATE_ISSUE_MUTATION, queries_UPDATE_ISSUE_TYPE_MUTATION as UPDATE_ISSUE_TYPE_MUTATION, queries_UPDATE_ITEM_FIELD_MUTATION as UPDATE_ITEM_FIELD_MUTATION, queries_UPDATE_ITEM_STATUS_MUTATION as UPDATE_ITEM_STATUS_MUTATION, queries_VIEWER_QUERY as VIEWER_QUERY };
1043
1054
  }
1044
1055
 
1045
- export { type AssigneeInfo, type AuthError, BranchLinker, CLI_TO_VSCODE_MAP, type Collaborator, type ConflictChoices, type ConflictResolution, DEFAULT_VALUES, type DateFieldValue, type FieldInfo, type FieldValue, type FieldValueConnection, GitHubAPI, type GitHubAPIOptions, type GitOptions, type IssueDetails, type IssueReference, type IterationFieldValue, type LabelInfo, type NumberFieldValue, type Project, type ProjectConfig, type ProjectItem, type ProjectItemContent, type ProjectItemsQueryResponse, type ProjectV2, type ProjectV2Field, type ProjectV2Item, type ProjectV2View, type ProjectWithViews, type ProjectsQueryResponse, type RepoInfo, type ResolvedSettings, SETTING_DISPLAY_NAMES, SYNCABLE_KEYS, type SettingConflict, type SettingsDiff, type SettingsSource, type SingleSelectFieldValue, type StatusField, type SyncableSettingKey, type SyncableSettings, type TextFieldValue, type TokenProvider, VSCODE_TO_CLI_MAP, type WorktreeInfo, branchExists, buildIssueUrl, buildOrgProjectUrl, buildProjectUrl, buildPullRequestUrl, buildRepoUrl, checkoutBranch, computeSettingsDiff, createBranch, createWorktree, detectRepository, fetchOrigin, formatConflict, generateBranchName, generateWorktreePath, getAllBranches, getCommitsAhead, getCommitsBehind, getCurrentBranch, getDefaultBranch, getDiffSummary, getLocalBranches, getRemoteBranches, getRepositoryRoot, getWorktreeForBranch, hasDifferences, hasUncommittedChanges, isGitRepository, listWorktrees, normalizeVSCodeSettings, parseBranchLink, parseGitHubUrl, parseIssueUrl, pullLatest, queries, removeBranchLinkFromBody, removeWorktree, resolveConflicts, sanitizeForBranchName, setBranchLinkInBody, skip, toVSCodeSettings, useCli, useCustom, useVSCode, worktreeExists };
1056
+ export { type AssigneeInfo, type AuthError, BranchLinker, CLI_TO_VSCODE_MAP, type Collaborator, type ConflictChoices, type ConflictResolution, DEFAULT_VALUES, type DateFieldValue, type FieldInfo, type FieldValue, type FieldValueConnection, GitHubAPI, type GitHubAPIOptions, type GitOptions, type IssueDetails, type IssueReference, type IterationFieldValue, type LabelInfo, type NumberFieldValue, type Project, type ProjectConfig, type ProjectItem, type ProjectItemContent, type ProjectItemsQueryResponse, type ProjectV2, type ProjectV2Field, type ProjectV2Item, type ProjectV2View, type ProjectWithViews, type ProjectsQueryResponse, type RepoInfo, type ResolvedSettings, SETTING_DISPLAY_NAMES, SYNCABLE_KEYS, type SettingConflict, type SettingsDiff, type SettingsSource, type SingleSelectFieldValue, type StatusField, type SyncableSettingKey, type SyncableSettings, type TextFieldValue, type TokenProvider, VSCODE_TO_CLI_MAP, type WorktreeInfo, branchExists, buildIssueUrl, buildOrgProjectUrl, buildProjectUrl, buildPullRequestUrl, buildRepoUrl, checkoutBranch, computeSettingsDiff, createBranch, createWorktree, detectRepository, extractIssueNumberFromBranch, fetchOrigin, formatConflict, generateBranchName, generateWorktreePath, getAllBranches, getCommitsAhead, getCommitsBehind, getCurrentBranch, getDefaultBranch, getDiffSummary, getLocalBranches, getRemoteBranches, getRepositoryRoot, getWorktreeForBranch, hasDifferences, hasUncommittedChanges, isGitRepository, listWorktrees, normalizeVSCodeSettings, parseBranchLink, parseGitHubUrl, parseIssueUrl, pullLatest, queries, removeBranchLinkFromBody, removeWorktree, resolveConflicts, sanitizeForBranchName, setBranchLinkInBody, skip, toVSCodeSettings, useCli, useCustom, useVSCode, worktreeExists };
package/dist/index.d.ts CHANGED
@@ -629,6 +629,16 @@ declare function generateBranchName(pattern: string, vars: {
629
629
  title: string;
630
630
  repo: string;
631
631
  }, maxLength?: number): string;
632
+ /**
633
+ * Extract issue number from a branch name.
634
+ * Supports common patterns:
635
+ * - user/123-feature-name
636
+ * - feature/123-something
637
+ * - 123-fix-bug
638
+ * - fix-123-something
639
+ * - ends with #123 or /123
640
+ */
641
+ declare function extractIssueNumberFromBranch(branchName: string): number | null;
632
642
  /**
633
643
  * Get all local branches
634
644
  */
@@ -692,13 +702,14 @@ declare function getWorktreeForBranch(branch: string, options?: GitOptions): Pro
692
702
  */
693
703
  declare function worktreeExists(worktreePath: string, options?: GitOptions): Promise<boolean>;
694
704
  /**
695
- * Generate a worktree path based on repo and branch info
705
+ * Generate a worktree path based on repo and issue info
696
706
  * @param basePath - Base directory for worktrees (e.g., ~/.ghp/worktrees)
697
707
  * @param repoName - Repository name
698
708
  * @param identifier - Issue number or branch name to use as identifier
709
+ * @param title - Optional title to create a descriptive directory name (e.g., "123-fix-auth-bug")
699
710
  * @returns Full path to the worktree directory
700
711
  */
701
- declare function generateWorktreePath(basePath: string, repoName: string, identifier: string | number): string;
712
+ declare function generateWorktreePath(basePath: string, repoName: string, identifier: string | number, title?: string): string;
702
713
 
703
714
  /**
704
715
  * URL parsing utilities for GitHub repositories and issues.
@@ -1042,4 +1053,4 @@ declare namespace queries {
1042
1053
  export { queries_ADD_COMMENT_MUTATION as ADD_COMMENT_MUTATION, queries_ADD_LABELS_MUTATION as ADD_LABELS_MUTATION, queries_ADD_TO_PROJECT_MUTATION as ADD_TO_PROJECT_MUTATION, queries_COLLABORATORS_QUERY as COLLABORATORS_QUERY, queries_CREATE_ISSUE_MUTATION as CREATE_ISSUE_MUTATION, queries_ISSUES_WITH_LABEL_QUERY as ISSUES_WITH_LABEL_QUERY, queries_ISSUE_AND_LABEL_QUERY as ISSUE_AND_LABEL_QUERY, queries_ISSUE_DETAILS_QUERY as ISSUE_DETAILS_QUERY, queries_ISSUE_FOR_UPDATE_QUERY as ISSUE_FOR_UPDATE_QUERY, queries_ISSUE_NODE_ID_QUERY as ISSUE_NODE_ID_QUERY, queries_ISSUE_TYPES_QUERY as ISSUE_TYPES_QUERY, queries_LABEL_EXISTS_QUERY as LABEL_EXISTS_QUERY, queries_PROJECT_FIELDS_QUERY as PROJECT_FIELDS_QUERY, queries_PROJECT_ITEMS_QUERY as PROJECT_ITEMS_QUERY, queries_PROJECT_VIEWS_QUERY as PROJECT_VIEWS_QUERY, queries_RECENT_ISSUES_QUERY as RECENT_ISSUES_QUERY, queries_REMOVE_LABELS_MUTATION as REMOVE_LABELS_MUTATION, queries_REPOSITORY_ID_QUERY as REPOSITORY_ID_QUERY, queries_REPOSITORY_PROJECTS_QUERY as REPOSITORY_PROJECTS_QUERY, queries_UPDATE_ISSUE_BODY_MUTATION as UPDATE_ISSUE_BODY_MUTATION, queries_UPDATE_ISSUE_MUTATION as UPDATE_ISSUE_MUTATION, queries_UPDATE_ISSUE_TYPE_MUTATION as UPDATE_ISSUE_TYPE_MUTATION, queries_UPDATE_ITEM_FIELD_MUTATION as UPDATE_ITEM_FIELD_MUTATION, queries_UPDATE_ITEM_STATUS_MUTATION as UPDATE_ITEM_STATUS_MUTATION, queries_VIEWER_QUERY as VIEWER_QUERY };
1043
1054
  }
1044
1055
 
1045
- export { type AssigneeInfo, type AuthError, BranchLinker, CLI_TO_VSCODE_MAP, type Collaborator, type ConflictChoices, type ConflictResolution, DEFAULT_VALUES, type DateFieldValue, type FieldInfo, type FieldValue, type FieldValueConnection, GitHubAPI, type GitHubAPIOptions, type GitOptions, type IssueDetails, type IssueReference, type IterationFieldValue, type LabelInfo, type NumberFieldValue, type Project, type ProjectConfig, type ProjectItem, type ProjectItemContent, type ProjectItemsQueryResponse, type ProjectV2, type ProjectV2Field, type ProjectV2Item, type ProjectV2View, type ProjectWithViews, type ProjectsQueryResponse, type RepoInfo, type ResolvedSettings, SETTING_DISPLAY_NAMES, SYNCABLE_KEYS, type SettingConflict, type SettingsDiff, type SettingsSource, type SingleSelectFieldValue, type StatusField, type SyncableSettingKey, type SyncableSettings, type TextFieldValue, type TokenProvider, VSCODE_TO_CLI_MAP, type WorktreeInfo, branchExists, buildIssueUrl, buildOrgProjectUrl, buildProjectUrl, buildPullRequestUrl, buildRepoUrl, checkoutBranch, computeSettingsDiff, createBranch, createWorktree, detectRepository, fetchOrigin, formatConflict, generateBranchName, generateWorktreePath, getAllBranches, getCommitsAhead, getCommitsBehind, getCurrentBranch, getDefaultBranch, getDiffSummary, getLocalBranches, getRemoteBranches, getRepositoryRoot, getWorktreeForBranch, hasDifferences, hasUncommittedChanges, isGitRepository, listWorktrees, normalizeVSCodeSettings, parseBranchLink, parseGitHubUrl, parseIssueUrl, pullLatest, queries, removeBranchLinkFromBody, removeWorktree, resolveConflicts, sanitizeForBranchName, setBranchLinkInBody, skip, toVSCodeSettings, useCli, useCustom, useVSCode, worktreeExists };
1056
+ export { type AssigneeInfo, type AuthError, BranchLinker, CLI_TO_VSCODE_MAP, type Collaborator, type ConflictChoices, type ConflictResolution, DEFAULT_VALUES, type DateFieldValue, type FieldInfo, type FieldValue, type FieldValueConnection, GitHubAPI, type GitHubAPIOptions, type GitOptions, type IssueDetails, type IssueReference, type IterationFieldValue, type LabelInfo, type NumberFieldValue, type Project, type ProjectConfig, type ProjectItem, type ProjectItemContent, type ProjectItemsQueryResponse, type ProjectV2, type ProjectV2Field, type ProjectV2Item, type ProjectV2View, type ProjectWithViews, type ProjectsQueryResponse, type RepoInfo, type ResolvedSettings, SETTING_DISPLAY_NAMES, SYNCABLE_KEYS, type SettingConflict, type SettingsDiff, type SettingsSource, type SingleSelectFieldValue, type StatusField, type SyncableSettingKey, type SyncableSettings, type TextFieldValue, type TokenProvider, VSCODE_TO_CLI_MAP, type WorktreeInfo, branchExists, buildIssueUrl, buildOrgProjectUrl, buildProjectUrl, buildPullRequestUrl, buildRepoUrl, checkoutBranch, computeSettingsDiff, createBranch, createWorktree, detectRepository, extractIssueNumberFromBranch, fetchOrigin, formatConflict, generateBranchName, generateWorktreePath, getAllBranches, getCommitsAhead, getCommitsBehind, getCurrentBranch, getDefaultBranch, getDiffSummary, getLocalBranches, getRemoteBranches, getRepositoryRoot, getWorktreeForBranch, hasDifferences, hasUncommittedChanges, isGitRepository, listWorktrees, normalizeVSCodeSettings, parseBranchLink, parseGitHubUrl, parseIssueUrl, pullLatest, queries, removeBranchLinkFromBody, removeWorktree, resolveConflicts, sanitizeForBranchName, setBranchLinkInBody, skip, toVSCodeSettings, useCli, useCustom, useVSCode, worktreeExists };
package/dist/index.js CHANGED
@@ -1268,6 +1268,25 @@ function generateBranchName(pattern, vars, maxLength = 60) {
1268
1268
  }
1269
1269
  return branch;
1270
1270
  }
1271
+ function extractIssueNumberFromBranch(branchName) {
1272
+ const patterns = [
1273
+ /\/(\d+)-/,
1274
+ // user/123-title
1275
+ /^(\d+)-/,
1276
+ // 123-title
1277
+ /-(\d+)-/,
1278
+ // feature-123-title
1279
+ /[/#](\d+)$/
1280
+ // ends with #123 or /123
1281
+ ];
1282
+ for (const pattern of patterns) {
1283
+ const match = branchName.match(pattern);
1284
+ if (match) {
1285
+ return parseInt(match[1], 10);
1286
+ }
1287
+ }
1288
+ return null;
1289
+ }
1271
1290
  async function getLocalBranches(options = {}) {
1272
1291
  try {
1273
1292
  const { stdout } = await execGit('git branch --format="%(refname:short)"', options);
@@ -1385,12 +1404,18 @@ async function worktreeExists(worktreePath, options = {}) {
1385
1404
  const worktrees = await listWorktrees(options);
1386
1405
  return worktrees.some((wt) => wt.path === worktreePath);
1387
1406
  }
1388
- function generateWorktreePath(basePath, repoName, identifier) {
1407
+ function generateWorktreePath(basePath, repoName, identifier, title) {
1389
1408
  const safeRepoName = sanitizeForPath(repoName);
1390
- const safeIdentifier = sanitizeForPath(String(identifier));
1409
+ let dirName;
1410
+ if (title && typeof identifier === "number") {
1411
+ const titleSlug = sanitizeForBranchName(title).substring(0, 35).replace(/-$/, "");
1412
+ dirName = `${identifier}-${titleSlug}`;
1413
+ } else {
1414
+ dirName = sanitizeForPath(String(identifier));
1415
+ }
1391
1416
  const expandedBase = basePath.startsWith("~") ? basePath.replace("~", homedir()) : basePath;
1392
1417
  const cleanBase = expandedBase.replace(/\/+$/, "");
1393
- return `${cleanBase}/${safeRepoName}/${safeIdentifier}`;
1418
+ return `${cleanBase}/${safeRepoName}/${dirName}`;
1394
1419
  }
1395
1420
 
1396
1421
  // src/sync.ts
@@ -1573,6 +1598,7 @@ export {
1573
1598
  createBranch,
1574
1599
  createWorktree,
1575
1600
  detectRepository,
1601
+ extractIssueNumberFromBranch,
1576
1602
  fetchOrigin,
1577
1603
  formatConflict,
1578
1604
  generateBranchName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bretwardjames/ghp-core",
3
- "version": "0.2.0-beta.1",
3
+ "version": "0.2.0-beta.3",
4
4
  "description": "Shared core library for GitHub Projects tools",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",