mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
refactor Author type
This commit is contained in:
@@ -2,6 +2,7 @@ package commits
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
git "github.com/go-git/go-git/v5"
|
git "github.com/go-git/go-git/v5"
|
||||||
@@ -10,6 +11,43 @@ import (
|
|||||||
"github.com/taigrr/gico/types"
|
"github.com/taigrr/gico/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (paths RepoSet) GetRepoAuthors() ([]string, error) {
|
||||||
|
outChan := make(chan types.Commit, 10)
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
for _, p := range paths {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(path string) {
|
||||||
|
defer wg.Done()
|
||||||
|
repo, err := OpenRepo(path)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cc, err := repo.GetCommitChan()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for c := range cc {
|
||||||
|
outChan <- c
|
||||||
|
}
|
||||||
|
}(p)
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
wg.Wait()
|
||||||
|
close(outChan)
|
||||||
|
}()
|
||||||
|
authors := make(map[string]bool)
|
||||||
|
for commit := range outChan {
|
||||||
|
authors[commit.Author.Email] = true
|
||||||
|
authors[commit.Author.Name] = true
|
||||||
|
}
|
||||||
|
a := []string{}
|
||||||
|
for k := range authors {
|
||||||
|
a = append(a, k)
|
||||||
|
}
|
||||||
|
sort.Strings(a)
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (paths RepoSet) GetRepoCommits(year int, authors []string) ([][]types.Commit, error) {
|
func (paths RepoSet) GetRepoCommits(year int, authors []string) ([][]types.Commit, error) {
|
||||||
yearLength := 365
|
yearLength := 365
|
||||||
if year%4 == 0 {
|
if year%4 == 0 {
|
||||||
@@ -132,7 +170,10 @@ func (repo Repo) GetCommitChan() (chan types.Commit, error) {
|
|||||||
cIter.ForEach(func(c *object.Commit) error {
|
cIter.ForEach(func(c *object.Commit) error {
|
||||||
ts := c.Author.When
|
ts := c.Author.When
|
||||||
commit := types.Commit{
|
commit := types.Commit{
|
||||||
Author: c.Author.Name,
|
Author: types.Author{
|
||||||
|
Name: c.Author.Name,
|
||||||
|
Email: c.Author.Email,
|
||||||
|
},
|
||||||
Message: c.Message, TimeStamp: ts,
|
Message: c.Message, TimeStamp: ts,
|
||||||
Hash: c.Hash.String(), Repo: repo.Path,
|
Hash: c.Hash.String(), Repo: repo.Path,
|
||||||
FilesChanged: 0, Added: 0, Deleted: 0,
|
FilesChanged: 0, Added: 0, Deleted: 0,
|
||||||
@@ -197,7 +238,7 @@ func FilterCChanByAuthor(in chan types.Commit, authors []string) (chan types.Com
|
|||||||
for commit := range in {
|
for commit := range in {
|
||||||
regset:
|
regset:
|
||||||
for _, r := range regSet {
|
for _, r := range regSet {
|
||||||
if r.MatchString(commit.Author) {
|
if r.MatchString(commit.Author.Email) || r.MatchString(commit.Author.Name) {
|
||||||
out <- commit
|
out <- commit
|
||||||
break regset
|
break regset
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,10 @@ func (repo Repo) GetCommitSet() (CommitSet, error) {
|
|||||||
cIter.ForEach(func(c *object.Commit) error {
|
cIter.ForEach(func(c *object.Commit) error {
|
||||||
ts := c.Author.When
|
ts := c.Author.When
|
||||||
commit := types.Commit{
|
commit := types.Commit{
|
||||||
Author: c.Author.Name,
|
Author: types.Author{
|
||||||
|
Name: c.Author.Name,
|
||||||
|
Email: c.Author.Email,
|
||||||
|
},
|
||||||
Message: c.Message, TimeStamp: ts,
|
Message: c.Message, TimeStamp: ts,
|
||||||
Hash: c.Hash.String(), Repo: repo.Path,
|
Hash: c.Hash.String(), Repo: repo.Path,
|
||||||
FilesChanged: 0, Added: 0, Deleted: 0,
|
FilesChanged: 0, Added: 0, Deleted: 0,
|
||||||
@@ -137,7 +140,7 @@ func (cs CommitSet) FilterByAuthorRegex(authors []string) (CommitSet, error) {
|
|||||||
for _, commit := range cs.Commits {
|
for _, commit := range cs.Commits {
|
||||||
regset:
|
regset:
|
||||||
for _, r := range regSet {
|
for _, r := range regSet {
|
||||||
if r.MatchString(commit.Author) {
|
if r.MatchString(commit.Author.Name) || r.MatchString(commit.Author.Email) {
|
||||||
newCS.Commits = append(newCS.Commits, commit)
|
newCS.Commits = append(newCS.Commits, commit)
|
||||||
break regset
|
break regset
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ func NewDataSet() DataSet {
|
|||||||
return make(DataSet)
|
return make(DataSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCommit(Author, Message, Repo, Path string, Added, Deleted, FilesChanged int) Commit {
|
func NewCommit(AuthorName, AuthorEmail, Message, Repo, Path string, Added, Deleted, FilesChanged int) Commit {
|
||||||
ci := Commit{
|
ci := Commit{
|
||||||
Message: Message, Added: Added, Deleted: Deleted,
|
Message: Message, Added: Added, Deleted: Deleted,
|
||||||
Author: Author, FilesChanged: FilesChanged, TimeStamp: time.Now(),
|
Author: Author{Name: AuthorName, Email: AuthorEmail}, FilesChanged: FilesChanged, TimeStamp: time.Now(),
|
||||||
Repo: Repo, Path: Path,
|
Repo: Repo, Path: Path,
|
||||||
}
|
}
|
||||||
return ci
|
return ci
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ import (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
Month string
|
Month string
|
||||||
|
Author struct {
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
Email string `json:"email,omitempty"`
|
||||||
|
}
|
||||||
Commit struct {
|
Commit struct {
|
||||||
Deleted int `json:"deleted,omitempty"`
|
Deleted int `json:"deleted,omitempty"`
|
||||||
Added int `json:"added,omitempty"`
|
Added int `json:"added,omitempty"`
|
||||||
@@ -15,7 +19,7 @@ type (
|
|||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
Hash string `json:"hash,omitempty"`
|
Hash string `json:"hash,omitempty"`
|
||||||
TimeStamp time.Time `json:"ts,omitempty"`
|
TimeStamp time.Time `json:"ts,omitempty"`
|
||||||
Author string `json:"author,omitempty"`
|
Author Author `json:"author,omitempty"`
|
||||||
Repo string `json:"repo,omitempty"`
|
Repo string `json:"repo,omitempty"`
|
||||||
Path string `json:"path,omitempty"`
|
Path string `json:"path,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user