Skip to content
Snippets Groups Projects
Commit 05c4a49b authored by Nick Thomas's avatar Nick Thomas
Browse files

Add types and interfaces for commits

parent f0a3b562
No related branches found
No related tags found
1 merge request!1Initial implementation of an elasticsearch indexer in Go
Loading
Loading
@@ -84,3 +84,7 @@ func NewClient(config *Config) (*Client, error) {
func (c *Client) Flush() error {
return c.bulk.Flush()
}
func (c *Client) IndexCommit(indexName string, commit interface{}) error {
return fmt.Errorf("TODO")
}
package indexer
import (
"fmt"
"srcd.works/go-git.v4/plumbing/object"
)
type Person struct {
Name string `json:"name"`
Email string `json:"email"`
Time string `json:"time"` // %Y%m%dT%H%M%S%z
}
type Commit struct {
Author *Person `json:"author"`
Committer *Person `json:"commiter"`
ID string `json:"id"` // ${RepoID}_${SHA}
RepoID string `json:"rid"`
Message string `json:"message"`
SHA string `json:"sha"`
}
func BuildPerson(p object.Signature) *Person {
return &Person{
Name: p.Name,
Email: p.Email,
//Time: // FIXME: work this out
}
}
func BuildCommit(c *object.Commit, repoID string) *Commit {
sha := c.Hash.String()
return &Commit{
Author: BuildPerson(c.Author),
Committer: BuildPerson(c.Committer),
ID: fmt.Sprintf("%s_%s", repoID, sha),
RepoID: repoID,
Message: c.Message,
SHA: sha,
}
}
Loading
Loading
@@ -10,19 +10,21 @@ import (
)
 
type Submitter interface {
IndexCommit(indexName string, commit interface{}) error
Flush() error
}
 
type Indexer struct {
IndexName string
ProjectID string
Repo *git.Repo
Submitter
}
 
func (i *Indexer) SubmitCommit(c *object.Commit) error {
log.Print("Commit: ", c.ID())
// TODO: touch Submitter
return nil
commit := BuildCommit(c, i.ProjectID)
return i.Submitter.IndexCommit(i.IndexName, commit)
}
 
func (i *Indexer) SubmitBlob(file *object.File) error {
Loading
Loading
Loading
Loading
@@ -35,6 +35,7 @@ func main() {
 
idx := &indexer.Indexer{
IndexName: "gitlab",
ProjectID: projectID,
Submitter: esClient,
Repo: repo,
}
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment