Skip to content

Commit 26bfcb4

Browse files
committed
🔧 chore(project): upgrade Go to 1.24, add tidy target, update docs
Signed-off-by: samzong <samzong.lu@gmail.com>
1 parent aa79d68 commit 26bfcb4

12 files changed

Lines changed: 121 additions & 101 deletions

File tree

‎.github/workflows/pr-review.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Set up Go
2222
uses: actions/setup-go@v5
2323
with:
24-
go-version: '1.21'
24+
go-version: '1.24.x'
2525
cache: true
2626

2727
- name: Format check
@@ -39,4 +39,4 @@ jobs:
3939
uses: actions/upload-artifact@v4
4040
with:
4141
name: gmc
42-
path: bin/gmc
42+
path: bin/gmc

‎.github/workflows/release.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Set up Go
3535
uses: actions/setup-go@v4
3636
with:
37-
go-version: ">=1.21.0"
37+
go-version: "1.24.x"
3838
cache: true
3939

4040
- name: Install git-chglog

‎Makefile‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,17 @@ test-coverage-ci: ## Run tests with coverage for CI (no HTML)
5959
@go tool cover -func=$(BUILD_DIR)/coverage.out | tail -1
6060

6161
.PHONY: fmt
62-
fmt: ## Format code and tidy modules
62+
fmt: ## Format code
6363
@echo "Formatting code..."
6464
@go fmt ./...
65-
@go mod tidy
6665
@echo "Format Command Done"
6766

67+
.PHONY: tidy
68+
tidy: ## Tidy go.mod and go.sum
69+
@echo "Tidying modules..."
70+
@go mod tidy
71+
@echo "Tidy Command Done"
72+
6873
.PHONY: lint
6974
lint: ## Run code analysis
7075
@echo "$(BLUE)Running code analysis...$(NC)"

‎README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
### Quick start (required config)
2727

28-
`gmc` reads configuration from `~/.gmc.yaml` by default (override with `--config`). On macOS/Linux, the config file is forced to permission `0600`. You can also place a `.gmc.yaml` in your project directory to override global settings on a per-repo basis.
28+
`gmc` reads configuration from `~/.config/gmc/config.yaml` by default (override with `--config`). If a legacy `~/.gmc.yaml` exists, it is used as a fallback. On macOS/Linux, the config file is forced to permission `0600`. You can also place a `.gmc.yaml` in your project directory to override global settings on a per-repo basis.
2929

3030
Recommended: run the guided setup (or accept the prompt shown on first use):
3131

@@ -175,6 +175,10 @@ fpath=(~/.zsh/completions $fpath)
175175
autoload -Uz compinit && compinit
176176
```
177177

178+
### Man pages
179+
180+
Man pages under `docs/man/` are generated via `make man` (from `cmd/gendoc/main.go`). Do not edit them manually.
181+
178182
## Prompt templates
179183

180184
`gmc` supports a single prompt template override. If `prompt_template` is empty or set to `default`, the built-in template is used.

‎action.yml‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ inputs:
2525
prompt_template:
2626
description: "Prompt template name (in prompts_dir)"
2727
required: false
28-
prompts_dir:
29-
description: "Directory containing prompt templates"
30-
required: false
3128
working-directory:
3229
description: "Working directory to run commands in"
3330
required: false
@@ -51,7 +48,7 @@ runs:
5148
- name: Set up Go
5249
uses: actions/setup-go@v5
5350
with:
54-
go-version: '1.21'
51+
go-version: '1.24.x'
5552

5653
- name: Build gmc
5754
shell: bash
@@ -71,7 +68,6 @@ runs:
7168
if [ -n "${{ inputs.model }}" ]; then ./gmc config set model "${{ inputs.model }}"; fi
7269
if [ -n "${{ inputs.role }}" ]; then ./gmc config set role "${{ inputs.role }}"; fi
7370
if [ -n "${{ inputs.prompt_template }}" ]; then ./gmc config set prompt_template "${{ inputs.prompt_template }}"; fi
74-
if [ -n "${{ inputs.prompts_dir }}" ]; then ./gmc config set prompts_dir "${{ inputs.prompts_dir }}"; fi
7571
7672
- name: Run GMC
7773
id: run

‎cmd/root.go‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"errors"
66
"fmt"
7+
"io"
78
"os"
89
"os/exec"
910
"strings"
@@ -15,6 +16,7 @@ import (
1516
"github.com/samzong/gmc/internal/formatter"
1617
"github.com/samzong/gmc/internal/git"
1718
"github.com/samzong/gmc/internal/llm"
19+
"github.com/samzong/gmc/internal/stringsutil"
1820
"github.com/samzong/gmc/internal/ui"
1921
"github.com/spf13/cobra"
2022
)
@@ -227,15 +229,13 @@ func handleStdinDiff() error {
227229
// Extract file names from diff
228230
changedFiles := extractFilesFromDiff(diff)
229231

230-
cfg := config.GetConfig()
231-
proceed, err := ensureLLMConfigured(cfg, os.Stdin, os.Stderr, runInitWizard)
232+
cfg, proceed, err := ensureConfiguredAndGetConfig(config.GetConfig(), os.Stdin, os.Stderr, runInitWizard)
232233
if err != nil {
233234
return err
234235
}
235236
if !proceed {
236237
return nil
237238
}
238-
cfg = config.GetConfig()
239239

240240
// Generate commit message
241241
message, err := generateCommitMessage(cfg, changedFiles, diff, userPrompt)
@@ -249,41 +249,44 @@ func handleStdinDiff() error {
249249
return nil
250250
}
251251

252+
func ensureConfiguredAndGetConfig(
253+
cfg *config.Config,
254+
in io.Reader,
255+
out io.Writer,
256+
initRunner func(io.Reader, io.Writer, *config.Config) error,
257+
) (*config.Config, bool, error) {
258+
proceed, err := ensureLLMConfigured(cfg, in, out, initRunner)
259+
if err != nil || !proceed {
260+
return nil, proceed, err
261+
}
262+
return config.GetConfig(), true, nil
263+
}
264+
252265
// extractFilesFromDiff parses file names from unified diff format
253266
func extractFilesFromDiff(diff string) []string {
254267
var files []string
255-
seen := make(map[string]bool)
256268

257269
for _, line := range strings.Split(diff, "\n") {
258270
if strings.HasPrefix(line, "+++ b/") {
259271
file := strings.TrimPrefix(line, "+++ b/")
260-
if !seen[file] {
261-
files = append(files, file)
262-
seen[file] = true
263-
}
272+
files = append(files, file)
264273
} else if strings.HasPrefix(line, "--- a/") {
265274
file := strings.TrimPrefix(line, "--- a/")
266-
if !seen[file] {
267-
files = append(files, file)
268-
seen[file] = true
269-
}
275+
files = append(files, file)
270276
}
271277
}
272278

273-
return files
279+
return stringsutil.UniqueStrings(files)
274280
}
275281

276282
func handleCommitFlow(diff string, changedFiles []string) error {
277-
cfg := config.GetConfig()
278-
279-
proceed, err := ensureLLMConfigured(cfg, os.Stdin, os.Stderr, runInitWizard)
283+
cfg, proceed, err := ensureConfiguredAndGetConfig(config.GetConfig(), os.Stdin, os.Stderr, runInitWizard)
280284
if err != nil {
281285
return err
282286
}
283287
if !proceed {
284288
return nil
285289
}
286-
cfg = config.GetConfig()
287290

288291
return runCommitFlow(cfg, changedFiles, diff, performCommit)
289292
}
@@ -493,16 +496,13 @@ func commitStagedFiles(files []string) error {
493496
}
494497

495498
func handleSelectiveCommitFlow(diff string, files []string) error {
496-
cfg := config.GetConfig()
497-
498-
proceed, err := ensureLLMConfigured(cfg, os.Stdin, os.Stderr, runInitWizard)
499+
cfg, proceed, err := ensureConfiguredAndGetConfig(config.GetConfig(), os.Stdin, os.Stderr, runInitWizard)
499500
if err != nil {
500501
return err
501502
}
502503
if !proceed {
503504
return nil
504505
}
505-
cfg = config.GetConfig()
506506

507507
return runCommitFlow(cfg, files, diff, func(message string) error {
508508
return performSelectiveCommit(message, files)

‎internal/emoji/emoji.go‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"regexp"
66
"sort"
77
"strings"
8+
"sync"
89
)
910

1011
// emojiMap maps commit types to their corresponding emojis
@@ -31,6 +32,11 @@ var emojiMap = map[string]string{
3132
// Pre-compiled regex pattern for extracting commit type
3233
var commitTypeRegex = regexp.MustCompile(`^([a-zA-Z]+)(?:\([^)]+\))?:`)
3334

35+
var (
36+
commitTypesOnce sync.Once
37+
cachedCommitTypes []string
38+
)
39+
3440
// GetEmojiForType returns the emoji for a given commit type.
3541
// Returns empty string if type is not recognized.
3642
func GetEmojiForType(commitType string) string {
@@ -42,12 +48,15 @@ func GetEmojiForType(commitType string) string {
4248

4349
// GetAllCommitTypes returns all supported commit types in alphabetical order.
4450
func GetAllCommitTypes() []string {
45-
types := make([]string, 0, len(emojiMap))
46-
for t := range emojiMap {
47-
types = append(types, t)
48-
}
49-
sort.Strings(types)
50-
return types
51+
commitTypesOnce.Do(func() {
52+
types := make([]string, 0, len(emojiMap))
53+
for t := range emojiMap {
54+
types = append(types, t)
55+
}
56+
sort.Strings(types)
57+
cachedCommitTypes = types
58+
})
59+
return append([]string(nil), cachedCommitTypes...)
5160
}
5261

5362
// GetEmojiDescription returns a formatted string listing all commit types with their emojis.

0 commit comments

Comments
 (0)