2015-03-25 07:55:10 +00:00
|
|
|
// Copyright (C) 2014 The Syncthing Authors.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-09 06:52:18 +00:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2015-03-25 07:55:10 +00:00
|
|
|
|
2015-04-20 05:03:50 +00:00
|
|
|
// +build ignore
|
|
|
|
|
2015-03-22 15:14:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2016-05-31 12:40:30 +00:00
|
|
|
"encoding/json"
|
2017-11-19 20:19:33 +00:00
|
|
|
"errors"
|
2015-03-22 15:14:52 +00:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
2016-05-31 12:40:30 +00:00
|
|
|
"io/ioutil"
|
2015-03-22 15:14:52 +00:00
|
|
|
"log"
|
2016-05-31 12:40:30 +00:00
|
|
|
"net/http"
|
|
|
|
"os"
|
2015-03-22 15:14:52 +00:00
|
|
|
"os/exec"
|
|
|
|
"regexp"
|
2017-11-19 20:19:33 +00:00
|
|
|
"sort"
|
2016-05-31 12:40:30 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2015-03-22 15:14:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2015-04-04 07:50:59 +00:00
|
|
|
subjectIssues = regexp.MustCompile(`^([^(]+)\s+\((?:fixes|ref) ([^)]+)\)(?:[^\w])?$`)
|
2015-03-22 15:14:52 +00:00
|
|
|
issueNumbers = regexp.MustCompile(`(#\d+)`)
|
|
|
|
)
|
|
|
|
|
2017-11-19 20:19:33 +00:00
|
|
|
type issue struct {
|
|
|
|
number int
|
|
|
|
subject string
|
|
|
|
labels []string
|
|
|
|
}
|
|
|
|
|
2015-03-22 15:14:52 +00:00
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
// Display changelog since the version given on the command line, or
|
|
|
|
// figure out the last release if there were no arguments.
|
|
|
|
var prevRel string
|
|
|
|
if flag.NArg() > 0 {
|
|
|
|
prevRel = flag.Arg(0)
|
|
|
|
} else {
|
|
|
|
bs, err := runError("git", "describe", "--abbrev=0", "HEAD^")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
prevRel = string(bs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the git log with subject and author nickname
|
2017-11-19 20:19:33 +00:00
|
|
|
bs, err := runError("git", "log", "--reverse", "--pretty=format:%s", prevRel+"..")
|
2015-03-22 15:14:52 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2017-11-19 20:19:33 +00:00
|
|
|
var resolved []issue
|
|
|
|
|
2015-03-22 15:14:52 +00:00
|
|
|
// Split into lines
|
|
|
|
for _, line := range bytes.Split(bs, []byte{'\n'}) {
|
|
|
|
// Check if subject contains a "(fixes ...)" or "(ref ...)""
|
2017-11-19 20:19:33 +00:00
|
|
|
if m := subjectIssues.FindSubmatch(line); len(m) > 0 {
|
2015-03-22 15:14:52 +00:00
|
|
|
issues := issueNumbers.FindAll(m[2], -1)
|
2017-11-19 20:19:33 +00:00
|
|
|
for _, i := range issues {
|
|
|
|
n, err := strconv.Atoi(string(i[1:]))
|
2016-05-31 12:40:30 +00:00
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
2017-11-19 20:19:33 +00:00
|
|
|
title, labels, err := githubIssueTitleLabels(n)
|
2016-05-31 12:40:30 +00:00
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-11-19 20:19:33 +00:00
|
|
|
resolved = append(resolved, issue{n, title, labels})
|
2016-05-31 12:40:30 +00:00
|
|
|
}
|
2015-03-22 15:14:52 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-19 20:19:33 +00:00
|
|
|
|
|
|
|
sort.Slice(resolved, func(a, b int) bool {
|
|
|
|
return resolved[a].number < resolved[b].number
|
|
|
|
})
|
|
|
|
|
|
|
|
var bugs, enhancements, other []issue
|
|
|
|
var prev int
|
|
|
|
for _, i := range resolved {
|
|
|
|
if i.number == prev {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
prev = i.number
|
|
|
|
switch {
|
|
|
|
case contains("unreleased", i.labels):
|
|
|
|
continue
|
|
|
|
case contains("bug", i.labels):
|
|
|
|
bugs = append(bugs, i)
|
|
|
|
case contains("enhancement", i.labels):
|
|
|
|
enhancements = append(enhancements, i)
|
|
|
|
default:
|
|
|
|
other = append(other, i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("--- markdown ---\n\n")
|
|
|
|
markdown(prevRel, bugs, enhancements, other)
|
|
|
|
fmt.Printf("\n--- text ---\n\n")
|
|
|
|
text(prevRel, bugs, enhancements, other)
|
|
|
|
}
|
|
|
|
|
|
|
|
func markdown(version string, bugs, enhancements, other []issue) {
|
|
|
|
fmt.Printf("## Resolved issues since %s\n\n", version)
|
|
|
|
if len(bugs) > 0 {
|
|
|
|
fmt.Printf("### Bugs\n\n")
|
|
|
|
for _, issue := range bugs {
|
|
|
|
fmt.Printf("* [#%d](https://github.com/syncthing/syncthing/issues/%d): %s\n", issue.number, issue.number, issue.subject)
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
if len(enhancements) > 0 {
|
|
|
|
fmt.Printf("### Enhancements\n\n")
|
|
|
|
for _, issue := range enhancements {
|
|
|
|
fmt.Printf("* [#%d](https://github.com/syncthing/syncthing/issues/%d): %s\n", issue.number, issue.number, issue.subject)
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
if len(other) > 0 {
|
|
|
|
fmt.Printf("### Unclassified\n\n")
|
|
|
|
for _, issue := range other {
|
|
|
|
fmt.Printf("* [#%d](https://github.com/syncthing/syncthing/issues/%d): %s\n", issue.number, issue.number, issue.subject)
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func text(version string, bugs, enhancements, other []issue) {
|
|
|
|
fmt.Println(underline(fmt.Sprintf("Resolved issues since %s", version), "="))
|
|
|
|
fmt.Println()
|
|
|
|
if len(bugs) > 0 {
|
|
|
|
fmt.Println(underline("Bugs", "-"))
|
|
|
|
fmt.Println()
|
|
|
|
for _, issue := range bugs {
|
|
|
|
fmt.Printf("* #%d: %s\n", issue.number, issue.subject)
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
if len(enhancements) > 0 {
|
|
|
|
fmt.Println(underline("Enhancements", "-"))
|
|
|
|
fmt.Println()
|
|
|
|
for _, issue := range enhancements {
|
|
|
|
fmt.Printf("* #%d: %s\n", issue.number, issue.subject)
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
if len(other) > 0 {
|
|
|
|
fmt.Println(underline("Unclassified", "-"))
|
|
|
|
fmt.Println()
|
|
|
|
for _, issue := range other {
|
|
|
|
fmt.Printf("* #%d: %s\n", issue.number, issue.subject)
|
|
|
|
}
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func underline(s, c string) string {
|
|
|
|
return fmt.Sprintf("%s\n%s", s, strings.Repeat(c, len(s)))
|
2015-03-22 15:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func runError(cmd string, args ...string) ([]byte, error) {
|
|
|
|
ecmd := exec.Command(cmd, args...)
|
|
|
|
bs, err := ecmd.CombinedOutput()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return bytes.TrimSpace(bs), nil
|
|
|
|
}
|
2016-05-31 12:40:30 +00:00
|
|
|
|
2017-11-19 20:19:33 +00:00
|
|
|
func githubIssueTitleLabels(n int) (string, []string, error) {
|
2016-05-31 12:40:30 +00:00
|
|
|
req, err := http.NewRequest("GET", fmt.Sprintf("https://api.github.com/repos/syncthing/syncthing/issues/%d", n), nil)
|
2017-07-07 19:56:12 +00:00
|
|
|
if err != nil {
|
2017-11-19 20:19:33 +00:00
|
|
|
return "", nil, err
|
2017-07-07 19:56:12 +00:00
|
|
|
}
|
2016-05-31 12:40:30 +00:00
|
|
|
|
|
|
|
user, token := os.Getenv("GITHUB_USERNAME"), os.Getenv("GITHUB_TOKEN")
|
|
|
|
if user != "" && token != "" {
|
|
|
|
req.SetBasicAuth(user, token)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
2017-11-19 20:19:33 +00:00
|
|
|
return "", nil, err
|
2016-05-31 12:40:30 +00:00
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
bs, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
2017-11-19 20:19:33 +00:00
|
|
|
return "", nil, err
|
2016-05-31 12:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var res struct {
|
2017-11-19 20:19:33 +00:00
|
|
|
Title string
|
|
|
|
Labels []struct {
|
|
|
|
Name string
|
|
|
|
}
|
|
|
|
PR struct {
|
|
|
|
URL string
|
|
|
|
} `json:"pull_request"`
|
2016-05-31 12:40:30 +00:00
|
|
|
}
|
|
|
|
err = json.Unmarshal(bs, &res)
|
|
|
|
if err != nil {
|
2017-11-19 20:19:33 +00:00
|
|
|
return "", nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if res.PR.URL != "" {
|
|
|
|
return "", nil, errors.New("pull request")
|
|
|
|
}
|
|
|
|
|
|
|
|
var labels []string
|
|
|
|
for _, l := range res.Labels {
|
|
|
|
labels = append(labels, l.Name)
|
2016-05-31 12:40:30 +00:00
|
|
|
}
|
|
|
|
|
2017-11-19 20:19:33 +00:00
|
|
|
return res.Title, labels, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func contains(s string, ss []string) bool {
|
|
|
|
for _, x := range ss {
|
|
|
|
if s == x {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
2016-05-31 12:40:30 +00:00
|
|
|
}
|