@bretwardjames/ghp-core 0.9.0 → 0.10.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/dist/index.cjs CHANGED
@@ -337,6 +337,10 @@ var PROJECT_FIELDS_QUERY = `
337
337
  ... on ProjectV2IterationField {
338
338
  id
339
339
  name
340
+ configuration {
341
+ iterations { id title }
342
+ completedIterations { id title }
343
+ }
340
344
  }
341
345
  }
342
346
  }
@@ -1350,28 +1354,48 @@ var GitHubAPI = class {
1350
1354
  async getProjectFields(projectId) {
1351
1355
  if (!this.graphqlWithAuth) throw new Error("Not authenticated");
1352
1356
  const response = await this.graphqlWithRetry(PROJECT_FIELDS_QUERY, { projectId });
1353
- return response.node.fields.nodes.map((f) => ({
1354
- id: f.id,
1355
- name: f.name,
1356
- type: f.__typename.replace("ProjectV2", "").replace("Field", ""),
1357
- options: f.options
1358
- }));
1357
+ return response.node.fields.nodes.map((f) => {
1358
+ let options = f.options;
1359
+ if (f.configuration) {
1360
+ const all = [...f.configuration.iterations, ...f.configuration.completedIterations];
1361
+ options = all.map((i) => ({ id: i.id, name: i.title }));
1362
+ }
1363
+ return {
1364
+ id: f.id,
1365
+ name: f.name,
1366
+ type: f.__typename.replace("ProjectV2", "").replace("Field", ""),
1367
+ options
1368
+ };
1369
+ });
1359
1370
  }
1360
1371
  /**
1361
- * Set a field value on a project item
1372
+ * Set a field value on a project item.
1373
+ * Routes SingleSelect fields through the inline mutation pattern
1374
+ * (passing the option ID as a scalar variable) since GitHub's API
1375
+ * does not reliably deserialize ProjectV2FieldValue input objects.
1362
1376
  */
1363
1377
  async setFieldValue(projectId, itemId, fieldId, value) {
1364
1378
  if (!this.graphqlWithAuth) throw new Error("Not authenticated");
1365
1379
  try {
1366
- await this.graphqlWithRetry(UPDATE_ITEM_FIELD_MUTATION, {
1367
- projectId,
1368
- itemId,
1369
- fieldId,
1370
- value
1371
- });
1372
- return true;
1373
- } catch {
1374
- return false;
1380
+ if (value.singleSelectOptionId) {
1381
+ await this.graphqlWithRetry(UPDATE_ITEM_STATUS_MUTATION, {
1382
+ projectId,
1383
+ itemId,
1384
+ fieldId,
1385
+ optionId: value.singleSelectOptionId
1386
+ });
1387
+ } else {
1388
+ await this.graphqlWithRetry(UPDATE_ITEM_FIELD_MUTATION, {
1389
+ projectId,
1390
+ itemId,
1391
+ fieldId,
1392
+ value
1393
+ });
1394
+ }
1395
+ return { success: true };
1396
+ } catch (error) {
1397
+ const message = error instanceof Error ? error.message : String(error);
1398
+ return { success: false, error: message };
1375
1399
  }
1376
1400
  }
1377
1401
  /**
package/dist/index.d.cts CHANGED
@@ -557,13 +557,21 @@ declare class GitHubAPI {
557
557
  }>;
558
558
  }>>;
559
559
  /**
560
- * Set a field value on a project item
560
+ * Set a field value on a project item.
561
+ * Routes SingleSelect fields through the inline mutation pattern
562
+ * (passing the option ID as a scalar variable) since GitHub's API
563
+ * does not reliably deserialize ProjectV2FieldValue input objects.
561
564
  */
562
565
  setFieldValue(projectId: string, itemId: string, fieldId: string, value: {
563
566
  text?: string;
564
567
  number?: number;
565
568
  singleSelectOptionId?: string;
566
- }): Promise<boolean>;
569
+ date?: string;
570
+ iterationId?: string;
571
+ }): Promise<{
572
+ success: boolean;
573
+ error?: string;
574
+ }>;
567
575
  /**
568
576
  * Create a new issue
569
577
  */
@@ -1179,7 +1187,7 @@ declare const PROJECT_ITEMS_QUERY = "\n query($projectId: ID!, $cursor: Strin
1179
1187
  /**
1180
1188
  * Query to get project fields (including status options)
1181
1189
  */
1182
- declare const PROJECT_FIELDS_QUERY = "\n query($projectId: ID!) {\n node(id: $projectId) {\n ... on ProjectV2 {\n fields(first: 30) {\n nodes {\n __typename\n ... on ProjectV2Field {\n id\n name\n }\n ... on ProjectV2SingleSelectField {\n id\n name\n options { id name }\n }\n ... on ProjectV2IterationField {\n id\n name\n }\n }\n }\n }\n }\n }\n";
1190
+ declare const PROJECT_FIELDS_QUERY = "\n query($projectId: ID!) {\n node(id: $projectId) {\n ... on ProjectV2 {\n fields(first: 30) {\n nodes {\n __typename\n ... on ProjectV2Field {\n id\n name\n }\n ... on ProjectV2SingleSelectField {\n id\n name\n options { id name }\n }\n ... on ProjectV2IterationField {\n id\n name\n configuration {\n iterations { id title }\n completedIterations { id title }\n }\n }\n }\n }\n }\n }\n }\n";
1183
1191
  /**
1184
1192
  * Query to get project views
1185
1193
  */
package/dist/index.d.ts CHANGED
@@ -557,13 +557,21 @@ declare class GitHubAPI {
557
557
  }>;
558
558
  }>>;
559
559
  /**
560
- * Set a field value on a project item
560
+ * Set a field value on a project item.
561
+ * Routes SingleSelect fields through the inline mutation pattern
562
+ * (passing the option ID as a scalar variable) since GitHub's API
563
+ * does not reliably deserialize ProjectV2FieldValue input objects.
561
564
  */
562
565
  setFieldValue(projectId: string, itemId: string, fieldId: string, value: {
563
566
  text?: string;
564
567
  number?: number;
565
568
  singleSelectOptionId?: string;
566
- }): Promise<boolean>;
569
+ date?: string;
570
+ iterationId?: string;
571
+ }): Promise<{
572
+ success: boolean;
573
+ error?: string;
574
+ }>;
567
575
  /**
568
576
  * Create a new issue
569
577
  */
@@ -1179,7 +1187,7 @@ declare const PROJECT_ITEMS_QUERY = "\n query($projectId: ID!, $cursor: Strin
1179
1187
  /**
1180
1188
  * Query to get project fields (including status options)
1181
1189
  */
1182
- declare const PROJECT_FIELDS_QUERY = "\n query($projectId: ID!) {\n node(id: $projectId) {\n ... on ProjectV2 {\n fields(first: 30) {\n nodes {\n __typename\n ... on ProjectV2Field {\n id\n name\n }\n ... on ProjectV2SingleSelectField {\n id\n name\n options { id name }\n }\n ... on ProjectV2IterationField {\n id\n name\n }\n }\n }\n }\n }\n }\n";
1190
+ declare const PROJECT_FIELDS_QUERY = "\n query($projectId: ID!) {\n node(id: $projectId) {\n ... on ProjectV2 {\n fields(first: 30) {\n nodes {\n __typename\n ... on ProjectV2Field {\n id\n name\n }\n ... on ProjectV2SingleSelectField {\n id\n name\n options { id name }\n }\n ... on ProjectV2IterationField {\n id\n name\n configuration {\n iterations { id title }\n completedIterations { id title }\n }\n }\n }\n }\n }\n }\n }\n";
1183
1191
  /**
1184
1192
  * Query to get project views
1185
1193
  */
package/dist/index.js CHANGED
@@ -166,6 +166,10 @@ var PROJECT_FIELDS_QUERY = `
166
166
  ... on ProjectV2IterationField {
167
167
  id
168
168
  name
169
+ configuration {
170
+ iterations { id title }
171
+ completedIterations { id title }
172
+ }
169
173
  }
170
174
  }
171
175
  }
@@ -1179,28 +1183,48 @@ var GitHubAPI = class {
1179
1183
  async getProjectFields(projectId) {
1180
1184
  if (!this.graphqlWithAuth) throw new Error("Not authenticated");
1181
1185
  const response = await this.graphqlWithRetry(PROJECT_FIELDS_QUERY, { projectId });
1182
- return response.node.fields.nodes.map((f) => ({
1183
- id: f.id,
1184
- name: f.name,
1185
- type: f.__typename.replace("ProjectV2", "").replace("Field", ""),
1186
- options: f.options
1187
- }));
1186
+ return response.node.fields.nodes.map((f) => {
1187
+ let options = f.options;
1188
+ if (f.configuration) {
1189
+ const all = [...f.configuration.iterations, ...f.configuration.completedIterations];
1190
+ options = all.map((i) => ({ id: i.id, name: i.title }));
1191
+ }
1192
+ return {
1193
+ id: f.id,
1194
+ name: f.name,
1195
+ type: f.__typename.replace("ProjectV2", "").replace("Field", ""),
1196
+ options
1197
+ };
1198
+ });
1188
1199
  }
1189
1200
  /**
1190
- * Set a field value on a project item
1201
+ * Set a field value on a project item.
1202
+ * Routes SingleSelect fields through the inline mutation pattern
1203
+ * (passing the option ID as a scalar variable) since GitHub's API
1204
+ * does not reliably deserialize ProjectV2FieldValue input objects.
1191
1205
  */
1192
1206
  async setFieldValue(projectId, itemId, fieldId, value) {
1193
1207
  if (!this.graphqlWithAuth) throw new Error("Not authenticated");
1194
1208
  try {
1195
- await this.graphqlWithRetry(UPDATE_ITEM_FIELD_MUTATION, {
1196
- projectId,
1197
- itemId,
1198
- fieldId,
1199
- value
1200
- });
1201
- return true;
1202
- } catch {
1203
- return false;
1209
+ if (value.singleSelectOptionId) {
1210
+ await this.graphqlWithRetry(UPDATE_ITEM_STATUS_MUTATION, {
1211
+ projectId,
1212
+ itemId,
1213
+ fieldId,
1214
+ optionId: value.singleSelectOptionId
1215
+ });
1216
+ } else {
1217
+ await this.graphqlWithRetry(UPDATE_ITEM_FIELD_MUTATION, {
1218
+ projectId,
1219
+ itemId,
1220
+ fieldId,
1221
+ value
1222
+ });
1223
+ }
1224
+ return { success: true };
1225
+ } catch (error) {
1226
+ const message = error instanceof Error ? error.message : String(error);
1227
+ return { success: false, error: message };
1204
1228
  }
1205
1229
  }
1206
1230
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bretwardjames/ghp-core",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Shared core library for GitHub Projects tools",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",