Commit 38a41d59 authored by Savas Vedova's avatar Savas Vedova

Merge branch...

Merge branch '327389-fe-generic-report-schema-render-commit-type-on-vulnerability-details-page' into 'master'

Add commit type to generic security reports

See merge request gitlab-org/gitlab!63723
parents e84cf8ce d8fa67ba
<script>
import { GlLink } from '@gitlab/ui';
import { isRootRelative } from '~/lib/utils/url_utility';
export default {
components: {
GlLink,
},
inject: ['projectFullPath'],
props: {
value: {
type: String,
required: true,
},
},
computed: {
commitPath() {
const { projectFullPath, value } = this;
// `projectFullPath` comes in two flavors: relative (e.g.: `group/project`) and absolute (e.g.: `/group/project`)
// adding a leading slash to the relative path makes sure we always link to an absolute path
const absoluteProjectPath = isRootRelative(projectFullPath)
? projectFullPath
: `/${projectFullPath}`;
return `${absoluteProjectPath}/-/commit/${value}`;
},
},
};
</script>
<template>
<gl-link :href="commitPath">{{ value }}</gl-link>
</template>
......@@ -12,6 +12,7 @@ export const REPORT_TYPES = {
table: 'table',
code: 'code',
markdown: 'markdown',
commit: 'commit',
};
const REPORT_TYPE_TO_COMPONENT_MAP = {
......@@ -26,6 +27,7 @@ const REPORT_TYPE_TO_COMPONENT_MAP = {
[REPORT_TYPES.table]: () => import('./table.vue'),
[REPORT_TYPES.code]: () => import('./code.vue'),
[REPORT_TYPES.markdown]: () => import('./markdown.vue'),
[REPORT_TYPES.commit]: () => import('./commit.vue'),
};
export const getComponentNameForType = (reportType) =>
......
......@@ -19,6 +19,7 @@ export default (el) => {
reportType: vulnerability.reportType,
newIssueUrl: vulnerability.newIssueUrl,
projectFingerprint: vulnerability.projectFingerprint,
projectFullPath: vulnerability.project?.fullPath,
vulnerabilityId: vulnerability.id,
issueTrackingHelpPath: vulnerability.issueTrackingHelpPath,
permissionsHelpPath: vulnerability.permissionsHelpPath,
......
import { GlLink } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Commit from 'ee/vulnerabilities/components/generic_report/types/commit.vue';
const TEST_DATA = {
value: '24922148',
};
describe('ee/vulnerabilities/components/generic_report/types/commit.vue', () => {
let wrapper;
const createWrapper = ({ provide } = {}) => {
return shallowMount(Commit, {
propsData: TEST_DATA,
provide: {
projectFullPath: '',
...provide,
},
});
};
const findLink = () => wrapper.findComponent(GlLink);
afterEach(() => {
wrapper.destroy();
});
it.each(['/foo/bar', 'foo/bar'])(
'given `projectFullPath` is "%s" it links to the absolute path of the commit',
(projectFullPath) => {
const absoluteCommitPath = `/foo/bar/-/commit/${TEST_DATA.value}`;
wrapper = createWrapper({ provide: { projectFullPath } });
expect(findLink().attributes('href')).toBe(absoluteCommitPath);
},
);
it('shows the value as the link-text', () => {
wrapper = createWrapper();
expect(findLink().text()).toBe(TEST_DATA.value);
});
});
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