diff --git a/src/BacklogService.ts b/src/BacklogService.ts index 6825cc9..53804cc 100644 --- a/src/BacklogService.ts +++ b/src/BacklogService.ts @@ -1,5 +1,5 @@ import {BacklogClient, BacklogClientImpl, GoogleAppsScriptDateFormatter} from "./BacklogClient" -import {Key, Project, Issue, BacklogDefinition, Locale, UserProperty, CustomFieldDefinition, IssueType} from "./datas" +import {Key, Project, Issue, BacklogDefinition, Locale, UserProperty, CustomFieldDefinition, IssueType, isSupportedCustomField} from "./datas" import {HttpClient} from "./Http" import {Option, Some, None} from "./Option" import {Either, Right, Left} from "./Either" @@ -45,7 +45,14 @@ export const getProject = (client: BacklogClient, key: Key, locale: Loc } const validate = (issues: List, issueTypes: List, customFieldDefinitions: List, client: BacklogClient, locale: Locale): Either => { - const definitions = customFieldDefinitions.filter(item => item.typeId < 6) + for (let i = 0; i < customFieldDefinitions.length; i++) { + const definition = customFieldDefinitions[i] + + if (definition.required && !isSupportedCustomField(definition)) + return Left(Error(Message.VALIDATE_CUSTOM_FIELD_VALUE_IS_REQUIRED_UNSUPPORTED(definition.name, locale))) + } + + const definitions = customFieldDefinitions.filter(item => isSupportedCustomField(item)) for (let i = 0; i < issues.length; i++) { const issue = issues[i] @@ -353,7 +360,7 @@ export const BacklogService = (spreadSheetService: SpreadSheetService): BacklogS */ let customFieldName = "" - if (customField.typeId >= 6) + if (!isSupportedCustomField(customField)) continue switch (customField.typeId) { case 1: @@ -395,7 +402,7 @@ export const BacklogService = (spreadSheetService: SpreadSheetService): BacklogS let validationRuleIndex = 0 for (let i = 0; i < definition.customFields.length; i++) { const customField = definition.customFields[i] - if (customField.typeId >= 6) + if (!isSupportedCustomField(customField)) continue if (customField.typeId === 5) { definition.customFieldItemNames(customField).map(itemNames => { diff --git a/src/datas.ts b/src/datas.ts index f3a0560..da4e698 100644 --- a/src/datas.ts +++ b/src/datas.ts @@ -97,6 +97,9 @@ export interface CustomField extends WithId { } export const CustomField = (id: number, fieldTypeId: number, value: any) => ({id, fieldTypeId, value}) +export const isSupportedCustomField = (definition: CustomFieldDefinition) => + definition.typeId < 6 + export interface BacklogDefinition { readonly issueTypes: List readonly categories: List diff --git a/src/resources.ts b/src/resources.ts index 073140f..7782be6 100644 --- a/src/resources.ts +++ b/src/resources.ts @@ -152,6 +152,13 @@ export const Message = { } return msg[locale] }, + VALIDATE_CUSTOM_FIELD_VALUE_IS_REQUIRED_UNSUPPORTED: (definitionName: string, locale: Locale): string => { + const msg = { + "en": `Custom field value '${definitionName}' is required but it isn't supported. Please cancel this setting.`, + "ja": `カスタム属性 '${definitionName}' は必須ですがサポートされていません。必須の設定を解除してください。` + } + return msg[locale] + }, VALIDATE_CUSTOM_FIELD_VALUE_IS_NUMBER: (definitionName: string, input: string, locale: Locale): string => { const msg = { "en": `Custom field value '${definitionName}' needs number. Row input: ${input}`,