8000 Feat/add installation script by jsburckhardt · Pull Request #11 · jsburckhardt/gic · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
< 8000 div id="files_bucket" class="files-bucket files-next-bucket clearfix pull-request-tab-content is-visible js-multi-line-comments-enabled">

Feat/add installation script #11

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

Merged
merged 6 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
"installOhMyZsh": true,
"installOhMyZshConfig": true
},
"ghcr.io/stuartleeks/dev-container-features/shell-history:0": {},
"ghcr.io/devcontainers/features/azure-cli:1": {
"installBicep": true
},
// "ghcr.io/prulloac/devcontainer-features/ollama:1": {
// "pull": "phi3.5"
// }
"ghcr.io/stuartleeks/dev-container-features/azure-cli-persistence:0": {},
"ghcr.io/stuartleeks/dev-container-features/shell-history:0": {}

},
"waitFor": "onCreateCommand",
// "updateContentCommand": "python3 -m pip install -r requirements.txt",
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | sudo tee /etc/apt/sources.list.d/goreleaser.list
sudo apt update
sudo apt install goreleaser
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
- name: Semantic Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
9 changes: 4 additions & 5 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ builds:
goos:
- linux
- darwin
- windows
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}}

sboms:
- artifacts: archive
Expand All @@ -41,8 +44,4 @@ archives:
format: zip

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
use: github-native
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GIt-Commit (gic)

A tool that helps developers generate git commit messages based on the `git diff` of staged files, following specified instructions. It's ideal for use alongside [Semantic Release](https://github.com/semantic-release/semantic-release).
Reducing cognitive load by automating commit message generation, allowing developers to focus on coding instead of crafting messages. A tool that helps developers generate git commit messages based on the `git diff` of staged files, following instructions. It's ideal for use alongside [Semantic Release](https://github.com/semantic-release/semantic-release).

## AzureAD

Expand Down
22 changes: 9 additions & 13 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,27 @@ import (
"github.com/spf13/cobra"
)

// const exitCodeFailure = 1

var (
hash string
verbose bool

rootCmd = &cobra.Command{
Use: "gic",
Short: "gic",
Long: "gic generates git commit messages based on staged changes.",
PersistentPreRun: func(_ *cobra.Command, _ []string) {
PersistentPreRunE: func(_ *cobra.Command, args []string) error {
// Set logger level based on the verbose flag
if verbose {
logger.SetLogLevel("debug")
} else {
logger.SetLogLevel("info")
}

// Check for non-flag arguments
if len(args) > 0 {
return fmt.Errorf("unexpected arguments: %v", args)
}

return nil
},
}
)
Expand All @@ -37,17 +41,12 @@ var (
func Execute(version, commit string) error {
rootCmd.Version = version
hash = commit

setVersion()

rootCmd.RunE = executeCmd

return rootCmd.Execute()
}

func executeCmd(_ *cobra.Command, _ []string) error {
// _ = cmd
// _ = args
l := logger.GetLogger()
l.Debug("Started executing command")
l.Debug("Start loading configuration")
Expand All @@ -56,27 +55,24 @@ func executeCmd(_ *cobra.Command, _ []string) error {
return err
}
l.Debug("Finish loading configuration")

l.Debug("Start getting staged changes")
gitDiff, err := git.GetStagedChanges()
if err != nil {
return err
}
l.Debug("Finish getting staged changes")

l.Debug("Start generating commit message")
commitMessage, err := llm.GenerateCommitMessage(cfg, gitDiff)
if err != nil {
return err
}
l.Debug("Finish generating commit message")

l.Debug("Start validating commit message includes changes")
if commitMessage == "### NO STAGED CHAGES ###" {
return nil
}
l.Info("commit message: " + commitMessage)
l.Debug("Finish validating commit message includes changes")

return git.Commit(commitMessage, cfg)
}

Expand Down
7 changes: 5 additions & 2 deletions internal/llm/llm.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func GenerateCommitMessage(cfg config.Config, diff string) (string, error) {
case "azure":
return GenerateCommitMessageAzure(apikey, cfg, diff)
case "azure_ad":
return GenerateCommitMessageAzureAD(cfg, diff)
return GenerateCommitMessageAzureAD(cfg, diff, l)
case "openai":
return GenerateCommitMessageOpenAI(apikey, cfg, diff)
case "ollama":
Expand Down Expand Up @@ -109,9 +109,12 @@ func GenerateCommitMessageAzure(apikey string, cfg config.Config, diff string) (
// authentication.
// It takes a config.Config object and a string representing
// the diff as input.
func GenerateCommitMessageAzureAD(cfg config.Config, diff string) (string, error) {
func GenerateCommitMessageAzureAD(cfg config.Config, diff string, l *logger.Logger) (string, error) {
l.Debug("GenerateCommitMessageAzureAD")
l.Debug("obtaining token credential")
tokenCredential, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
l.Error("failed getting token", "error", err)
return emptyString, err
}
client, err := azopenai.NewClient(cfg.AzureEndpoint, tokenCredential, nil)
Expand Down
63 changes: 63 additions & 0 deletions script/install-gic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

# Variables
REPO_OWNER="jsburckhardt"
REPO_NAME="gic"
BINARY_NAME="gic"

# Function to get the latest version from GitHub API
get_latest_version() {
LATEST_URL="https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/releases/latest"
curl -s "$LATEST_URL" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'
}

# Check if a version is passed as an argument
if [ -z "$1" ]; then
# No version provided, get the latest version
VERSION=$(get_latest_version)
echo "No version provided, installing the latest version: $VERSION"
else
VERSION=$1
echo "Installing specified version: $VERSION"
fi

# Determine the OS and architecture following the naming template
OS=$(uname | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)

if [ "$ARCH" == "x86_64" ]; then
ARCH="x86_64"
elif [ "$ARCH" == "i686" ]; then
ARCH="i386"
elif [ "$ARCH" == "armv7l" ]; then
ARCH="armv7"
elif [ "$ARCH" == "aarch64" ]; then
ARCH="arm64"
fi

# Construct the download URL to match the naming template
DOWNLOAD_URL="https://github.com/$REPO_OWNER/$REPO_NAME/releases/download/$VERSION/${REPO_NAME}_$(echo "$OS" | sed 's/.*/\u&/')_$ARCH.tar.gz"

# Create a temporary directory for the download
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR" || exit

# Download the binary tarball
echo "Downloading $BINARY_NAME from $DOWNLOAD_URL"
curl -LO "$DOWNLOAD_URL"

# Extract the tarball
echo "Extracting the tarball"
tar -xzf "${REPO_NAME}_$(echo "$OS" | sed 's/.*/\u&/')_$ARCH.tar.gz"

# Move the binary to /usr/local/bin
echo "Installing $BINARY_NAME"
sudo mv $BINARY_NAME /usr/local/bin/

# Cleanup
cd - || exit
rm -rf "$TMP_DIR"

# Verify installation
echo "Verifying installation"
$BINARY_NAME --version
0