Skip to content

Commit

Permalink
feat(CoAuthor): Initial functionality for the CoAuthor adding
Browse files Browse the repository at this point in the history
refs: #1
  • Loading branch information
HRemonen committed Sep 7, 2023
1 parent 1cbb59a commit be35b66
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Binary file modified commitsense
Binary file not shown.
27 changes: 17 additions & 10 deletions pkg/author/author.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,34 @@ package author
import (
"fmt"
"os/exec"
"regexp"
"strings"
)

func extractNameAndEmail(line string) []string {
pattern := `(\w[\w\s]+)\s+<([^>]+)>`
re := regexp.MustCompile(pattern)
return re.FindStringSubmatch(line)
}

func GetSuggestedCoAuthors() ([]string, error) {
// Use the `git rev-list` command to obtain a list of authors who have made commits in the Git repository.
cmd := exec.Command("git", "log", "--format='%aN <%aE>'", "--all", "--no-merges", "|", "sort", "--unique")
revlist := "git log --pretty='%an <%ae>' | sort -u"
cmd := exec.Command("bash", "-c", revlist)
output, err := cmd.CombinedOutput()

if err != nil {
return nil, err
}

authorString := strings.TrimSpace(string(output))

strings.Replace(authorString, `\n`, "\n", -1)

// Parse the output to extract author names and email addresses.
lines := strings.Split(string(output), "\n")

fmt.Println(lines)
var suggestedCoAuthors []string
for _, line := range lines {
if strings.HasPrefix(line, "'") && strings.HasSuffix(line, "'") {
suggestedCoAuthors = append(suggestedCoAuthors, strings.Trim(line, "'"))
}
}
suggestedCoAuthors := strings.Split(authorString, "\n")

fmt.Println("suggested authors", suggestedCoAuthors)

return suggestedCoAuthors, nil
}

0 comments on commit be35b66

Please sign in to comment.