summaryrefslogtreecommitdiff
path: root/tools/make-release-notes.scala
blob: 3e5b60d223f5174130aaca8ae6145c5fce3abd74 (plain) (blame)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh
exec scala -feature $0 $@
!#

import sys.process._

val tag1 = "v2.10.0-M4"
val tag2 = "v2.10.0-M5"

// Git commit parsing magikz

case class Commit(sha: String, author: String, header: String, body: String) {
  override def toString = " * " + sha + " (" + author + ") " + header + " - " + body.take(5) + " ..."
}

val gitFormat = "--format=format:*-*%h``%aN``%s``%b"

def processGitCommits(input: String): IndexedSeq[Commit] =
  ((input split "[\\r\\n]*\\*\\-\\*").view map (_ split "``") collect {
    case Array(sha, author, hdr, msg) => Commit(sha, author, hdr, msg)
  }).toVector

val commits =
  processGitCommits(Process(Seq("git", "log", tag1+".."+tag2,"--format=format:*-*%h``%aN``%s``%b","--no-merges")).!!)

val authors: Seq[(String, Int)] = {
  val grouped: Vector[(String,Int)] = (commits groupBy (_.author)).map { case (a,c) => a -> c.length }{collection.breakOut}
  (grouped sortBy (_._2)).reverse
}

def hasFixins(msg: String): Boolean = (
  (msg contains "SI-") /*&& ((msg.toLowerCase contains "fix") || (msg.toLowerCase contains "close"))*/
)

val fixCommits =
   for {
     commit <- commits
     searchString = commit.body + commit.header
     if hasFixins(searchString)
   } yield commit


val siPattern = java.util.regex.Pattern.compile("(SI-[0-9]+)")

def fixLinks(commit: Commit): String = {
  val searchString = commit.body + commit.header
  val m = siPattern matcher searchString
  val issues = new collection.mutable.ArrayBuffer[String]
  while(m.find()) {
    issues += (m group 1)
  }
  issues map (si => """<a href="https://issues.scala-lang.org/browse/%s">%s</a>""" format (si, si)) mkString ", "
}


// HTML Generation for Toni

def commitShaLink(sha: String) = 
  """<a href="https://github.com/scala/scala/commit/%s">%s</a>""" format (sha,sha)

def printBlankLine(): Unit = println("<p>&nbsp</p>")
def printHeader4(msg: String): Unit = println("<h4>%s</h4>" format (msg))

def printCommiterList(): Unit = {
  printBlankLine()
  printHeader4("Special thanks to all the contribtuors!")
  println("""<table border="0" cellspacing="0" cellpadding="1">
   <thead><tr><th>#</th><th align="left">Author</th></tr></thead>
   <tbody>""")
  for((author, count) <- authors)
     println("""<tr><td align="right">%d &nbsp;</td><td>%s</td></tr>""" format (count, author))
  println("""</tbody>
</table>""")
}

def printCommitList(): Unit = {
  printBlankLine()
  printHeader4("Complete commit list!")
  println("""<table border="0" cellspacing="0" cellpadding="1">
   <thead><tr><th>sha</th><th align="left">Title</th></tr></thead>
   <tbody>""")
  for(commit <- commits) {
     println("<tr>")
     println("""<td align="right">%s&nbsp;</td><td>%s</td>""" format (commitShaLink(commit.sha), commit.header))
     /*print("<td>")
     (commit.body split "[\\r\\n]") foreach { line =>
       print(line)
       print("<br/>")
     }
     print("</td>")*/
     println("""</tr>""")
  }
  println("""</tbody>
</table>""")
}

def issueFixPrinter(): Unit = {
  printBlankLine()
  printHeader4("Here's a list of isssues that have been fixed since %s" format (tag1))
  println("""<table border="0" cellspacing="0" cellpading="1">
  <thead><tr><th>Issue(s)</th><th>Commit</th><th>Message</th></tr></thead>
  <tbody>""")
  for(commit <- fixCommits) {
    println("""<tr><td>%s&nbsp;</td><td>%s&nbsp;</td><td>%s</td></tr>""" format(fixLinks(commit), commitShaLink(commit.sha), commit.header))
  }
  println("""</tbody>
</table>""")
   printBlankLine()
}

def printHTML(): Unit = {
  println("""<html>
  <head>
    <title>%s - Release notes</title>
  </head>
  <body>
  <h3>A new release of Scala is available!  Please point your build tools at %s</h3>
  <p>:: INSERT HAND GENERATED NOTES HERE ::</p>
""" format(tag2, tag2 drop 1))
  issueFixPrinter()
  printCommiterList()
  printCommitList()
  println("""</body></html>""")
}

printHTML()