Skip to content

Commit 546860a

Browse files
feat: add auto tag and list commits functionality
1 parent e038d1f commit 546860a

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

..HEAD

Whitespace-only changes.

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,19 @@ When use `-a` flag, ai-commit will auto stage all changes then commit with gener
6464
ai-commit -a
6565
```
6666

67-
## Tip
67+
### Auto tag
6868

69-
It's recommended to make multiple small commits, commit more often.
69+
When use `-t` flag, ai-commit will ba
70+
71+
```bash
72+
ai-commit -t
73+
```
7074

7175
## Todo
7276

7377
- [ ] Auto split changes in to multiple commits.
7478
- [x] Detect commit type.
75-
- [ ] Auto tags?
79+
- [x] Auto tags?
7680

7781
## License
7882

main.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ func main() {
147147
currentTag = "v0.0.0"
148148
}
149149

150-
nextTag, err := getNextTag(client, commitMessage, currentTag)
150+
commits, err := listCommits(currentTag)
151+
errGuard(client, err)
152+
153+
nextTag, err := getNextTag(client, commits, currentTag)
151154
errGuard(client, err)
152155

153156
if err := tag(nextTag); err != nil {
@@ -222,6 +225,23 @@ func gitAdd() error {
222225
)
223226
}
224227

228+
// git log v1.1.3..HEAD --oneline
229+
func listCommits(lastTag string) (string, error) {
230+
workingDir, err := os.Getwd()
231+
if err != nil {
232+
return "", err
233+
}
234+
235+
cmd := exec.Command("git", "log", lastTag+"..HEAD", "--oneline")
236+
cmd.Dir = workingDir
237+
out, err := cmd.Output()
238+
if err != nil {
239+
return "", err
240+
}
241+
242+
return strings.TrimSpace(string(out)), nil
243+
}
244+
225245
func askForAutoStage(apiClient *GptClient) (bool, error) {
226246
question := "Your working tree is dirty, do you want me to stage the changes first?"
227247
userResponse, err := readUserInput(question)

0 commit comments

Comments
 (0)