-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
87 lines (70 loc) · 1.93 KB
/
main.go
File metadata and controls
87 lines (70 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"fmt"
"html/template"
"os"
"os/exec"
"strings"
)
type commit struct {
CommitId string
Author string
Date string
Title string
PullRequestId string
Message string
}
func getGitCommits(repo string) []commit {
format := `[[start]]%n%H%n%al%n%aI%n%s%n%b`
cmd := fmt.Sprintf("cd %s && git log --branches=*master --after=2025-04-01 --author=grno --format=format:%s", repo, format)
gitLogCmd := exec.Command("cmd", "/c", cmd)
out, err := gitLogCmd.Output()
if err != nil {
panic(fmt.Sprintf("Failed on running %s", repo))
}
data := string(out)
commits := strings.Split(data, "[[start]]")
cleanCommits := []commit{}
for _, c := range commits[1:] {
commitLines := strings.Split(strings.TrimSpace(c), "\n")
subject := commitLines[3]
subjectParts := strings.Split(subject, ":")
commitData := commit{
CommitId: commitLines[0],
Author: commitLines[1],
Date: commitLines[2],
PullRequestId: strings.TrimSpace(strings.ReplaceAll(subjectParts[0], "Merged PR ", "")),
Title: strings.TrimSpace(subjectParts[1]),
Message: strings.Join(commitLines[4:], "\n"),
}
cleanCommits = append(cleanCommits, commitData)
}
return cleanCommits
}
var repositories = []string{
"C:\\Git\\JenkinsJobs",
"C:\\Git\\TestComplete",
}
func main() {
allCommits := []commit{}
for _, repo := range repositories {
commits := getGitCommits(repo)
allCommits = append(allCommits, commits...)
}
// funcs := template.FuncMap{
// "nl2br": func(text string) template.HTML {
// escaped := template.HTMLEscapeString(text)
// return template.HTML(strings.ReplaceAll(escaped, "\n", "<br>"))
// },
// }
t := template.New("report.tpl")
// t.Funcs(funcs)
t, err := t.ParseFiles("report.tpl")
if err != nil {
panic(fmt.Sprintf("Failed on template creation with %v", err))
}
e := t.Execute(os.Stdout, allCommits)
if e != nil {
panic(e)
}
}