@@ -3,103 +3,93 @@ case class Commit(sha: String, author: String, header: String, body: String) {
3
3
override def toString = " * " + sha + " (" + author + " ) " + header + " - " + body.take(5 ) + " ..."
4
4
}
5
5
6
-
7
6
/** Gobal functions for dealing with git. */
8
7
object GitHelper {
9
8
def processGitCommits (gitDir : java.io.File , previousTag : String , currentTag : String ): IndexedSeq [Commit ] = {
10
9
import sys .process ._
11
10
val gitFormat = " %h %s" // sha and subject
12
- val log = Process (Seq (" git" , " --no-pager" , " log" , s " ${previousTag}.. ${currentTag}" ," --format=format:" + gitFormat," --no-merges" , " --topo-order" ), gitDir).lines
11
+ val log = Process (Seq (" git" , " --no-pager" , " log" , s " ${previousTag}.. ${currentTag}" , " --format=format:" + gitFormat, " --no-merges" , " --topo-order" ), gitDir).lines
13
12
14
13
log.par.map(_.split(" " , 2 )).collect {
15
14
case Array (sha, title) =>
16
- val (author :: body) = Process (Seq (" git" , " --no-pager" , " show" , sha , " --format=format:%aN%n%b" ," --quiet" ), gitDir).lines.toList
15
+ val (author :: body) = Process (Seq (" git" , " --no-pager" , " show" , sha, " --format=format:%aN%n%b" , " --quiet" ), gitDir).lines.toList
17
16
Commit (sha, author, title, body.mkString(" \n " ))
18
17
}.toVector
19
18
}
20
19
21
20
def hasFixins (msg : String ): Boolean = (
22
21
(msg contains " SI-" ) /* && ((msg.toLowerCase contains "fix") || (msg.toLowerCase contains "close"))*/
23
22
)
24
-
23
+
25
24
val siPattern = java.util.regex.Pattern .compile(" (SI-[0-9]+)" )
26
25
27
- def fixLinks (commit : Commit ): String = {
26
+ def fixLinks (commit : Commit )( implicit targetLanguage : TargetLanguage ) : String = {
28
27
val searchString = commit.body + commit.header
29
28
val m = siPattern matcher searchString
30
29
val issues = new collection.mutable.ArrayBuffer [String ]
31
- while (m.find()) {
30
+ while (m.find()) {
32
31
issues += (m group 1 )
33
32
}
34
- issues map (si => """ <a href=" https://issues.scala-lang.org/browse/%s">%s</a> """ format (si , si)) mkString " , "
33
+ issues map (si => targetLanguage.createHyperLink( s " https://issues.scala-lang.org/browse/ $si " , si)) mkString " , "
35
34
}
36
35
37
36
def htmlEncode (s : String ) = org.apache.commons.lang3.StringEscapeUtils .escapeHtml4(s)
38
37
}
39
38
40
- class GitInfo (gitDir : java.io.File , val previousTag : String , val currentTag : String ) {
39
+ class GitInfo (gitDir : java.io.File , val previousTag : String , val currentTag : String )( implicit targetLanguage : TargetLanguage ) {
41
40
import GitHelper ._
42
41
val commits = processGitCommits(gitDir, previousTag, currentTag)
43
42
44
43
val authors : Seq [(String , Int )] = {
45
- val grouped : Vector [(String ,Int )] = (commits groupBy (_.author)).map { case (a,c) => a -> c.length }{ collection.breakOut}
44
+ val grouped : Vector [(String , Int )] = (commits groupBy (_.author)).map { case (a, c) => a -> c.length } { collection.breakOut }
46
45
(grouped sortBy (_._2)).reverse
47
46
}
48
47
49
48
val fixCommits =
50
- for {
51
- commit <- commits
52
- searchString = commit.body + commit.header
53
- if hasFixins(searchString)
54
- } yield commit
49
+ for {
50
+ commit <- commits
51
+ searchString = commit.body + commit.header
52
+ if hasFixins(searchString)
53
+ } yield commit
55
54
56
- private def commitShaLink (sha : String ) =
57
- s """ <a href=" https://github.com/scala/scala/commit/ ${sha}"> ${ sha} </a> """
55
+ private def commitShaLink (sha : String ) =
56
+ targetLanguage.createHyperLink( s " https://github.com/scala/scala/commit/ ${sha}" , sha)
58
57
59
- private def blankLine (): String = " <p> </p> "
60
- private def header4 (msg : String ): String = s " <h4> $ msg</h4> "
58
+ private def blankLine (): String = targetLanguage.blankLine()
59
+ private def header4 (msg : String ): String = targetLanguage.header4( msg)
61
60
62
61
def renderCommitterList : String = {
63
62
val sb = new StringBuffer
64
63
sb append blankLine()
65
64
sb append header4(" A big thank you to all the contributors!" )
66
- sb append """ |<table border="0" cellspacing="0" cellpadding="1">
67
- | <thead><tr><th>#</th><th align="left">Author</th></tr></thead>
68
- |<tbody>""" .stripMargin
69
- for ((author, count) <- authors)
70
- sb append s """ <tr><td align="right"> ${count} </td><td> ${htmlEncode(author)}</td></tr> """
71
- sb append """ </tbody></table>"""
65
+ sb append targetLanguage.tableHeader(" #" , " Author" )
66
+ for ((author, count) <- authors)
67
+ sb append targetLanguage.tableRow(count.toString, author)
68
+ sb append targetLanguage.tableEnd
72
69
sb.toString
73
70
}
74
71
75
72
def renderCommitList : String = {
76
73
val sb = new StringBuffer
77
74
sb append blankLine()
78
75
sb append header4(" Complete commit list!" )
79
- sb append """ <table border="0" cellspacing="0" cellpadding="1">
80
- <thead><tr><th>sha</th><th align="left">Title</th></tr></thead>
81
- <tbody>"""
82
- for (commit <- commits)
83
- sb append s """ <tr><td align="right"> ${commitShaLink(commit.sha)} </td><td> ${htmlEncode(commit.header)}</td></tr> """
84
- sb append """ </tbody>
85
- </table>"""
76
+ sb append targetLanguage.tableHeader(" sha" , " Title" )
77
+ for (commit <- commits)
78
+ sb append targetLanguage.tableRow(commitShaLink(commit.sha), commit.header)
79
+ sb append targetLanguage.tableEnd
86
80
sb.toString
87
81
}
88
82
89
83
def renderFixedIssues : String = {
90
84
val sb = new StringBuffer
91
85
sb append blankLine()
92
86
sb append header4(s " Commits and the issues they fixed since ${previousTag}" )
93
- sb append (""" <table border="0" cellspacing="0" cellpading="1">
94
- <thead><tr><th>Issue(s)</th><th>Commit</th><th>Message</th></tr></thead>
95
- <tbody>""" )
96
- for (commit <- fixCommits)
97
- sb append s """ <tr><td> ${fixLinks(commit)} </td><td> ${commitShaLink(commit.sha)} </td><td> ${htmlEncode(commit.header)}</td></tr> """
98
- sb append """ </tbody>
99
- </table>"""
87
+ sb append targetLanguage.tableHeader(" Issue(s)" , " Commit" , " Message" )
88
+ for (commit <- fixCommits)
89
+ sb append targetLanguage.tableRow(fixLinks(commit), commitShaLink(commit.sha), commit.header)
90
+ sb append targetLanguage.tableEnd
100
91
sb append blankLine()
101
92
sb.toString
102
93
}
103
94
104
-
105
95
}
0 commit comments