@bretwardjames/ghp-core 0.1.5 → 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
@@ -1007,6 +1007,63 @@ var GitHubAPI = class {
1007
1007
  return false;
1008
1008
  }
1009
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
+ }
1010
1067
  };
1011
1068
 
1012
1069
  // src/branch-linker.ts
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
  /**
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
  /**
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bretwardjames/ghp-core",
3
- "version": "0.1.5",
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",