Commit 0028339c authored by Phil Hughes's avatar Phil Hughes

Merge branch '280766-block-mr-widget-on-jira-missing' into 'master'

Add jira association missing state to MR widget

See merge request gitlab-org/gitlab!58658
parents c106cc5d e8e5a425
<script>
import StatusIcon from '~/vue_merge_request_widget/components/mr_widget_status_icon.vue';
export default {
name: 'MrWidgetJiraAssociationMissing',
components: {
StatusIcon,
},
};
</script>
<template>
<div class="mr-widget-body media">
<status-icon :show-disabled-button="true" status="warning" />
<div class="media-body">
<strong class="gl-font-weight-bold gl-text-gray-700">
{{
s__('mrWidget|To merge, a Jira issue key must be mentioned in the title or description.')
}}
</strong>
</div>
</div>
</template>
......@@ -10,6 +10,7 @@ import { s__, __, sprintf } from '~/locale';
import ReportSection from '~/reports/components/report_section.vue';
import CEWidgetOptions from '~/vue_merge_request_widget/mr_widget_options.vue';
import BlockingMergeRequestsReport from './components/blocking_merge_requests/blocking_merge_requests_report.vue';
import MrWidgetJiraAssociationMissing from './components/states/mr_widget_jira_association_missing.vue';
import MrWidgetPolicyViolation from './components/states/mr_widget_policy_violation.vue';
import MrWidgetGeoSecondaryNode from './components/states/mr_widget_secondary_geo_node.vue';
......@@ -18,6 +19,7 @@ export default {
MrWidgetLicenses,
MrWidgetGeoSecondaryNode,
MrWidgetPolicyViolation,
MrWidgetJiraAssociationMissing,
BlockingMergeRequestsReport,
GroupedSecurityReportsApp: () =>
import('ee/vue_shared/security_reports/grouped_security_reports_app.vue'),
......
......@@ -10,5 +10,9 @@ export default function getStateKey() {
return stateKey.policyViolation;
}
if (this.jiraAssociation.enforced && this.jiraAssociation.issue_keys.length === 0) {
return stateKey.jiraAssociationMissing;
}
return CEGetStateKey.call(this);
}
......@@ -46,6 +46,7 @@ export default class MergeRequestStore extends CEMergeRequestStore {
this.mergeTrainsCount = data.merge_trains_count || 0;
this.mergeTrainIndex = data.merge_train_index;
this.policyViolation = data.policy_violation;
this.jiraAssociation = data.jira_associations || {};
super.setData(data, isRebased);
}
......
......@@ -2,9 +2,11 @@ import stateMaps from '~/vue_merge_request_widget/stores/state_maps';
stateMaps.stateToComponentMap.geoSecondaryNode = 'mr-widget-geo-secondary-node';
stateMaps.stateToComponentMap.policyViolation = 'mr-widget-policy-violation';
stateMaps.stateToComponentMap.jiraAssociationMissing = 'mr-widget-jira-association-missing';
export const stateKey = {
policyViolation: 'policyViolation',
jiraAssociationMissing: 'jiraAssociationMissing',
};
export default {
......
import getStateKey from 'ee/vue_merge_request_widget/stores/get_state_key';
describe('getStateKey', () => {
const canMergeContext = {
canMerge: true,
commitsCount: 2,
};
describe('jiraAssociationMissing', () => {
const createContext = (enforced, hasIssues) => ({
...canMergeContext,
jiraAssociation: {
enforced,
issue_keys: hasIssues ? [1] : [],
},
});
it.each`
scenario | enforced | hasIssues | state
${'enforced with issues'} | ${true} | ${true} | ${null}
${'enforced without issues'} | ${true} | ${false} | ${'jiraAssociationMissing'}
${'not enforced with issues'} | ${false} | ${true} | ${null}
${'not enforced without issues'} | ${false} | ${false} | ${null}
`('when $scenario, state should equal $state', ({ enforced, hasIssues, state }) => {
const bound = getStateKey.bind(createContext(enforced, hasIssues));
expect(bound()).toBe(state);
});
});
});
import { shallowMount } from '@vue/test-utils';
import MrWidgetJiraAssociationMissing from 'ee/vue_merge_request_widget/components/states/mr_widget_jira_association_missing.vue';
import StatusIcon from '~/vue_merge_request_widget/components/mr_widget_status_icon.vue';
describe('MrWidgetJiraAssociationMissing', () => {
let wrapper;
const findStatusIcon = () => wrapper.find(StatusIcon);
const createComponent = () => {
wrapper = shallowMount(MrWidgetJiraAssociationMissing);
};
afterEach(() => {
wrapper.destroy();
wrapper = null;
});
beforeEach(() => {
createComponent();
});
it('shows the disabled merge button', () => {
expect(findStatusIcon().props('showDisabledButton')).toBe(true);
});
it('shows the disabled reason', () => {
expect(wrapper.text()).toContain(
'To merge, a Jira issue key must be mentioned in the title or description.',
);
});
});
......@@ -36990,6 +36990,9 @@ msgstr ""
msgid "mrWidget|To approve this merge request, please enter your password. This project requires all approvals to be authenticated."
msgstr ""
msgid "mrWidget|To merge, a Jira issue key must be mentioned in the title or description."
msgstr ""
msgid "mrWidget|Use %{linkStart}CI pipelines to test your code%{linkEnd} by simply adding a GitLab CI configuration file to your project. It only takes a minute to make your code more secure and robust."
msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment