This repository has been archived by the owner on Jun 6, 2021. It is now read-only.
forked from gerad/release-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommits.go
81 lines (66 loc) · 1.55 KB
/
commits.go
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
package main
import (
"fmt"
"log"
"regexp"
"strings"
)
type CommitApp struct {
config Config
github GithubGateway
}
func NewCommitApp(config Config, github GithubGateway) CommitApp {
return CommitApp{config, github}
}
func (app CommitApp) Issues() []Issue {
issues := []Issue{}
for _, repo := range strings.Fields(app.config.repos) {
issues = append(issues, app.repoIssues(repo)...)
}
return issues
}
func (app CommitApp) repoIssues(repo string) []Issue {
prs := []Issue{}
var res struct {
Commits []struct {
Commit struct {
Author struct {
Name string
}
Message string
}
}
}
err := app.github.Get(fmt.Sprintf("repos/%v/%v/compare/%v...%v",
app.config.owner,
repo,
app.config.base,
app.config.head), &res)
if err != nil {
log.Fatalf("%v", err)
}
re1 := regexp.MustCompile("Merge pull request #(?P<num>\\d+).*\n\n(?P<title>.*)")
re2 := regexp.MustCompile("(?P<title>.*) \\(#(?P<num>\\d+)\\)")
for _, commit := range res.Commits {
for _, re := range []*regexp.Regexp{re1, re2} {
matches := re.FindStringSubmatch(commit.Commit.Message)
if matches != nil && len(matches) == 3 {
result := make(map[string]string)
for i, name := range re.SubexpNames() {
if i != 0 {
result[name] = matches[i]
}
}
prs = append(prs, Issue{
Author: commit.Commit.Author.Name,
Repo: repo,
Num: result["num"],
URL: fmt.Sprintf("https://github.com/%s/%s/pull/%s", app.config.owner, repo, result["num"]),
Title: result["title"],
})
break
}
}
}
return prs
}