-
-
Save vilmibm/cf889b52622a6d912abff948fe4812d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Commit struct { | |
Sha string | |
Title string | |
Body string | |
} | |
func Commits(baseRef, headRef string) ([]*Commit, error) { | |
logCmd := GitCommand( | |
"log", "--pretty=format:%h,%s,\"%b\"", | |
fmt.Sprintf("%s..%s", baseRef, headRef)) | |
output, err := utils.PrepareCmd(logCmd).Output() | |
if err != nil { | |
return []*Commit{}, err | |
} | |
r := csv.NewReader(bytes.NewReader(output)) | |
commits := []*Commit{} | |
sha := 0 | |
title := 1 | |
body := 2 | |
for { | |
record, err := r.Read() | |
if err == io.EOF { | |
break | |
} | |
if err != nil { | |
os.Stderr.WriteString( | |
fmt.Sprintf("skipping unparseable commit. error: %v\n", err.Error())) | |
continue | |
} | |
commits = append(commits, &Commit{ | |
Sha: record[sha], | |
Title: record[title], | |
Body: record[body], | |
}) | |
} | |
return commits, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment