Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement universal Git hooks integration #184

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

secret-point
Copy link

Changes

  • Implemented init, pre-commit, pre-push, and prepare-commit-message Git hooks within the new Deno module lib/universal/git-hooks.ts.
  • Migrated existing Bash-based .githooks/prepare-commit-message logic into the Deno module, enhancing cross-platform compatibility and maintainability.
  • Developed a Deno-based initialization process for Git hooks, facilitating the automatic setup of the .githooks directory and associated scripts.
  • Incorporated environment variable GITHOOK_BYPASS checks to offer developers an easy way to bypass hooks during development if needed.
    Usage
    To set up the Git hooks in your project, run:

deno run --allow-write=.githooks https://raw.githubusercontent.com/netspective-labs/sql-aide/vX.Y.Z/lib/universal/git-hooks.ts init
This command initializes the .githooks directory and configures the hooks to use our Deno-based scripts.

@@ -0,0 +1,108 @@

import { parse } from "https://deno.land/std/flags/mod.ts";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be sure to turn on Deno linting in VS Code, it will remind you that this is not a proper way to reference imports. You should use pinned versions.

@@ -0,0 +1,108 @@

import { parse } from "https://deno.land/std/flags/mod.ts";
import { Command } from "https://deno.land/x/cliffy/command/mod.ts";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be sure to turn on Deno linting in VS Code, it will remind you that this is not a proper way to reference imports. You should use pinned versions.


for (const [name, handler] of Object.entries(hooks)) {
const script = `#!/usr/bin/env -S deno run --allow-read --allow-write --allow-env
import { ${name} } from "https://raw.githubusercontent.com/netspective-labs/sql-aide/vX.Y.Z/lib/universal/git-hooks.ts";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vX.Y.Z will fail every time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means you gave me a PR without local testing. Please never do that again.

import { parse } from "https://deno.land/std/flags/mod.ts";
import { Command } from "https://deno.land/x/cliffy/command/mod.ts";

async function initHooks() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add default args like:

initHooks(gitHooksPath = path.join(Deno.cwd(), '.githooks') )

Include anything else that might be optional.

import { ${name} } from "https://raw.githubusercontent.com/netspective-labs/sql-aide/vX.Y.Z/lib/universal/git-hooks.ts";
await ${name}();`;

await Deno.writeTextFile(`${gitHooksDir}/${name}`, script, { mode: 0o755 });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Deno stdlib path module and path.join() not string concatenation for filename.

}

if (import.meta.main) {
await main();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why two if(import.meta.main) blocks?

await main();
}

if (import.meta.main) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why two if(import.meta.main) blocks?

Copy link
Contributor

@shah shah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, for true cross-platform utility use the dax module for calling shell scripts if something is not available in Deno.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants