Skip to content

Commit

Permalink
✨ Add URI parameter to Scorecard viewer (#422)
Browse files Browse the repository at this point in the history
Signed-off-by: Cintia Sanchez Garcia <cynthiasg@icloud.com>
  • Loading branch information
cynthia-sg committed Jun 20, 2023
1 parent e9bf257 commit ef5f8af
Showing 1 changed file with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions scorecards-site/static/viewer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,25 @@
Its behavior can be controlled with the following query string parameters:
- platform (required): VCS platform (eg. github.com).
- org (required): Name of the owner/organization of the repository.
- repo (required): Name of the repository.
- commit (optional): SHA1 commit hash expressed in hexadecimal format.
- theme (optional): Theme to use (light/dark).
- sort_by (optional): Sort criteria (check-name/risk-level/check-score)
- sort_direction (optional): Sort direction (asc/desc)
- embed (optional): Whether the rendered result would be embedded on another site (true/false).
(required)
- uri: Repository URI (eg. github.com/ossf/scorecard)
(or, alternatively, each component of the URI)
- platform: VCS platform (eg. github.com).
- org: Name of the owner/organization of the repository.
- repo: Name of the repository.
(optional)
- commit: SHA1 commit hash expressed in hexadecimal format.
- theme: Theme to use (light/dark).
- sort_by: Sort criteria (check-name/risk-level/check-score)
- sort_direction: Sort direction (asc/desc)
- embed: Whether the rendered result would be embedded on another site (true/false).
-->

<!DOCTYPE html>
<html lang="en" data-theme="light">
<head>
Expand Down Expand Up @@ -1086,6 +1096,16 @@
document.getElementsByClassName('table-wrapper')[0].classList.add('embedded');
}

let platform, org, repo;

if (params.uri) {
[platform, org, repo] = params.uri.split('/');
} else {
platform = params.platform;
org = params.org;
repo = params.repo;
}

let sortBy = params.sort_by || DEFAULT_SORT_BY;
let sortDirection = params.sort_direction || DEFAULT_SORT_DIRECTTION;
let scoreData;
Expand Down Expand Up @@ -1143,7 +1163,7 @@

Handlebars.registerHelper('getRepoLogo', () => {
let icon = '<svg class="repo-icon" stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 640 512" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M278.9 511.5l-61-17.7c-6.4-1.8-10-8.5-8.2-14.9L346.2 8.7c1.8-6.4 8.5-10 14.9-8.2l61 17.7c6.4 1.8 10 8.5 8.2 14.9L293.8 503.3c-1.9 6.4-8.5 10.1-14.9 8.2zm-114-112.2l43.5-46.4c4.6-4.9 4.3-12.7-.8-17.2L117 256l90.6-79.7c5.1-4.5 5.5-12.3.8-17.2l-43.5-46.4c-4.5-4.8-12.1-5.1-17-.5L3.8 247.2c-5.1 4.7-5.1 12.8 0 17.5l144.1 135.1c4.9 4.6 12.5 4.4 17-.5zm327.2.6l144.1-135.1c5.1-4.7 5.1-12.8 0-17.5L492.1 112.1c-4.8-4.5-12.4-4.3-17 .5L431.6 159c-4.6 4.9-4.3 12.7.8 17.2L523 256l-90.6 79.7c-5.1 4.5-5.5 12.3-.8 17.2l43.5 46.4c4.5 4.9 12.1 5.1 17 .6z"></path></svg>';
switch (params.platform) {
switch (platform) {
case 'github.com':
icon = '<svg class="repo-icon" stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 24 24" class="github-icon" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M12 0a12 12 0 1 0 0 24 12 12 0 0 0 0-24zm3.163 21.783h-.093a.513.513 0 0 1-.382-.14.513.513 0 0 1-.14-.372v-1.406c.006-.467.01-.94.01-1.416a3.693 3.693 0 0 0-.151-1.028 1.832 1.832 0 0 0-.542-.875 8.014 8.014 0 0 0 2.038-.471 4.051 4.051 0 0 0 1.466-.964c.407-.427.71-.943.885-1.506a6.77 6.77 0 0 0 .3-2.13 4.138 4.138 0 0 0-.26-1.476 3.892 3.892 0 0 0-.795-1.284 2.81 2.81 0 0 0 .162-.582c.033-.2.05-.402.05-.604 0-.26-.03-.52-.09-.773a5.309 5.309 0 0 0-.221-.763.293.293 0 0 0-.111-.02h-.11c-.23.002-.456.04-.674.111a5.34 5.34 0 0 0-.703.26 6.503 6.503 0 0 0-.661.343c-.215.127-.405.249-.573.362a9.578 9.578 0 0 0-5.143 0 13.507 13.507 0 0 0-.572-.362 6.022 6.022 0 0 0-.672-.342 4.516 4.516 0 0 0-.705-.261 2.203 2.203 0 0 0-.662-.111h-.11a.29.29 0 0 0-.11.02 5.844 5.844 0 0 0-.23.763c-.054.254-.08.513-.081.773 0 .202.017.404.051.604.033.199.086.394.16.582A3.888 3.888 0 0 0 5.702 10a4.142 4.142 0 0 0-.263 1.476 6.871 6.871 0 0 0 .292 2.12c.181.563.483 1.08.884 1.516.415.422.915.75 1.466.964.653.25 1.337.41 2.033.476a1.828 1.828 0 0 0-.452.633 2.99 2.99 0 0 0-.2.744 2.754 2.754 0 0 1-1.175.27 1.788 1.788 0 0 1-1.065-.3 2.904 2.904 0 0 1-.752-.824 3.1 3.1 0 0 0-.292-.382 2.693 2.693 0 0 0-.372-.343 1.841 1.841 0 0 0-.432-.24 1.2 1.2 0 0 0-.481-.101c-.04.001-.08.005-.12.01a.649.649 0 0 0-.162.02.408.408 0 0 0-.13.06.116.116 0 0 0-.06.1.33.33 0 0 0 .14.242c.093.074.17.131.232.171l.03.021c.133.103.261.214.382.333.112.098.213.209.3.33.09.119.168.246.231.381.073.134.15.288.231.463.188.474.522.875.954 1.145.453.243.961.364 1.476.351.174 0 .349-.01.522-.03.172-.028.343-.057.515-.091v1.743a.5.5 0 0 1-.533.521h-.062a10.286 10.286 0 1 1 6.324 0v.005z"></path></svg>';
break;
Expand Down Expand Up @@ -1265,11 +1285,11 @@
}
}

if (params.platform && params.org && params.repo) {
if (platform && org && repo) {
// Load placeholder
renderDataTemplate({ data: {...PLACEHOLDER, checks: sortChecks(PLACEHOLDER.checks), repo: {name: `${params.platform}/${params.org}/${params.repo}`, commit: ""}}, isPlaceholder: true, sortBy: sortBy, sortDirection: sortDirection });
renderDataTemplate({ data: {...PLACEHOLDER, checks: sortChecks(PLACEHOLDER.checks), repo: {name: `${platform}/${org}/${repo}`, commit: ""}}, isPlaceholder: true, sortBy: sortBy, sortDirection: sortDirection });

apiFetch(params.platform, params.org, params.repo, params.commit)
apiFetch(platform, org, repo, params.commit)
.then((data) => {
scoreData = data;
renderDataTemplate({ data: {...data, checks: sortChecks(data.checks)}, isPlaceholder: false, sortBy: sortBy, sortDirection: sortDirection });
Expand Down Expand Up @@ -1297,13 +1317,13 @@
});
} else {
let missingParams = [];
if (params.platform === null) {
if (platform === null || platform === undefined) {
missingParams.push('platform');
}
if (params.repo === null) {
if (repo === null || repo === undefined) {
missingParams.push('repo');
}
if (params.org === null) {
if (org === null || org === undefined) {
missingParams.push('org');
}
const template = Handlebars.compile(errorTmpl);
Expand Down

0 comments on commit ef5f8af

Please sign in to comment.