Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Duda committed May 15, 2024
1 parent 1c2e84d commit 3d37fe2
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/HTMLCreator/HTMLCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export class HTMLCreator {
},
{
type: "th",
content: "Tag / module"
content: "Module / Tag"
},
{
type: "th",
Expand Down Expand Up @@ -421,7 +421,7 @@ export class HTMLCreator {
private _renderTagIdentifiers(tagIdentifiers: TagIdentifier[]) {
return [{
type: "p",
content: tagIdentifiers.map(tagIdentifier => `<strong>${tagIdentifier.tag}</strong> / <strong>${tagIdentifier.module}</strong>`).join('<br>')
content: tagIdentifiers.map(tagIdentifier => `<strong>${tagIdentifier.module}</strong> / <strong>${tagIdentifier.tag}</strong>`).join('<br>')
}]
}

Expand Down
35 changes: 26 additions & 9 deletions src/Report/AdfUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,38 @@ export const tableRow = (content: any) => ({
content
});

export const nestedExpand = (attrs: any) => (...content: any) => ({
type: 'nestedExpand',
attrs,
content
});

/**
* Careful, nestedExpand cannot be empty inside
*/
export const nestedExpand = (attrs: any) => (...content: any) => {
// Check for empty text, as it won't be parsed by Jira
// if (Array.isArray(content) && content.some(c => c?.content?.type === "text" && c?.content?.text?.length === 0)) {
// throw new Error("[AdfUtils] Nested expands cannot have empty text field");
// }

return {
type: 'nestedExpand',
attrs,
content
};
};

export const p = (...content: any) => ({
type: 'paragraph',
content: createTextNodes(content)
});

export const text = (text: any) => ({
type: 'text',
text
});
export const text = (text: any) => {
if (!text.length) {
throw new Error("[AdfUtils] Text node cannot be empty");
}

return {
type: 'text',
text
}
};

export const strong = (maybeNode: any) => applyMark({
type: 'strong'
Expand Down
109 changes: 91 additions & 18 deletions src/Report/JiraBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import { formatDate } from "./TimeUtils";
import {
expand,
table,
doc,
tableRow,
tableHeader,
nestedExpand,
p,
strong,
text,
link,
} from "./AdfUtils";
import { expand, table, doc, tableRow, tableHeader, p, strong, text, link, nestedExpand } from "./AdfUtils";
import { getScriptVersion } from "../scope";
import { ReferencedFileInfo } from "../References/IReferenceFinder";
import { TagIdentifier } from "../Scope/FileTagsDatabase";
import { FileInfo } from "./ReportGenerator";

export type TagInfo = {
tag: string,
Expand All @@ -30,23 +21,34 @@ export type LinesInfo = {
}

export type ReportTableRow = {
affectedTags: Array<string>,
affectedTags: Array<TagIdentifier>,
lines: LinesInfo
uniqueModules: Array<ModuleInfo>,
referencedTags: Array<TagInfo>,
untaggedReferences: Array<ReferencedFileInfo>,
unusedReferences: Array<ReferencedFileInfo>,
};

export type UntaggedFilesTableRow = {
affectedFiles: Array<FileInfo>,
lines: LinesInfo
uniqueModules: Array<ModuleInfo>,
referencedTags: Array<TagInfo>,
untaggedReferences: Array<ReferencedFileInfo>,
unusedReferences: Array<ReferencedFileInfo>,
}

export class JiraBuilder {
public constructor() { }

public parseReport(
entries: Array<ReportTableRow>,
untaggedFilesRow: UntaggedFilesTableRow,
date: Date,
projectName: string,
buildTag: string,
printToConsole = false,
logURL?: string
logURL?: string,
): string {
let tableTitle = `'${projectName}' scope tags v${getScriptVersion()}${formatDate(date, "Europe/Warsaw")}`;
tableTitle += buildTag ? ` │ ${buildTag}` : "";
Expand All @@ -55,6 +57,7 @@ export class JiraBuilder {
...table(
this._getHeaderRow(),
...entries.map(entry => this._getEntryRow(entry)),
...this._getUntaggedFilesRow(untaggedFilesRow),
),
...{ attrs: { layout: "full-width" } }
};
Expand Down Expand Up @@ -94,13 +97,73 @@ export class JiraBuilder {

private _getEntryRow(entry: ReportTableRow): any {
return tableRow([
tableHeader({})(p(entry.affectedTags.join('\n'))),
tableHeader({})(p(entry.affectedTags.map(tag => `${tag.module} / ${tag.tag}`).join('\n'))),
tableHeader({})(p(`++ ${entry.lines.added}\n-- ${entry.lines.removed}`)),
tableHeader({})(...this._referencedModulesAsNestedExpands(entry.uniqueModules)),
tableHeader({})(
...this._referencedModulesAsNestedExpands(entry.uniqueModules),
...this._untaggedReferencesAsNextedExpand(entry.untaggedReferences)
),
tableHeader({})(...this._referencedTagsAsNestedExpands(entry.referencedTags, entry.unusedReferences)),
]);
}

private _getUntaggedFilesRow(entry: UntaggedFilesTableRow): any[] {
if (!entry.affectedFiles.length) {
return [];
}

return [tableRow([
tableHeader({})(this._getFileListAsNestedExpand(entry.affectedFiles)),
tableHeader({})(p(`++ ${entry.lines.added}\n-- ${entry.lines.removed}`)),
tableHeader({})(
...this._referencedModulesAsNestedExpands(entry.uniqueModules),
...this._untaggedReferencesAsNextedExpand(entry.untaggedReferences)
),
tableHeader({})(...this._referencedTagsAsNestedExpands(entry.referencedTags, entry.unusedReferences)),
])];
}

private _untaggedReferencesAsNextedExpand(untaggedReferences: ReferencedFileInfo[]): any[] {
if (!untaggedReferences.length) {
return [];
}

let title = `${untaggedReferences.length} untagged file`;

if (untaggedReferences.length > 1) {
title += "s";
}

// Careful, nestedExpand cannot be empty inside
return [nestedExpand({ title: title })(
p(untaggedReferences
.map(reference => reference.unused ? `${reference.filename} (unused)` : reference.filename)
.join("\n")
)
)];
}

// Practically the same as above
private _getFileListAsNestedExpand(files: FileInfo[]) {
if (!files.length) {
return [];
}

let title = `${files.length} untagged file`;

if (files.length > 1) {
title += "s";
}

// Careful, nestedExpand cannot be empty inside
return nestedExpand({ title: title })(
p(files
.map(file => file.file)
.join("\n")
)
);
}

private _referencedModulesAsNestedExpands(
uniqueModules: ModuleInfo[],
): any[] {
Expand All @@ -109,8 +172,13 @@ export class JiraBuilder {
}

return uniqueModules.map(uniqueModule => {
const tags: string = uniqueModule.tags.length > 0
? uniqueModule.tags.join("\n")
: "No tags";

// Careful, nestedExpand cannot be empty inside
return nestedExpand({ title: uniqueModule.module })(
p(uniqueModule.tags.join('\n'))
p(tags)
);
});
}
Expand All @@ -124,8 +192,13 @@ export class JiraBuilder {
}

return referencedTags.map(referenced => {
const modules: string = referenced.tag.length > 0
? referenced.modules.join("\n")
: "No modules";

// Careful, nestedExpand cannot be empty inside
return nestedExpand({ title: referenced.tag })(
p(referenced.modules.join('\n'))
p(modules)
);
});
}
Expand Down
Loading

0 comments on commit 3d37fe2

Please sign in to comment.