Skip to content

Commit

Permalink
fixed async stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Duda committed Mar 11, 2024
1 parent 08cf8f8 commit fa5eead
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 35 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ npm i scope-tags -D

- Option `gitCommitCountLimit` is a maximum number of commits to search for when doing rev walk on git push hook - used just on the user side while running commands `--verify-unpushed-commits` or `--skip`. It this number is reached you'll get a warning and ignoring it may result in some files being ommited from tag verification.

- Option `logsURL` is used to link to logs directly from generated reports - makes it easier to see all changes which were made to that build. It is optional, if not present the link won't be added to reports. The URL should contain build tag (`"buildTag"` specified in build metadata file) somewhere.

```
"logsURL"
```

### Features to do

- [x] Import `ts-morph` library
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scope-tags",
"version": "0.1.18",
"version": "0.1.20",
"description": "Output human readable test scope report for QA",
"main": "dist/scope.js",
"types": "dist/scope.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/runReportForCommitCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function runReportForCommitCommand(args: Array<string>, root: string) {
}
})

const generator = new ReportGenerator(repository, tagsDefinitionFile, fileTagsDatabase, referenceFinders);
const generator = new ReportGenerator(repository, tagsDefinitionFile, fileTagsDatabase, configFile, referenceFinders);
const relevancyManager = new RelevancyManager();

repository.getCommitByHash(hash).then(async (commit: Commit) => {
Expand Down
54 changes: 27 additions & 27 deletions src/Commands/runReportForCommitListCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Commit } from "nodegit";
import { GitRepository } from "../Git/GitRepository";
import { ExternalMapReferenceFinder } from "../References/ExternalMapReferenceFinder";
import { IReferenceFinder } from "../References/IReferenceFinder";
Expand All @@ -14,7 +13,7 @@ import { Logger } from "../Logger/Logger";

const os = require("os");

export function runReportForCommitListCommand(args: Array<string>, root: string) {
export async function runReportForCommitListCommand(args: Array<string>, root: string) {
// Checks if all files from the commit are present in database (or excluded)

const buildDataFile = args[1];
Expand Down Expand Up @@ -59,52 +58,53 @@ export function runReportForCommitListCommand(args: Array<string>, root: string)
}
})

const generator = new ReportGenerator(repository, tagsDefinitionFile, fileTagsDatabase, referenceFinders);
const generator = new ReportGenerator(repository, tagsDefinitionFile, fileTagsDatabase, configFile, referenceFinders);
const relevancyTagger = new RelevancyManager();
const buildIntegration = new BuildIntegration(buildDataFile, configFile);
const uniqueIssues = buildIntegration.getUniqueIssues();

let totalCommitCount = 0;

uniqueIssues.forEach(issue => {
for (const issue of uniqueIssues) {
console.log(`[Scope tags]: Checking commits of issue '${issue}'`);

const commits = buildIntegration.getIssueCommits(issue);
const issueCommits = buildIntegration.getIssueCommits(issue);
const buildTag = buildIntegration.getBuildTag();

Logger.setConfigurationProperty("Build tag", buildTag);

repository.getCommitsByHashes(commits.map(commit => commit.hash)).then(async (commits: Commit[]) => {
for (const commit of commits) {
console.log(`[Scope tags]: Found '${commit.summary()}'`);
}
// const commits = await repository.getCommitsByHashes(commits.map(commit => commit.hash)).then(async (commits: Commit[]) => {
const commits = await repository.getCommitsByHashes(issueCommits.map(commit => commit.hash));

Logger.pushIssueInfo(issue, commits);
for (const commit of commits) {
console.log(`[Scope tags]: Found '${commit.summary()}'`);
}

totalCommitCount += commits.length;
Logger.pushIssueInfo(issue, commits);

console.log(`[Scope tags]: Loading relevancy map...'`);
const relevancyMap = relevancyTagger.loadRelevancyMapFromCommits(commits);
totalCommitCount += commits.length;

console.log(`[Scope tags]: Generating report for issue '${issue}'...'`);
const report = await generator.generateReportForCommits(commits, projects[0].name, buildTag, false, relevancyMap);
console.log(`[Scope tags]: Loading relevancy map...'`);
const relevancyMap = relevancyTagger.loadRelevancyMapFromCommits(commits);

if (generator.isReportEmpty(report)) {
console.log(`[Scope tags]: Report ommited because no tags for modified files were found'`);
return;
}
console.log(`[Scope tags]: Generating report for issue '${issue}'...'`);
const report = await generator.generateReportForCommits(commits, projects[0].name, buildTag, false, relevancyMap);

const commentReportJSON = generator.getReportAsJiraComment(report, false);
if (generator.isReportEmpty(report)) {
console.log(`[Scope tags]: Report ommited because no tags for modified files were found'`);
return;
}

const commentReportJSON = generator.getReportAsJiraComment(report, false);

console.log(`[Scope tags]: Posting report as comment for issue '${issue}'...'`);
console.log(`[Scope tags]: Posting report as comment for issue '${issue}'...'`);

await buildIntegration.updateIssue({
issue: issue,
report: commentReportJSON,
hostname: os.hostname(),
});
await buildIntegration.updateIssue({
issue: issue,
report: commentReportJSON,
hostname: os.hostname(),
});
});
}

if (logFilePath) {
if (fileExists(logFilePath)) {
Expand Down
1 change: 1 addition & 0 deletions src/HTMLCreator/CSSOverrides.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const CSSOverrides = `
:root {
--justify-important: left;
--width-content: 1800px;
}
hr {
Expand Down
5 changes: 5 additions & 0 deletions src/Report/AdfUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export function applyMark(mark: any, maybeNode: any) {
return node;
}

export const link = (attrs: any) => (maybeNode: any) => applyMark({
type: 'link',
attrs
}, maybeNode);

function isDuplicateMark(node: any, type: any) {
if (node.marks && node.marks.some((mark: any) => mark.type === type)) {
return true;
Expand Down
33 changes: 30 additions & 3 deletions src/Report/JiraBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { formatDate } from "./TimeUtils";
import { expand, table, doc, tableRow, tableHeader, nestedExpand, p, strong } from "./AdfUtils";
import {
expand,
table,
doc,
tableRow,
tableHeader,
nestedExpand,
p,
strong,
text,
link,
} from "./AdfUtils";
import { getScriptVersion } from "../scope";
import { ReferencedFileInfo } from "../References/IReferenceFinder";

Expand Down Expand Up @@ -34,7 +45,8 @@ export class JiraBuilder {
date: Date,
projectName: string,
buildTag: string,
printToConsole = false
printToConsole = false,
logURL?: string
): string {
let tableTitle = `'${projectName}' scope tags v${getScriptVersion()}${formatDate(date, "Europe/Warsaw")}`;
tableTitle += buildTag ? ` │ ${buildTag}` : "";
Expand All @@ -47,9 +59,13 @@ export class JiraBuilder {
...{ attrs: { layout: "full-width" } }
};

const expandContent = logURL ? [reportTable, this._createLink(logURL, "Go to build logs")] : [reportTable];

const expandTable = expand(
{ title: tableTitle },
)(reportTable);
)(
...expandContent
);

const adfDocument = doc(expandTable);

Expand Down Expand Up @@ -114,6 +130,17 @@ export class JiraBuilder {
});
}

private _createLink(url: string, description: string) {
const adfText = text(description);

const adfLink = link({
href: url,
title: description
})(adfText);

return p(adfLink);
}

// Enables to paste the generated ADF to the online viewer
public debugPrintADF(document: any) {
console.log(`
Expand Down
7 changes: 5 additions & 2 deletions src/Report/ReportGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { JiraBuilder, ModuleInfo, ReportTableRow, TagInfo } from "./JiraBuilder"
import { RelevancyMap } from "../Relevancy/RelevancyManager";
import { Relevancy } from "../Relevancy/Relevancy";
import { Logger } from "../Logger/Logger";
import { ConfigFile } from "../Scope/ConfigFile";

export type ModuleReport = {
module: Module["name"],
Expand Down Expand Up @@ -41,7 +42,8 @@ export class ReportGenerator {
private _repository: GitRepository,
private _tagsDefinitionFile: TagsDefinitionFile,
private _fileTagsDatabase: FileTagsDatabase,
private _referenceFinders: Array<IReferenceFinder>
private _configFile: ConfigFile,
private _referenceFinders: Array<IReferenceFinder>,
) { }

public async generateReportForCommit(commit: Commit, projectName: string, relevancyMap: RelevancyMap): Promise<Report> {
Expand Down Expand Up @@ -301,7 +303,8 @@ export class ReportGenerator {
report.date,
report.projectName,
report.jobName,
printToConsole
printToConsole,
this._configFile.getLogsURL(report.jobName),
);
}

Expand Down
15 changes: 14 additions & 1 deletion src/Scope/ConfigFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ export type ConfigFileType = {
updateIssueURL?: string,
ignoredExtensions?: Array<string>,
viewIssueURL?: string, // Used only for linking to issues in HTML logs
logsURL?: string,
};

export class ConfigFile implements IJSONFileDatabase<ConfigFile> {
private static PATH = ".scope/config.json";
private static LOGURL_BUILD_REPLACE_TAG = "__BUILD__";

private _root: string;
private _config: ConfigFileType;
Expand Down Expand Up @@ -70,7 +72,18 @@ export class ConfigFile implements IJSONFileDatabase<ConfigFile> {
return false;
}

public getViewIssueUrl(): any {
public getViewIssueUrl(): string | undefined {
return this._config.viewIssueURL;
}

public getLogsURL(buildTag: string): string | undefined {
if (!buildTag) {
console.log("[ConfigFile] Could not create logs URL because of empty buildTag");
return;
} else if (!this._config.logsURL?.includes(ConfigFile.LOGURL_BUILD_REPLACE_TAG)) {
console.log(`[ConfigFile] Could not create logs URL because logsURL does not include required tag '${ConfigFile.LOGURL_BUILD_REPLACE_TAG}'`);
return;
}
return this._config.logsURL?.replace(ConfigFile.LOGURL_BUILD_REPLACE_TAG, buildTag);
}
}

0 comments on commit fa5eead

Please sign in to comment.