Skip to content

Commit

Permalink
added .scope as default ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Duda committed May 9, 2024
1 parent 0c6eca0 commit d110abd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Commands/runAddCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function runAddCommand(args: Array<string>, root: string) {
let fileDataRelevancy: Map<FileData, Relevancy> = new Map();

try {
fileDataRelevancy = await relevancyTagger.start(fileDataToTag);
fileDataRelevancy = await relevancyTagger.start(fileDataToTag, fileTagsDatabase);
} catch (e) {
console.log("[Scope tags] Could not add relevancy, the changes won't be saved.");
return;
Expand Down
10 changes: 6 additions & 4 deletions src/Relevancy/RelevancyManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Commit } from "nodegit";
import { FileData, FilePath } from "../Git/Types";
import { Relevancy } from "./Relevancy";
import { FileTagsDatabase } from "../Scope/FileTagsDatabase";

const { Scale } = require('enquirer');

Expand Down Expand Up @@ -34,7 +35,6 @@ export class RelevancyManager {
private static COMMIT_MSG_PREFIX = "__relevancy__";
private static CURRENT_COMMIT = "__current__";


private _relevancyDescriptions = new Map<Relevancy, RelevancyDescription>([
[Relevancy.LOW, { name: "Low", message: "Does not list file at all (example: formatting changes)" }],
[Relevancy.MEDIUM, { name: "Medium", message: "Does list tags for file, but does not search references for it" }],
Expand All @@ -45,9 +45,11 @@ export class RelevancyManager {

public constructor() { }

public async start(entries: Array<RelevancyEntry>): Promise<Map<FileData, Relevancy>> {
public async start(entries: Array<RelevancyEntry>, fileTagsDatabase: FileTagsDatabase): Promise<Map<FileData, Relevancy>> {

const notIgnoredEntries = entries.filter(entry => !fileTagsDatabase.isIgnored(entry.newPath));

const uniqueEntries = entries.filter((value, index, self) =>
const uniqueEntries = notIgnoredEntries.filter((value, index, self) =>
index === self.findIndex((t) => (
t.newPath === value.newPath
))
Expand All @@ -68,7 +70,7 @@ export class RelevancyManager {
currentPageEntries.forEach(uniqueEntry => {
// Set every matching fileData to the same relevancy, this doesn't neet to be change specific

const matchingFileData = entries.filter(entry => entry.newPath === uniqueEntry.newPath);
const matchingFileData = notIgnoredEntries.filter(entry => entry.newPath === uniqueEntry.newPath);
matchingFileData.forEach(fileData => answerMap.set(fileData, this._getRelevancyByIndex(answer[uniqueEntry.newPath])));
});
}
Expand Down
4 changes: 4 additions & 0 deletions src/Scope/FileTagsDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ export class FileTagsDatabase implements IJSONFileDatabase<FileTagsDatabase> {
}

public isIgnored(file: string, ignoredFileExtensions?: Array<string>): boolean {
if (file.startsWith(".scope")) {
return true;
}

const fileExtenstion = path.extname(file);
if (ignoredFileExtensions && fileExtenstion) {
if (ignoredFileExtensions.includes(fileExtenstion)) {
Expand Down

0 comments on commit d110abd

Please sign in to comment.