@bretwardjames/ghp-core 0.1.4 → 0.1.6

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
@@ -33,10 +33,13 @@ __export(index_exports, {
33
33
  detectRepository: () => detectRepository,
34
34
  fetchOrigin: () => fetchOrigin,
35
35
  generateBranchName: () => generateBranchName,
36
+ getAllBranches: () => getAllBranches,
36
37
  getCommitsAhead: () => getCommitsAhead,
37
38
  getCommitsBehind: () => getCommitsBehind,
38
39
  getCurrentBranch: () => getCurrentBranch,
39
40
  getDefaultBranch: () => getDefaultBranch,
41
+ getLocalBranches: () => getLocalBranches,
42
+ getRemoteBranches: () => getRemoteBranches,
40
43
  getRepositoryRoot: () => getRepositoryRoot,
41
44
  hasUncommittedChanges: () => hasUncommittedChanges,
42
45
  isGitRepository: () => isGitRepository,
@@ -1004,6 +1007,63 @@ var GitHubAPI = class {
1004
1007
  return false;
1005
1008
  }
1006
1009
  }
1010
+ /**
1011
+ * Update assignees on an issue
1012
+ */
1013
+ async updateAssignees(repo, issueNumber, assigneeLogins) {
1014
+ if (!this.graphqlWithAuth) throw new Error("Not authenticated");
1015
+ try {
1016
+ const issueResponse = await this.graphqlWithAuth(
1017
+ `query($owner: String!, $name: String!, $number: Int!) {
1018
+ repository(owner: $owner, name: $name) {
1019
+ issue(number: $number) {
1020
+ id
1021
+ assignees(first: 20) { nodes { id login } }
1022
+ }
1023
+ }
1024
+ }`,
1025
+ { owner: repo.owner, name: repo.name, number: issueNumber }
1026
+ );
1027
+ if (!issueResponse.repository.issue) {
1028
+ return false;
1029
+ }
1030
+ const issueId = issueResponse.repository.issue.id;
1031
+ const assigneeIds = [];
1032
+ for (const login of assigneeLogins) {
1033
+ const userResponse = await this.graphqlWithAuth(
1034
+ `query($login: String!) { user(login: $login) { id } }`,
1035
+ { login }
1036
+ );
1037
+ if (userResponse.user) {
1038
+ assigneeIds.push(userResponse.user.id);
1039
+ }
1040
+ }
1041
+ const currentAssigneeIds = issueResponse.repository.issue.assignees.nodes.map((a) => a.id);
1042
+ if (currentAssigneeIds.length > 0) {
1043
+ await this.graphqlWithAuth(
1044
+ `mutation($assignableId: ID!, $assigneeIds: [ID!]!) {
1045
+ removeAssigneesFromAssignable(input: { assignableId: $assignableId, assigneeIds: $assigneeIds }) {
1046
+ clientMutationId
1047
+ }
1048
+ }`,
1049
+ { assignableId: issueId, assigneeIds: currentAssigneeIds }
1050
+ );
1051
+ }
1052
+ if (assigneeIds.length > 0) {
1053
+ await this.graphqlWithAuth(
1054
+ `mutation($assignableId: ID!, $assigneeIds: [ID!]!) {
1055
+ addAssigneesToAssignable(input: { assignableId: $assignableId, assigneeIds: $assigneeIds }) {
1056
+ clientMutationId
1057
+ }
1058
+ }`,
1059
+ { assignableId: issueId, assigneeIds }
1060
+ );
1061
+ }
1062
+ return true;
1063
+ } catch {
1064
+ return false;
1065
+ }
1066
+ }
1007
1067
  };
1008
1068
 
1009
1069
  // src/branch-linker.ts
@@ -1225,6 +1285,34 @@ function generateBranchName(pattern, vars, maxLength = 60) {
1225
1285
  }
1226
1286
  return branch;
1227
1287
  }
1288
+ async function getLocalBranches(options = {}) {
1289
+ try {
1290
+ const { stdout } = await execGit('git branch --format="%(refname:short)"', options);
1291
+ return stdout.split("\n").map((b) => b.trim()).filter((b) => b.length > 0);
1292
+ } catch {
1293
+ return [];
1294
+ }
1295
+ }
1296
+ async function getRemoteBranches(options = {}) {
1297
+ try {
1298
+ await execGit("git fetch --prune", options);
1299
+ const { stdout } = await execGit('git branch -r --format="%(refname:short)"', options);
1300
+ return stdout.split("\n").map((b) => b.trim()).filter((b) => b.length > 0 && !b.includes("HEAD")).map((b) => b.replace(/^origin\//, ""));
1301
+ } catch {
1302
+ return [];
1303
+ }
1304
+ }
1305
+ async function getAllBranches(options = {}) {
1306
+ const [local, remote] = await Promise.all([
1307
+ getLocalBranches(options),
1308
+ getRemoteBranches(options)
1309
+ ]);
1310
+ const all = new Set(local);
1311
+ for (const b of remote) {
1312
+ all.add(b);
1313
+ }
1314
+ return Array.from(all);
1315
+ }
1228
1316
  async function getDefaultBranch(options = {}) {
1229
1317
  try {
1230
1318
  const { stdout } = await execGit(
@@ -1258,10 +1346,13 @@ async function getDefaultBranch(options = {}) {
1258
1346
  detectRepository,
1259
1347
  fetchOrigin,
1260
1348
  generateBranchName,
1349
+ getAllBranches,
1261
1350
  getCommitsAhead,
1262
1351
  getCommitsBehind,
1263
1352
  getCurrentBranch,
1264
1353
  getDefaultBranch,
1354
+ getLocalBranches,
1355
+ getRemoteBranches,
1265
1356
  getRepositoryRoot,
1266
1357
  hasUncommittedChanges,
1267
1358
  isGitRepository,
package/dist/index.d.cts CHANGED
@@ -505,6 +505,10 @@ declare class GitHubAPI {
505
505
  title?: string;
506
506
  body?: string;
507
507
  }): Promise<boolean>;
508
+ /**
509
+ * Update assignees on an issue
510
+ */
511
+ updateAssignees(repo: RepoInfo, issueNumber: number, assigneeLogins: string[]): Promise<boolean>;
508
512
  }
509
513
 
510
514
  /**
@@ -625,6 +629,18 @@ declare function generateBranchName(pattern: string, vars: {
625
629
  title: string;
626
630
  repo: string;
627
631
  }, maxLength?: number): string;
632
+ /**
633
+ * Get all local branches
634
+ */
635
+ declare function getLocalBranches(options?: GitOptions): Promise<string[]>;
636
+ /**
637
+ * Get all remote branches (excluding HEAD), stripped of origin/ prefix
638
+ */
639
+ declare function getRemoteBranches(options?: GitOptions): Promise<string[]>;
640
+ /**
641
+ * Get all branches (local + remote unique)
642
+ */
643
+ declare function getAllBranches(options?: GitOptions): Promise<string[]>;
628
644
  /**
629
645
  * Get the default branch name (main or master)
630
646
  */
@@ -817,4 +833,4 @@ declare namespace queries {
817
833
  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 };
818
834
  }
819
835
 
820
- export { type AssigneeInfo, type AuthError, BranchLinker, type Collaborator, 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 SingleSelectFieldValue, type StatusField, type TextFieldValue, type TokenProvider, branchExists, buildIssueUrl, buildOrgProjectUrl, buildProjectUrl, buildPullRequestUrl, buildRepoUrl, checkoutBranch, createBranch, detectRepository, fetchOrigin, generateBranchName, getCommitsAhead, getCommitsBehind, getCurrentBranch, getDefaultBranch, getRepositoryRoot, hasUncommittedChanges, isGitRepository, parseBranchLink, parseGitHubUrl, parseIssueUrl, pullLatest, queries, removeBranchLinkFromBody, sanitizeForBranchName, setBranchLinkInBody };
836
+ export { type AssigneeInfo, type AuthError, BranchLinker, type Collaborator, 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 SingleSelectFieldValue, type StatusField, type TextFieldValue, type TokenProvider, branchExists, buildIssueUrl, buildOrgProjectUrl, buildProjectUrl, buildPullRequestUrl, buildRepoUrl, checkoutBranch, createBranch, detectRepository, fetchOrigin, generateBranchName, getAllBranches, getCommitsAhead, getCommitsBehind, getCurrentBranch, getDefaultBranch, getLocalBranches, getRemoteBranches, getRepositoryRoot, hasUncommittedChanges, isGitRepository, parseBranchLink, parseGitHubUrl, parseIssueUrl, pullLatest, queries, removeBranchLinkFromBody, sanitizeForBranchName, setBranchLinkInBody };
package/dist/index.d.ts CHANGED
@@ -505,6 +505,10 @@ declare class GitHubAPI {
505
505
  title?: string;
506
506
  body?: string;
507
507
  }): Promise<boolean>;
508
+ /**
509
+ * Update assignees on an issue
510
+ */
511
+ updateAssignees(repo: RepoInfo, issueNumber: number, assigneeLogins: string[]): Promise<boolean>;
508
512
  }
509
513
 
510
514
  /**
@@ -625,6 +629,18 @@ declare function generateBranchName(pattern: string, vars: {
625
629
  title: string;
626
630
  repo: string;
627
631
  }, maxLength?: number): string;
632
+ /**
633
+ * Get all local branches
634
+ */
635
+ declare function getLocalBranches(options?: GitOptions): Promise<string[]>;
636
+ /**
637
+ * Get all remote branches (excluding HEAD), stripped of origin/ prefix
638
+ */
639
+ declare function getRemoteBranches(options?: GitOptions): Promise<string[]>;
640
+ /**
641
+ * Get all branches (local + remote unique)
642
+ */
643
+ declare function getAllBranches(options?: GitOptions): Promise<string[]>;
628
644
  /**
629
645
  * Get the default branch name (main or master)
630
646
  */
@@ -817,4 +833,4 @@ declare namespace queries {
817
833
  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 };
818
834
  }
819
835
 
820
- export { type AssigneeInfo, type AuthError, BranchLinker, type Collaborator, 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 SingleSelectFieldValue, type StatusField, type TextFieldValue, type TokenProvider, branchExists, buildIssueUrl, buildOrgProjectUrl, buildProjectUrl, buildPullRequestUrl, buildRepoUrl, checkoutBranch, createBranch, detectRepository, fetchOrigin, generateBranchName, getCommitsAhead, getCommitsBehind, getCurrentBranch, getDefaultBranch, getRepositoryRoot, hasUncommittedChanges, isGitRepository, parseBranchLink, parseGitHubUrl, parseIssueUrl, pullLatest, queries, removeBranchLinkFromBody, sanitizeForBranchName, setBranchLinkInBody };
836
+ export { type AssigneeInfo, type AuthError, BranchLinker, type Collaborator, 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 SingleSelectFieldValue, type StatusField, type TextFieldValue, type TokenProvider, branchExists, buildIssueUrl, buildOrgProjectUrl, buildProjectUrl, buildPullRequestUrl, buildRepoUrl, checkoutBranch, createBranch, detectRepository, fetchOrigin, generateBranchName, getAllBranches, getCommitsAhead, getCommitsBehind, getCurrentBranch, getDefaultBranch, getLocalBranches, getRemoteBranches, getRepositoryRoot, hasUncommittedChanges, isGitRepository, parseBranchLink, parseGitHubUrl, parseIssueUrl, pullLatest, queries, removeBranchLinkFromBody, sanitizeForBranchName, setBranchLinkInBody };
package/dist/index.js CHANGED
@@ -957,6 +957,63 @@ var GitHubAPI = class {
957
957
  return false;
958
958
  }
959
959
  }
960
+ /**
961
+ * Update assignees on an issue
962
+ */
963
+ async updateAssignees(repo, issueNumber, assigneeLogins) {
964
+ if (!this.graphqlWithAuth) throw new Error("Not authenticated");
965
+ try {
966
+ const issueResponse = await this.graphqlWithAuth(
967
+ `query($owner: String!, $name: String!, $number: Int!) {
968
+ repository(owner: $owner, name: $name) {
969
+ issue(number: $number) {
970
+ id
971
+ assignees(first: 20) { nodes { id login } }
972
+ }
973
+ }
974
+ }`,
975
+ { owner: repo.owner, name: repo.name, number: issueNumber }
976
+ );
977
+ if (!issueResponse.repository.issue) {
978
+ return false;
979
+ }
980
+ const issueId = issueResponse.repository.issue.id;
981
+ const assigneeIds = [];
982
+ for (const login of assigneeLogins) {
983
+ const userResponse = await this.graphqlWithAuth(
984
+ `query($login: String!) { user(login: $login) { id } }`,
985
+ { login }
986
+ );
987
+ if (userResponse.user) {
988
+ assigneeIds.push(userResponse.user.id);
989
+ }
990
+ }
991
+ const currentAssigneeIds = issueResponse.repository.issue.assignees.nodes.map((a) => a.id);
992
+ if (currentAssigneeIds.length > 0) {
993
+ await this.graphqlWithAuth(
994
+ `mutation($assignableId: ID!, $assigneeIds: [ID!]!) {
995
+ removeAssigneesFromAssignable(input: { assignableId: $assignableId, assigneeIds: $assigneeIds }) {
996
+ clientMutationId
997
+ }
998
+ }`,
999
+ { assignableId: issueId, assigneeIds: currentAssigneeIds }
1000
+ );
1001
+ }
1002
+ if (assigneeIds.length > 0) {
1003
+ await this.graphqlWithAuth(
1004
+ `mutation($assignableId: ID!, $assigneeIds: [ID!]!) {
1005
+ addAssigneesToAssignable(input: { assignableId: $assignableId, assigneeIds: $assigneeIds }) {
1006
+ clientMutationId
1007
+ }
1008
+ }`,
1009
+ { assignableId: issueId, assigneeIds }
1010
+ );
1011
+ }
1012
+ return true;
1013
+ } catch {
1014
+ return false;
1015
+ }
1016
+ }
960
1017
  };
961
1018
 
962
1019
  // src/branch-linker.ts
@@ -1178,6 +1235,34 @@ function generateBranchName(pattern, vars, maxLength = 60) {
1178
1235
  }
1179
1236
  return branch;
1180
1237
  }
1238
+ async function getLocalBranches(options = {}) {
1239
+ try {
1240
+ const { stdout } = await execGit('git branch --format="%(refname:short)"', options);
1241
+ return stdout.split("\n").map((b) => b.trim()).filter((b) => b.length > 0);
1242
+ } catch {
1243
+ return [];
1244
+ }
1245
+ }
1246
+ async function getRemoteBranches(options = {}) {
1247
+ try {
1248
+ await execGit("git fetch --prune", options);
1249
+ const { stdout } = await execGit('git branch -r --format="%(refname:short)"', options);
1250
+ return stdout.split("\n").map((b) => b.trim()).filter((b) => b.length > 0 && !b.includes("HEAD")).map((b) => b.replace(/^origin\//, ""));
1251
+ } catch {
1252
+ return [];
1253
+ }
1254
+ }
1255
+ async function getAllBranches(options = {}) {
1256
+ const [local, remote] = await Promise.all([
1257
+ getLocalBranches(options),
1258
+ getRemoteBranches(options)
1259
+ ]);
1260
+ const all = new Set(local);
1261
+ for (const b of remote) {
1262
+ all.add(b);
1263
+ }
1264
+ return Array.from(all);
1265
+ }
1181
1266
  async function getDefaultBranch(options = {}) {
1182
1267
  try {
1183
1268
  const { stdout } = await execGit(
@@ -1210,10 +1295,13 @@ export {
1210
1295
  detectRepository,
1211
1296
  fetchOrigin,
1212
1297
  generateBranchName,
1298
+ getAllBranches,
1213
1299
  getCommitsAhead,
1214
1300
  getCommitsBehind,
1215
1301
  getCurrentBranch,
1216
1302
  getDefaultBranch,
1303
+ getLocalBranches,
1304
+ getRemoteBranches,
1217
1305
  getRepositoryRoot,
1218
1306
  hasUncommittedChanges,
1219
1307
  isGitRepository,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bretwardjames/ghp-core",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Shared core library for GitHub Projects tools",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",