1
0
Fork 0
This repository has been archived on 2023-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
git-acknowledge/main.go

54 lines
1.0 KiB
Go

package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/AlecAivazis/survey/v2"
)
func CheckIfError(err error) {
if err != nil {
log.Fatal("Fail")
os.Exit(1)
}
}
func main() {
repo, err := git.PlainOpen(".")
CheckIfError(err)
cIter, err := repo.Log(&git.LogOptions{})
CheckIfError(err)
contributersMap := map[string]bool{}
contributers := []string{}
err = cIter.ForEach(func(c *object.Commit) error {
line := fmt.Sprintf("%s <%s>", c.Author.Name, c.Author.Email)
if !contributersMap[line] {
contributersMap[line] = true
contributers = append(contributers, line)
}
return nil
})
CheckIfError(err)
prompt := &survey.Select{
Message: "Which contributer:",
Options: contributers,
Filter: func(filterValue string, optValue string, optIndex int) bool {
return strings.Contains(optValue, filterValue)
},
}
contributer := ""
// or define a default for all of the questions
survey.AskOne(prompt, &contributer)
}