8000 feat(init): add main package and command execution by jsburckhardt · Pull Request #5 · jsburckhardt/gic · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(init): add main package and command execution #5

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 5 commits into from
Aug 29, 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
31 changes: 30 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"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"
// }
Expand Down Expand Up @@ -44,6 +44,35 @@
"files.insertFinalNewline": true,
"github.copilot.enable": {
"markdown": true
},
"go.toolsManagement.checkForUpdates": "local",
"go.useLanguageServer": true,
"go.gopath": "/go",
"go.lintTool": "revive",
"go.goroot": "/usr/local/go",
"go.lintFlags": [
"--fast"
],
"[go]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "always"
},
// Optional: Disable snippets, as they conflict with completion ranking.
"editor.snippetSuggestions": "none"
},
"[go.mod]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "always"
}
},
"gopls": {
// Add parameter placeholders when completing a function.
"usePlaceholders": true,
// If true, enable additional analyses with staticcheck.
// Warning: This will significantly increase memory usage.
"staticcheck": false
}
}
}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout Code
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@
# project
.env
.gic
gic

dist/
7 changes: 6 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ linters-settings:

revive:
enable-all-rules: true
rules:
- name: "line-length-limit"
arguments:
- 120

staticcheck:
checks: ["all"]
Expand Down Expand Up @@ -45,6 +49,7 @@ issues:
linters:
enable:
- govet
- revive
- errcheck
- staticcheck
- gocyclo
Expand All @@ -55,5 +60,5 @@ linters:

output:
formats:
- format: colored-line-number
- format: colored-tab
sort-results: true
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ before:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
# - go generate ./...

builds:
- env:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "cmd/gic/main.go",
"program": "main.go",
"cwd": "/workspaces/gic"
}
]
Expand Down
54 changes: 0 additions & 54 deletions cmd/gic/main.go

This file was deleted.

78 changes: 78 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Package cmd provides the command-line interface for the gic application.
package cmd

import (
"fmt"

"gic/internal/config"
"gic/internal/git"
"gic/internal/llm"

"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.",
}
)

// Execute runs the root command of the application.
func Execute(version, commit string) error {
rootCmd.Version = version
hash = commit

setVersion()

rootCmd = &cobra.Command{
Use: "gic",
Short: "gic generates git commit messages based on staged changes.",
RunE: func(cmd *cobra.Command, args []string) error {
_ = cmd
_ = args
cfg, err := config.LoadConfig()
if err != nil {
return err
}

gitDiff, err := git.GetStagedChanges()
if err != nil {
return err
}

// retrieve the commit message
commitMessage, err := llm.GenerateCommitMessage(cfg, gitDiff)
if err != nil {
return err
}

_, _ = fmt.Println("Suggested Commit Message:", commitMessage)
return nil
},
}

// Execute the root command
if err := rootCmd.Execute(); err != nil {
// log.Fatal(err)
return err
// os.Exit(exitCodeFailure)
}
return nil
}

func setVersion() {
template := fmt.Sprintf("gic version: %s commit: %s \n", rootCmd.Version, hash)
rootCmd.SetVersionTemplate(template)
}

func init() {
cobra.OnInitialize()
rootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "set logging level to verbose")
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/jsburckhardt/gic
module gic

go 1.23.0

Expand All @@ -7,6 +7,7 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.14.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0
github.com/joho/godotenv v1.5.1
github.com/jsburckhardt/gic v1.0.0
github.com/openai/openai-go v0.1.0-alpha.9
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfG E237 MeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/jsburckhardt/gic v1.0.0 h1:0cV5NiWUJtjVNl3YEYT3ipBUKEDl/5/3x5MnLUIZs8w=
github.com/jsburckhardt/gic v1.0.0/go.mod h1:jM3MILCAIdDF4uftsIBDGEHFepFXKLrjYEFFlY96+Ts=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down
14 changes: 11 additions & 3 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
// Package cli provides a command-line interface for the application.
package cli

import (
"log"
"os"

"github.com/joho/godotenv"
)

func LoadEnv() {
// LoadEnv loads environment variables from a .env file.
// It attempts to load the .env file located in the current working directory.
// If the file is not found or there is an error loading the file,
// it will cause a fatal error.
func LoadEnv() error {
err := godotenv.Load(".env")
if err != nil {
log.Fatal("Error loading .env file")
return err
}
return nil
}

// GetAPIKey returns the API key from the environment variables.
func GetAPIKey() string {
return os.Getenv("API_KEY")
}

// GetAzureOpenAIEndpoint returns the Azure OpenAI endpoint
// from the environment variables.
func GetAzureOpenAIEndpoint() string {
return os.Getenv("AZURE_OPENAI_ENDPOINT")
}
Loading
Loading
0