Skip to content

Commit

Permalink
feat: project based licenses report
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Oct 2, 2020
1 parent 7d84b1e commit 981c36d
Show file tree
Hide file tree
Showing 9 changed files with 693 additions and 81 deletions.
50 changes: 37 additions & 13 deletions src/lib/generate-report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as Handlebars from 'handlebars';
import * as path from 'path';
import * as fs from 'fs';
import * as debugLib from 'debug';
import * as _ from 'lodash';

import { LicenseReportData } from '../generate-org-license-report';
import { OrgData } from '../get-org-data';
import { SupportedViews } from '../types';
import _ = require('lodash');
import { SupportedViews, LicenseReportDataEntry } from '../types';

const debug = debugLib('snyk-licenses:generateHtmlReport');
const DEFAULT_TEMPLATE = './templates/licenses-view.hbs';
Expand Down Expand Up @@ -50,29 +50,53 @@ function transformDataForLicenseView(
}

interface ProjectsReportData {
[projectId: string]: LicenseReportData;
[projectId: string]: {
projectName: string;
projectIndex: number;
licenses: {
[licenseId: string]: LicenseReportDataEntry;
};
};
}

function transformDataForDependencyView(
orgPublicId: string,
data: LicenseReportData,
orgData: OrgData,
): {
projects: ProjectsReportData;
orgPublicId: string;
orgData: OrgData;
} {

): {
projects: ProjectsReportData;
orgPublicId: string;
orgData: OrgData;
totalProjects: number;
} {
const projectData: ProjectsReportData = {};
let totalProjects = 0;

for (const licenseId in Object.keys(data)) {
console.log('*** licenseId=', licenseId);
for (const licenseId of Object.keys(data)) {
const licenseData = data[licenseId];

for (const project of licenseData.projects) {
if (!projectData[project.id]) {
totalProjects += 1;
projectData[project.id] = {
projectIndex: totalProjects,
projectName: project.name,
licenses: {
[licenseId]: licenseData,
},
};
} else {
projectData[project.id].licenses[licenseId] = licenseData;
}
}
}


return { projects: projectData, orgPublicId, orgData };
return {
projects: projectData,
orgPublicId,
orgData,
totalProjects,
};
}

function selectTemplate(view: SupportedViews, templateOverride?): string {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/generate-report/templates/licenses-view.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@

<main class="u-padding--xl">
<h1>Snyk Licenses Attribution Report</h1>
<h2>Org: <a href="{{orgData.url}}">{{orgData.name}}</a></h2>
<h2>Organization: <a href="{{orgData.url}}">{{orgData.name}}</a></h2>
{{#each licenses}}
<div class="u-padding-top--sm">
<h1 class="license_title license_title--{{severity}}">
Expand Down
107 changes: 54 additions & 53 deletions src/lib/generate-report/templates/project-dependencies-view.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
color: #393842;
}
.project-section {
margin-top: 3rem;
}
.banner-logo {
padding-right: 2%;
margin-top: .85em;
Expand Down Expand Up @@ -82,12 +86,12 @@
}
.column {
flex: 1 0 150px;
flex: 1 0 200px;
max-width: 100%;
}
.column-large {
flex: 1 0 300px;
flex: 1 0 500px;
max-width: 100%;
}
Expand Down Expand Up @@ -143,67 +147,64 @@

<main class="u-padding--xl">
<h1>Snyk Licenses Attribution Report</h1>
<h2>Org: <a href="{{orgData.url}}">{{orgData.name}}</a></h2>
{{#each licenses}}
<div class="u-padding-top--sm">
<h1 class="license_title license_title--{{severity}}">
<a href="{{licenseUrl}}">{{id}}</a>
<h2>Organization: <a href="{{orgData.url}}">{{orgData.name}}</a></h2>
{{#each projects}}
<section class="project-section">
<h1>
Project ({{projectIndex}}/{{../totalProjects}}): <a href="{{../orgData.url}}/project/{{projectId}}">{{projectName}}</a>
</h1>
<strong>Severity</strong>: {{severity}}
{{#if instructions}}
<strong>Legal Instructions</strong>: {{instructions}}
{{/if}}
</div>

<div class="display-flex border-right border-top border-bottom border-left u-margin-top--sm">
<div class="column-large">
<div>
<div class="display-flex">
<div class="u-padding--sm dependency border-right">
<strong>Dependencies</strong>
</div>
<div class="u-padding--sm">
<strong>Copyrights</strong>
</div>
</div>
{{#each licenses}}
<div class="u-padding-top--sm">
<h2 class="license_title license_title--{{severity}}">
<a href="{{licenseUrl}}">{{id}}</a>
</h2>
<strong>Severity</strong>: {{severity}}
{{#if instructions}}
<strong>Legal Instructions</strong>: {{instructions}}
{{/if}}
</div>

<div>
{{#each dependencies}}
<div class="display-flex border-top">
<div class="u-padding--sm dependency">
{{name}}@{{version}}
<div class="display-flex border-right border-top border-bottom border-left u-margin-top--sm">
<div class="column-large">
<div>
<div class="display-flex">
<div class="u-padding--sm dependency border-right">
<strong>Dependencies</strong>
</div>
<div class="u-padding--sm">
<strong>Copyrights</strong>
</div>
</div>
<div class="u-padding--sm overflow-auto">
{{#each copyright}}
<div class="u-padding-top--sm overflow-auto">
{{this}}

<div>
{{#each dependencies}}
<div class="display-flex border-top">
<div class="u-padding--sm dependency">
{{name}}@{{version}}
</div>
<div class="u-padding--sm overflow-auto">
{{#each copyright}}
<div class="u-padding-top--sm overflow-auto">
{{this}}
</div>
{{/each}}
</div>
</div>

{{/each}}
</div>
</div>

{{/each}}
</div>
<div class="border-left overflow-auto">
<div class="border-bottom u-padding--sm">
<strong>License Text</strong>
</div>
<div class="u-padding--sm">{{{licenseText}}}</div>
</div>
</div>
</div>
<div class="column border-left">
<div class="border-bottom u-padding--sm">
<strong>Projects in Snyk</strong>
</div>
<div class="u-padding--sm">
{{#each projects}}
<a class="u-padding-top--sm" href="{{../../orgData.url}}/project/{{id}}">{{name}}</a><br>
{{/each}}
</div>
</div>
<div class="border-left overflow-auto">
<div class="border-bottom u-padding--sm">
<strong>License Text</strong>
</div>
<div class="u-padding--sm">{{{licenseText}}}</div>
</div>
</div>
</div>
{{/each}}
</section>
{{/each}}
</main>
</body>
Expand Down
Loading

0 comments on commit 981c36d

Please sign in to comment.