|
3 | 3 | import { addDraftIssueToProjectMutation } from "./lib/queries.js"; |
4 | 4 | import { projectItemNodeToGitHubProjectItem } from "./lib/project-item-node-to-github-project-item.js"; |
5 | 5 | import { getStateWithProjectFields } from "./lib/get-state-with-project-fields.js"; |
6 | | -import { getFieldsUpdateQueryAndFields } from "./lib/get-fields-update-query-and-fields.js"; |
7 | 6 | import { removeObjectKeys } from "./lib/remove-object-keys.js"; |
| 7 | +import { updateItemFields } from "./lib/update-project-item-fields.js"; |
8 | 8 |
|
9 | 9 | /** |
10 | 10 | * Creates draft item in project. |
@@ -38,30 +38,24 @@ export async function addDraftItem(project, state, content, fields) { |
38 | 38 | const nonExistingProjectFields = Object.entries(stateWithFields.fields) |
39 | 39 | .filter(([, field]) => field.existsInProject === false) |
40 | 40 | .map(([key]) => key); |
41 | | - const existingProjectFieldKeys = Object.keys(fields).filter( |
42 | | - (key) => !nonExistingProjectFields.includes(key) |
| 41 | + |
| 42 | + const fieldsAfterUpdate = await updateItemFields( |
| 43 | + project, |
| 44 | + state, |
| 45 | + draftItem.id, |
| 46 | + fields |
43 | 47 | ); |
44 | 48 |
|
45 | | - if (existingProjectFieldKeys.length === 0) |
| 49 | + if (!fieldsAfterUpdate) { |
46 | 50 | return { |
47 | 51 | ...draftItem, |
48 | 52 | // @ts-expect-error - complaints that built-in fields `title` and `status` might not exist, but we are good here |
49 | 53 | fields: removeObjectKeys(draftItem.fields, nonExistingProjectFields), |
50 | 54 | }; |
51 | | - |
52 | | - const existingFields = Object.fromEntries( |
53 | | - existingProjectFieldKeys.map((key) => [key, fields[key]]) |
54 | | - ); |
55 | | - |
56 | | - const result = getFieldsUpdateQueryAndFields(stateWithFields, existingFields); |
57 | | - |
58 | | - await project.octokit.graphql(result.query, { |
59 | | - projectId: stateWithFields.id, |
60 | | - itemId: draftItem.id, |
61 | | - }); |
| 55 | + } |
62 | 56 |
|
63 | 57 | return { |
64 | 58 | ...draftItem, |
65 | | - fields: result.fields, |
| 59 | + fields: fieldsAfterUpdate, |
66 | 60 | }; |
67 | 61 | } |
0 commit comments