|
|
@@ -21,6 +21,8 @@ const projectGraphqlData = ({
|
|
|
startDate = null,
|
|
|
startDateField = true,
|
|
|
startDateType = 'DATE',
|
|
|
+ startDateIsIssueField = true,
|
|
|
+ startDateIssueField = true,
|
|
|
} = {}) => ({
|
|
|
organization: {
|
|
|
projectV2: {
|
|
|
@@ -30,7 +32,15 @@ const projectGraphqlData = ({
|
|
|
nodes: [
|
|
|
{ id: 'status-field-id', name: 'Status', dataType: 'SINGLE_SELECT', options: [] },
|
|
|
...(startDateField
|
|
|
- ? [{ id: 'start-date-field-id', name: 'Start date', dataType: startDateType }]
|
|
|
+ ? [
|
|
|
+ {
|
|
|
+ id: 'start-date-project-field-id',
|
|
|
+ name: 'Start date',
|
|
|
+ dataType: startDateType,
|
|
|
+ isIssueField: startDateIsIssueField,
|
|
|
+ issueField: startDateIssueField ? { id: 'start-date-issue-field-id' } : null,
|
|
|
+ },
|
|
|
+ ]
|
|
|
: []),
|
|
|
],
|
|
|
},
|
|
|
@@ -46,7 +56,8 @@ const projectGraphqlData = ({
|
|
|
id: 'item-id',
|
|
|
project: { id: 'project-id' },
|
|
|
fieldValueByName: { name: 'Inbox', optionId: 'inbox-option-id' },
|
|
|
- startDateValue: startDate === null ? null : { date: startDate },
|
|
|
+ startDateValue:
|
|
|
+ startDate === null ? null : { issueFieldValue: { value: startDate } },
|
|
|
},
|
|
|
]
|
|
|
: [],
|
|
|
@@ -258,25 +269,27 @@ test('initializes every referenced Issue only for a PR opened event', async () =
|
|
|
assert.equal(writes.length, 3)
|
|
|
})
|
|
|
|
|
|
-test('writes an empty Project Start date with the configured field', async (t) => {
|
|
|
+test('writes an empty Issue Start date with the configured field', async (t) => {
|
|
|
const requests = mockGraphql(t, (request) => {
|
|
|
if (request.query.includes('query(')) return projectGraphqlData()
|
|
|
- return { updateProjectV2ItemFieldValue: { projectV2Item: { id: 'item-id' } } }
|
|
|
+ return { updateIssueFieldValue: { issue: { id: 'issue-id' } } }
|
|
|
})
|
|
|
|
|
|
await initializeIssueStartDate(42, '2026-08-28')
|
|
|
|
|
|
assert.equal(requests.length, 2)
|
|
|
- assert.match(requests[1].query, /value: \{date: \$date\}/)
|
|
|
+ assert.match(requests[0].query, /isIssueField/)
|
|
|
+ assert.match(requests[0].query, /ProjectV2ItemIssueFieldValue/)
|
|
|
+ assert.match(requests[1].query, /updateIssueFieldValue/)
|
|
|
+ assert.match(requests[1].query, /issueField: \{fieldId: \$fieldId, dateValue: \$date\}/)
|
|
|
assert.deepEqual(requests[1].variables, {
|
|
|
- projectId: 'project-id',
|
|
|
- itemId: 'item-id',
|
|
|
- fieldId: 'start-date-field-id',
|
|
|
+ issueId: 'issue-id',
|
|
|
+ fieldId: 'start-date-issue-field-id',
|
|
|
date: '2026-08-28',
|
|
|
})
|
|
|
})
|
|
|
|
|
|
-test('preserves an existing Project Start date', async (t) => {
|
|
|
+test('preserves an existing Issue Start date', async (t) => {
|
|
|
const requests = mockGraphql(t, () => projectGraphqlData({ startDate: '2026-08-01' }))
|
|
|
|
|
|
await initializeIssueStartDate(42, '2026-08-28')
|
|
|
@@ -290,24 +303,38 @@ test('adds a referenced Issue to the Project before setting Start date', async (
|
|
|
if (request.query.includes('addProjectV2ItemById')) {
|
|
|
return { addProjectV2ItemById: { item: { id: 'new-item-id' } } }
|
|
|
}
|
|
|
- return { updateProjectV2ItemFieldValue: { projectV2Item: { id: 'new-item-id' } } }
|
|
|
+ return { updateIssueFieldValue: { issue: { id: 'issue-id' } } }
|
|
|
})
|
|
|
|
|
|
await initializeIssueStartDate(42, '2026-08-28')
|
|
|
|
|
|
assert.equal(requests.length, 3)
|
|
|
assert.deepEqual(requests[1].variables, { projectId: 'project-id', contentId: 'issue-id' })
|
|
|
- assert.equal(requests[2].variables.itemId, 'new-item-id')
|
|
|
+ assert.deepEqual(requests[2].variables, {
|
|
|
+ issueId: 'issue-id',
|
|
|
+ fieldId: 'start-date-issue-field-id',
|
|
|
+ date: '2026-08-28',
|
|
|
+ })
|
|
|
})
|
|
|
|
|
|
-test('rejects a missing or non-Date Start date field', async (t) => {
|
|
|
+test('rejects a missing, non-Date, or Project-local Start date field', async (t) => {
|
|
|
let response = projectGraphqlData({ startDateField: false })
|
|
|
const requests = mockGraphql(t, () => response)
|
|
|
|
|
|
await assert.rejects(initializeIssueStartDate(42, '2026-08-28'), /Project 缺少 Start date 字段/)
|
|
|
response = projectGraphqlData({ startDateType: 'TEXT' })
|
|
|
await assert.rejects(initializeIssueStartDate(42, '2026-08-28'), /Start date 字段必须为 Date/)
|
|
|
- assert.equal(requests.length, 2)
|
|
|
+ response = projectGraphqlData({ startDateIsIssueField: false })
|
|
|
+ await assert.rejects(
|
|
|
+ initializeIssueStartDate(42, '2026-08-28'),
|
|
|
+ /Start date 字段必须为 Issue Date 字段/,
|
|
|
+ )
|
|
|
+ response = projectGraphqlData({ startDateIssueField: false })
|
|
|
+ await assert.rejects(
|
|
|
+ initializeIssueStartDate(42, '2026-08-28'),
|
|
|
+ /Start date 字段必须为 Issue Date 字段/,
|
|
|
+ )
|
|
|
+ assert.equal(requests.length, 4)
|
|
|
})
|
|
|
|
|
|
test('does not treat pull request references as Issue associations', () => {
|