lab.nexedi.com will be down from Thursday, 20 March 2025, 07:30:00 UTC for a duration of approximately 2 hours

Commit f313562f authored by Dave Pisek's avatar Dave Pisek

Review feedback: Use commit_path_template

parent 4ea68d4a
......@@ -167,6 +167,14 @@ module CommitsHelper
]
end
DEFAULT_SHA = '0000000'
# Returns the template path for commit resources
# to be utilized by the client applications.
def commit_path_template(project)
project_commit_path(project, DEFAULT_SHA).sub("/#{DEFAULT_SHA}", '/$COMMIT_SHA')
end
protected
# Private: Returns a link to a person. If the person has a matching user and
......
......@@ -23,7 +23,7 @@ export default () => {
vulnerabilitiesEndpoint,
emptyStateUnauthorizedSvgPath,
emptyStateForbiddenSvgPath,
commitBasePath,
commitPathTemplate,
projectFullPath,
pipelineJobsPath,
canAdminVulnerability,
......@@ -44,7 +44,7 @@ export default () => {
provide: {
dashboardType: DASHBOARD_TYPES.PIPELINE,
projectId: parseInt(projectId, 10),
commitBasePath,
commitPathTemplate,
projectFullPath,
dashboardDocumentation,
emptyStateSvgPath,
......
......@@ -5,7 +5,7 @@ export default {
components: {
GlLink,
},
inject: ['commitBasePath'],
inject: ['commitPathTemplate'],
props: {
value: {
type: String,
......@@ -14,7 +14,11 @@ export default {
},
computed: {
commitPath() {
return `${this.commitBasePath}/${this.value}`;
// search for all occurences of "$COMMIT_SHA" within the given template, eg.: "/base/project/path/-/commit/$COMMIT_SHA"
const allCommitShaPlaceHolders = /\$COMMIT_SHA/g;
// Replace it with the actual commit hash
// NOTE: This can be swapped to using `replaceAll` once it's more widely supported
return this.commitPathTemplate.replace(allCommitShaPlaceHolders, this.value);
},
},
};
......
......@@ -18,7 +18,7 @@ export default (el) => {
provide: {
reportType: vulnerability.reportType,
newIssueUrl: vulnerability.newIssueUrl,
commitBasePath: el.dataset.commitBasePath,
commitPathTemplate: el.dataset.commitPathTemplate,
projectFingerprint: vulnerability.projectFingerprint,
projectFullPath: vulnerability.project?.fullPath,
vulnerabilityId: vulnerability.id,
......
......@@ -21,7 +21,7 @@
empty_state_unauthorized_svg_path: image_path('illustrations/user-not-logged-in.svg'),
empty_state_forbidden_svg_path: image_path('illustrations/lock_promotion.svg'),
project_full_path: project.path_with_namespace,
commit_base_path: "#{project_path(project)}/-/commit",
commit_path_template: commit_path_template(project),
can_admin_vulnerability: can?(current_user, :admin_vulnerability, project).to_s,
security_report_help_page_link: help_page_path('user/application_security/index', anchor: 'security-report-validation') } }
......
......@@ -6,4 +6,4 @@
- add_page_specific_style 'page_bundles/security_dashboard'
#js-vulnerability-main{ data: { vulnerability: vulnerability_details_json(@vulnerability, @pipeline),
commit_base_path: "#{project_path(@vulnerability.project)}/-/commit" } }
commit_path_template: commit_path_template(@project) } }
......@@ -5,16 +5,18 @@ import Commit from 'ee/vulnerabilities/components/generic_report/types/commit.vu
const TEST_DATA = {
value: '24922148',
};
const TEST_PROJECT_COMMIT_PATH = '/foo/bar';
const TEST_COMMIT_PATH_BASE = `/foo/bar`;
const TEST_COMMIT_PATH_PARAMETERS = '?baz=quz';
const TEST_COMMIT_PATH_TEMPLATE = `${TEST_COMMIT_PATH_BASE}/$COMMIT_SHA/${TEST_COMMIT_PATH_PARAMETERS}`;
describe('ee/vulnerabilities/components/generic_report/types/commit.vue', () => {
describe.only('ee/vulnerabilities/components/generic_report/types/commit.vue', () => {
let wrapper;
const createWrapper = () => {
return shallowMount(Commit, {
propsData: TEST_DATA,
provide: {
commitBasePath: TEST_PROJECT_COMMIT_PATH,
commitPathTemplate: TEST_COMMIT_PATH_TEMPLATE,
},
});
};
......@@ -30,12 +32,12 @@ describe('ee/vulnerabilities/components/generic_report/types/commit.vue', () =>
});
it('links to the given commit hash', () => {
expect(findLink().attributes('href')).toBe(`${TEST_PROJECT_COMMIT_PATH}/${TEST_DATA.value}`);
expect(findLink().attributes('href')).toBe(
`${TEST_COMMIT_PATH_BASE}/${TEST_DATA.value}/${TEST_COMMIT_PATH_PARAMETERS}`,
);
});
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