Skip to content

Commit

Permalink
style: format
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelCurrin committed Sep 1, 2021
1 parent db6f21c commit e0b100b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/autofill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export async function makeAndFillCommitMsg(repository: Repository) {
const newMsg = generateMsg(fileChanges, oldMsg);
console.debug("New message: ", newMsg);

const commitMessageValue = await getCommitTemplateValue()
console.debug({ commitMessageValue })
const commitMessageValue = await getCommitTemplateValue();
console.debug({ commitMessageValue });

setCommitMsg(repository, newMsg);
}
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ export function activate(context: vscode.ExtensionContext) {
}

// eslint-disable-next-line @typescript-eslint/no-empty-function
export function deactivate() { }
export function deactivate() {}
14 changes: 7 additions & 7 deletions src/git/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ const exec = util.promisify(childProcess.exec);
/**
* Run a `git` subcommand with options and return output.
*/
export function execute(cwd: string, subcommand: string, options: string[] = []) {
export function execute(
cwd: string,
subcommand: string,
options: string[] = []
) {
const command = `git ${subcommand} ${options.join(" ")}`;

const result = exec(command, { cwd });
Expand Down Expand Up @@ -45,12 +49,8 @@ async function _diffIndex(options: string[] = []): Promise<Array<string>> {
"HEAD",
];

const workspace = getWorkspaceFolder()
const { stdout, stderr } = await execute(
workspace,
cmd,
fullOptions
);
const workspace = getWorkspaceFolder();
const { stdout, stderr } = await execute(workspace, cmd, fullOptions);

if (stderr) {
console.debug(`stderr for 'git ${cmd}' command:`, stderr);
Expand Down
44 changes: 22 additions & 22 deletions src/git/commitTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
*
* To avoid making an extra config value for the extension that one has to manage say in a Settings file or internal data, the approach is rather to use the existing commit template pattern in Git.
*/
import * as fs from 'fs';
import * as path from 'path';
import * as fs from "fs";
import * as path from "path";
import { getWorkspaceFolder } from "../workspace";
import { execute } from "./cli";

const CONFIG_SUBCOMMAND = "config"
const COMMIT_TEMPLATE_IDENTIFIER = 'commit.template'
const CONFIG_SUBCOMMAND = "config";
const COMMIT_TEMPLATE_IDENTIFIER = "commit.template";

/**
* Get a value from the Git config.
*
* The CLI will assume local (project) project by default.
*/
export async function _getConfigValue(options: string[]) {
const workspace = getWorkspaceFolder()
const workspace = getWorkspaceFolder();
const { stdout, stderr } = await execute(
workspace,
CONFIG_SUBCOMMAND,
Expand All @@ -36,7 +36,7 @@ export async function _getConfigValue(options: string[]) {
console.debug(`stderr for 'git ${CONFIG_SUBCOMMAND}' command:`, stderr);
}

return stdout
return stdout;
}

/**
Expand All @@ -46,10 +46,10 @@ export async function _getConfigValue(options: string[]) {
*/
async function _getCommitTemplatePath() {
try {
const options = [COMMIT_TEMPLATE_IDENTIFIER]
return await _getConfigValue(options)
const options = [COMMIT_TEMPLATE_IDENTIFIER];
return await _getConfigValue(options);
} catch (_e) {
return null
return null;
}
}

Expand All @@ -59,26 +59,26 @@ async function _getCommitTemplatePath() {
* NB. Use current workspace as the base path.
*/
function _readFile(filePath: string) {
const workspace = getWorkspaceFolder()
const p = path.join(workspace, filePath)
const workspace = getWorkspaceFolder();
const p = path.join(workspace, filePath);

let value
let value;

try {
value = fs.readFileSync(p, "utf-8")
value = fs.readFileSync(p, "utf-8");
} catch (err) {
console.error(`Could not find template file: ${p}. ${err.toString()}`)
console.error(`Could not find template file: ${p}. ${err.toString()}`);

return null
return null;
}

if (!value) {
return null
return null;
}

console.debug(`Read ${p} and found: ${value}`)
console.debug(`Read ${p} and found: ${value}`);

return value
return value;
}

/**
Expand All @@ -87,12 +87,12 @@ function _readFile(filePath: string) {
* Return null if file is not configured or file is missing, without aborting.
*/
export async function getCommitTemplateValue() {
const filePath = await _getCommitTemplatePath()
const filePath = await _getCommitTemplatePath();

if (!filePath) {
console.error(`Could not read missing file: ${filePath}`)
return null
console.error(`Could not read missing file: ${filePath}`);
return null;
}

return _readFile(filePath)
return _readFile(filePath);
}
4 changes: 2 additions & 2 deletions src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { workspace } from "vscode";

export function getWorkspaceFolder(): string {
const { workspaceFolders } = workspace;
console.log({ workspaceFolders })
console.log({ workspaceFolders });

return workspaceFolders ? workspaceFolders[0].uri.fsPath : "";
};
}

0 comments on commit e0b100b

Please sign in to comment.