Skip to content

Commit

Permalink
Do not allow labels with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Feb 6, 2021
1 parent 826a1ec commit dd10981
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ The following table describes the properties of the `incident` object.
| externalId | The id of the issue in Jira. If presented the incident will be update. Otherwise a new incident will be created. | string _(optional)_ |
| issueType | The id of the issue type in Jira. | string _(optional)_ |
| priority | The name of the priority in Jira. Example: `Medium`. | string _(optional)_ |
| labels | An array of labels. | string[] _(optional)_ |
| labels | An array of labels. Labels cannot contain spaces. | string[] _(optional)_ |
| parent | The parent issue id or key. Only for `Sub-task` issue types. | string _(optional)_ |

#### `subActionParams (getIncident)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ export const ExecutorSubActionPushParamsSchema = schema.object({
externalId: schema.nullable(schema.string()),
issueType: schema.nullable(schema.string()),
priority: schema.nullable(schema.string()),
labels: schema.nullable(schema.arrayOf(schema.string())),
labels: schema.nullable(
schema.arrayOf(
schema.string({
validate: (label) =>
label.includes(' ') ? `The label ${label} cannot contain spaces` : undefined,
})
)
),
parent: schema.nullable(schema.string()),
}),
comments: schema.nullable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export function getActionType(): ActionTypeModel<JiraConfig, JiraSecrets, JiraAc
validateParams: (actionParams: JiraActionParams): GenericValidationResult<unknown> => {
const errors = {
'subActionParams.incident.summary': new Array<string>(),
'subActionParams.incident.labels': new Array<string>(),
};
const validationResult = {
errors,
Expand All @@ -83,6 +84,12 @@ export function getActionType(): ActionTypeModel<JiraConfig, JiraSecrets, JiraAc
) {
errors['subActionParams.incident.summary'].push(i18n.SUMMARY_REQUIRED);
}

if (actionParams.subActionParams?.incident?.labels?.length) {
// Jira do not allows empty spaces on labels. If the label includes a whitespace show an error.
if (actionParams.subActionParams.incident.labels.some((label) => label.includes(' ')))
errors['subActionParams.incident.labels'].push(i18n.LABELS_WHITE_SPACES);
}
return validationResult;
},
actionParamsFields: lazy(() => import('./jira_params')),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ const JiraParamsFields: React.FunctionComponent<ActionParamsProps<JiraActionPara
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [actionParams]);

const areLabelsInvalid =
errors['subActionParams.incident.labels'] != null &&
errors['subActionParams.incident.labels'].length > 0 &&
incident.labels !== undefined;

return (
<Fragment>
<>
Expand Down Expand Up @@ -304,6 +309,8 @@ const JiraParamsFields: React.FunctionComponent<ActionParamsProps<JiraActionPara
defaultMessage: 'Labels',
}
)}
error={errors['subActionParams.incident.labels'] as string[]}
isInvalid={areLabelsInvalid}
>
<EuiComboBox
noSuggestions
Expand Down Expand Up @@ -331,6 +338,7 @@ const JiraParamsFields: React.FunctionComponent<ActionParamsProps<JiraActionPara
}}
isClearable={true}
data-test-subj="labelsComboBox"
isInvalid={areLabelsInvalid}
/>
</EuiFormRow>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,10 @@ export const SEARCH_ISSUES_LOADING = i18n.translate(
defaultMessage: 'Loading...',
}
);

export const LABELS_WHITE_SPACES = i18n.translate(
'xpack.triggersActionsUI.components.builtinActionTypes.jira.requiredSummaryTextField',
{
defaultMessage: 'Labels cannot contain spaces.',
}
);

0 comments on commit dd10981

Please sign in to comment.