Skip to content

Commit

Permalink
fix: lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
choisohyun committed Jul 30, 2024
1 parent 17f7b61 commit 01793b1
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 83 deletions.
1 change: 1 addition & 0 deletions packages/analysis-engine/src/csm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const buildCSMNode = (baseCommitNode: CommitNode, commitDict: CommitDict, stemDi
const squashStemId = squashStartNode.stemId!;
const squashStem = stemDict.get(squashStemId);
if (!squashStem) {
// eslint-disable-next-line no-continue
continue;
}

Expand Down
25 changes: 14 additions & 11 deletions packages/analysis-engine/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,22 @@ export class AnalysisEngine {

const commitRaws = getCommitRaws(this.gitLog);
if (this.isDebugMode) console.log("commitRaws: ", commitRaws);

const commitDict = buildCommitDict(commitRaws);
if (this.isDebugMode) console.log("commitDict: ", commitDict);

const pullRequests = await this.octokit.getPullRequests().catch((err) => {
console.error(err);
isPRSuccess = false;
return [];
}).then((pullRequests) => {
console.log("success, pr = ", pullRequests);
return pullRequests;
});
if (this.isDebugMode) console.log("pullRequests: ", pullRequests, );
const pullRequests = await this.octokit
.getPullRequests()
.catch((err) => {
console.error(err);
isPRSuccess = false;
return [];
})
.then((result) => {
console.log("success, pr = ", result);
return result;
});
if (this.isDebugMode) console.log("pullRequests: ", pullRequests);

const stemDict = buildStemDict(commitDict, this.baseBranchName);
if (this.isDebugMode) console.log("stemDict: ", stemDict);
Expand All @@ -74,7 +77,7 @@ export class AnalysisEngine {

return {
isPRSuccess,
csmDict
csmDict,
};
};

Expand Down
76 changes: 37 additions & 39 deletions packages/analysis-engine/src/parser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getCommitMessageType } from "./commit.util";
import getCommitRaws from "./parser";
import getCommitRaws from "./parser";
import type { CommitRaw, DifferenceStatistic } from "./types";

describe("commit message type", () => {
Expand Down Expand Up @@ -34,85 +34,79 @@ describe("commit message type", () => {
});
});

describe('getCommitRaws', () => {
describe("getCommitRaws", () => {
const testCommitLines = [
"commit a b (HEAD)",
"commit a b (HEAD -> main, origin/main, origin/HEAD)",
"commit a b (HEAD, tag: v1.0.0)",
"commit a b (HEAD -> main, origin/main, origin/HEAD, tag: v2.0.0)",
"commit a b (HEAD, tag: v2.0.0, tag: v1.4)"
"commit a b (HEAD, tag: v2.0.0, tag: v1.4)",
];

const expectedBranches = [
['HEAD'],
['HEAD', 'main', 'origin/main', 'origin/HEAD'],
['HEAD'],
['HEAD', 'main', 'origin/main', 'origin/HEAD'],
['HEAD']
["HEAD"],
["HEAD", "main", "origin/main", "origin/HEAD"],
["HEAD"],
["HEAD", "main", "origin/main", "origin/HEAD"],
["HEAD"],
];

const expectedTags = [
[],
[],
['v1.0.0'],
['v2.0.0'],
['v2.0.0', 'v1.4']
];
const expectedTags = [[], [], ["v1.0.0"], ["v2.0.0"], ["v2.0.0", "v1.4"]];

const testCommitFileChanges = [
"10\t0\ta.ts\n1\t0\tREADME.md",
"3\t3\ta.ts",
"4\t0\ta.ts",
"0\t6\ta.ts\n2\t0\tb.ts\n3\t3\tc.ts"
"0\t6\ta.ts\n2\t0\tb.ts\n3\t3\tc.ts",
];

const expectedFileChanged:DifferenceStatistic[] = [
const expectedFileChanged: DifferenceStatistic[] = [
{
totalInsertionCount: 11,
totalDeletionCount: 0,
fileDictionary: {
'a.ts': { insertionCount: 10, deletionCount: 0 },
'README.md': { insertionCount: 1, deletionCount: 0 },
}
"a.ts": { insertionCount: 10, deletionCount: 0 },
"README.md": { insertionCount: 1, deletionCount: 0 },
},
},
{
totalInsertionCount: 3,
totalDeletionCount: 3,
fileDictionary: { 'a.ts': { insertionCount: 3, deletionCount: 3 } }
fileDictionary: { "a.ts": { insertionCount: 3, deletionCount: 3 } },
},
{
totalInsertionCount: 4,
totalDeletionCount: 0,
fileDictionary: { 'a.ts': { insertionCount: 4, deletionCount: 0 } }
fileDictionary: { "a.ts": { insertionCount: 4, deletionCount: 0 } },
},
{
totalInsertionCount: 5,
totalDeletionCount: 9,
fileDictionary: {
'a.ts': { insertionCount: 0, deletionCount: 6 },
'b.ts': { insertionCount: 2, deletionCount: 0 },
'c.ts': { insertionCount: 3, deletionCount: 3 },
}
}
"a.ts": { insertionCount: 0, deletionCount: 6 },
"b.ts": { insertionCount: 2, deletionCount: 0 },
"c.ts": { insertionCount: 3, deletionCount: 3 },
},
},
];

const commonExpectatedResult: CommitRaw={
const commonExpectatedResult: CommitRaw = {
sequence: 0,
id: 'a',
parents: ['b'],
branches: ['HEAD'],
id: "a",
parents: ["b"],
branches: ["HEAD"],
tags: [],
author: { name: 'John Park', email: 'mail@gmail.com' },
authorDate: new Date('Sun Sep 4 20:17:59 2022 +0900'),
committer: { name: 'John Park', email: 'mail@gmail.com' },
committerDate: new Date('Sun Sep 4 20:17:59 2022 +0900'),
message: 'commit message',
author: { name: "John Park", email: "mail@gmail.com" },
authorDate: new Date("Sun Sep 4 20:17:59 2022 +0900"),
committer: { name: "John Park", email: "mail@gmail.com" },
committerDate: new Date("Sun Sep 4 20:17:59 2022 +0900"),
message: "commit message",
differenceStatistic: {
totalInsertionCount: 0,
totalDeletionCount: 0,
fileDictionary: {},
},
commitMessageType: ""
commitMessageType: "",
};

testCommitLines.forEach((mockLog, index) => {
Expand All @@ -125,8 +119,12 @@ CommitDate: Sun Sep 4 20:17:59 2022 +0900
\n\tcommit message
`;
const result = getCommitRaws(mock);
const expectedResult = { ...commonExpectatedResult, branches: expectedBranches[index], tags: expectedTags[index] };

const expectedResult = {
...commonExpectatedResult,
branches: expectedBranches[index],
tags: expectedTags[index],
};

expect(result).toEqual([expectedResult]);
});
});
Expand Down
1 change: 1 addition & 0 deletions packages/analysis-engine/src/pluginOctokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export class PluginOctokit extends Octokit.plugin(throttling) {

const pullNumbers = data.map((item) => item.number);

// eslint-disable-next-line no-underscore-dangle
const pullRequests = await Promise.all(pullNumbers.map((pullNumber) => this._getPullRequest(pullNumber)));

return pullRequests;
Expand Down
2 changes: 2 additions & 0 deletions packages/analysis-engine/src/stem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ export function buildStemDict(commitDict: CommitDict, baseBranchName: string): S

while (!q.isEmpty()) {
const tail = q.pop();
// eslint-disable-next-line no-continue
if (!tail) continue;

const stemId = getStemId(tail.commit.id, tail.commit.branches, baseBranchName, mainNode, headNode);

const nodes = getStemNodes(tail.commit.id, commitDict, q, stemId);
// eslint-disable-next-line no-continue
if (nodes.length === 0) continue;

const stem: Stem = { nodes };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import {
fakeFirstClusterNode,
fakeSecondClusterNode,
fakePrev,
} from "../../../tests/fakeAsset";
import { fakeFirstClusterNode, fakeSecondClusterNode, fakePrev } from "../../../tests/fakeAsset";

import { selectedDataUpdater } from "./VerticalClusterList.util";

const EmptyArrayAddSelectedDataUpdater = selectedDataUpdater(
fakeFirstClusterNode,
0,
);
const EmptyArrayAddSelectedDataUpdater = selectedDataUpdater(fakeFirstClusterNode, 0);
const PrevAddSelectedDataUpdater = selectedDataUpdater(fakeFirstClusterNode, 5);
const RemoveSelectedDataUpdater = selectedDataUpdater(fakeSecondClusterNode, 1);

Expand Down
13 changes: 6 additions & 7 deletions packages/vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as vscode from "vscode";
import { COMMAND_LAUNCH, COMMAND_LOGIN_WITH_GITHUB, COMMAND_RESET_GITHUB_AUTH } from "./commands";
import { Credentials } from "./credentials";
import { GithubTokenUndefinedError, WorkspacePathUndefinedError } from "./errors/ExtensionError";
import { deleteGithubToken, getGithubToken, setGithubToken, } from "./setting-repository";
import { deleteGithubToken, getGithubToken, setGithubToken } from "./setting-repository";
import { mapClusterNodesFrom } from "./utils/csm.mapper";
import {
findGit,
Expand All @@ -18,7 +18,7 @@ import {
import WebviewLoader from "./webview-loader";

let myStatusBarItem: vscode.StatusBarItem;
const projectName = 'githru';
const projectName = "githru";

function normalizeFsPath(fsPath: string) {
return fsPath.replace(/\\/g, "/");
Expand All @@ -27,7 +27,7 @@ function normalizeFsPath(fsPath: string) {
export async function activate(context: vscode.ExtensionContext) {
const { subscriptions, extensionPath, secrets } = context;
const credentials = new Credentials();
let currentPanel: vscode.WebviewPanel | undefined = undefined;
let currentPanel: vscode.WebviewPanel | undefined;

await credentials.initialize(context);

Expand Down Expand Up @@ -58,16 +58,15 @@ export async function activate(context: vscode.ExtensionContext) {

const fetchBranches = async () => await getBranches(gitPath, currentWorkspacePath);
const fetchCurrentBranch = async () => {

let branchName;
try {
branchName = await getCurrentBranchName(gitPath, currentWorkspacePath)
branchName = await getCurrentBranchName(gitPath, currentWorkspacePath);
} catch (error) {
console.error(error);
console.error(error);
}

if (!branchName) {
const branchList = (await fetchBranches()).branchList;
const { branchList } = await fetchBranches();
branchName = getDefaultBranchName(branchList);
}
return branchName;
Expand Down
7 changes: 3 additions & 4 deletions packages/vscode/src/setting-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const setGithubToken = async (secrets: vscode.SecretStorage, newGithubTok
};

export const deleteGithubToken = async (secrets: vscode.SecretStorage) => {
return await secrets.delete(SETTING_PROPERTY_NAMES.GITHUB_TOKEN);
}
return await secrets.delete(SETTING_PROPERTY_NAMES.GITHUB_TOKEN);
};

export const setPrimaryColor = (color: string) => {
const configuration = vscode.workspace.getConfiguration();
Expand All @@ -29,7 +29,6 @@ export const getPrimaryColor = (): string => {
if (!primaryColor) {
configuration.update(SETTING_PROPERTY_NAMES.PRIMARY_COLOR, "#ff8272");
return "#ff8272";
} else {
return primaryColor;
}
return primaryColor;
};
1 change: 1 addition & 0 deletions packages/vscode/src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as assert from "assert";

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from "vscode";
Expand Down
3 changes: 2 additions & 1 deletion packages/vscode/src/test/suite/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from "path";

import * as glob from "glob";
import * as Mocha from "mocha";
import * as path from "path";

export function run(): Promise<void> {
// Create the mocha test
Expand Down
18 changes: 8 additions & 10 deletions packages/vscode/src/utils/git.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,12 @@ function findGitOnDarwin() {

function findGitOnWin32() {
return (
findSystemGitWin32(process.env["ProgramW6432"])
findSystemGitWin32(process.env.ProgramW6432)
.then(undefined, () => findSystemGitWin32(process.env["ProgramFiles(x86)"]))
.then(undefined, () => findSystemGitWin32(process.env["ProgramFiles"]))
.then(undefined, () => findSystemGitWin32(process.env.ProgramFiles))
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
.then(undefined, () =>
findSystemGitWin32(
process.env["LocalAppData"] ? path.join(process.env["LocalAppData"]!, "Programs") : undefined
)
findSystemGitWin32(process.env.LocalAppData ? path.join(process.env.LocalAppData!, "Programs") : undefined)
)
.then(undefined, () => findGitWin32InPath())
);
Expand All @@ -103,7 +101,7 @@ function findSystemGitWin32(pathBase?: string) {
return pathBase ? getGitExecutable(path.join(pathBase, "Git", "cmd", "git.exe")) : Promise.reject<GitExecutable>();
}
async function findGitWin32InPath() {
const dirs = (process.env["PATH"] || "").split(";");
const dirs = (process.env.PATH || "").split(";");
dirs.unshift(process.cwd());

for (let i = 0; i < dirs.length; i++) {
Expand Down Expand Up @@ -169,7 +167,7 @@ export async function getGitLog(gitPath: string, currentWorkspacePath: string):
resolveSpawnOutput(
cp.spawn(gitPath, args, {
cwd: currentWorkspacePath,
env: Object.assign({}, process.env),
env: { ...process.env },
})
).then((values) => {
const [status, stdout, stderr] = values;
Expand All @@ -193,7 +191,7 @@ export async function getGitConfig(
resolveSpawnOutput(
cp.spawn(gitPath, args, {
cwd: currentWorkspacePath,
env: Object.assign({}, process.env),
env: { ...process.env },
})
).then((values) => {
const [status, stdout, stderr] = values;
Expand Down Expand Up @@ -235,7 +233,7 @@ export async function getBranches(
const [status, stdout, stderr] = await resolveSpawnOutput(
cp.spawn(path, ["branch", "-a"], {
cwd: repo,
env: Object.assign({}, process.env),
env: { ...process.env },
})
);

Expand Down Expand Up @@ -269,7 +267,7 @@ export async function getCurrentBranchName(path: string, repo: string): Promise<
const [status, stdout, stderr] = await resolveSpawnOutput(
cp.spawn(path, ["branch", "--show-current"], {
cwd: repo,
env: Object.assign({}, process.env),
env: { ...process.env },
})
);

Expand Down
5 changes: 3 additions & 2 deletions packages/vscode/src/webview-loader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from "path";

import * as vscode from "vscode";

import { getPrimaryColor, setPrimaryColor } from "./setting-repository";
Expand Down Expand Up @@ -39,8 +40,8 @@ export default class WebviewLoader implements vscode.Disposable {
context.workspaceState.update(`${ANALYZE_DATA_KEY}_${baseBranchName}`, analyzedData);

const resMessage = {
command,
payload: analyzedData,
command,
payload: analyzedData,
};

await this.respondToMessage(resMessage);
Expand Down

0 comments on commit 01793b1

Please sign in to comment.