Skip to content

Commit

Permalink
changelog generator added.
Browse files Browse the repository at this point in the history
  • Loading branch information
arkaterol committed Nov 20, 2019
1 parent fbf07c1 commit 46ca79b
Show file tree
Hide file tree
Showing 16 changed files with 926 additions and 0 deletions.
14 changes: 14 additions & 0 deletions nupkg/push_packages.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
. ".\common.ps1"

# Get the version
[xml]$commonPropsXml = Get-Content (Join-Path $rootFolder "common.props")
$version = $commonPropsXml.Project.PropertyGroup.Version

# Publish all packages
foreach($project in $projects) {
$projectName = $project.Substring($project.LastIndexOf("/") + 1)
& dotnet nuget push ($projectName + "." + $version + ".nupkg") -s "https://nuget.abp.io/API_KEY/v3/index.json"
}

# Go back to the pack folder
Set-Location $packFolder
36 changes: 36 additions & 0 deletions tools/github-changelog-generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# GitHub Change Log Generator

## Configuration

Edit the config.yaml file to customize the generated output.

## Usage

```
.\generator.exe generate [flags] > changelog.md
```

### Options

```
Flags:
-h, --help help for generate
-m, --milestone string milestone title to get issues and pull requests for
-r, --repo string repository name to generate the Changelog for, in the form user/repo
--since-tag string issues and pull requests since tag
-s, --state string state of the issues and pull requests to get (open,closed or all)
-t, --token string personal access token
--until-tag string issues and pull requests until tag
Global Flags:
--config string config file (default is config.yaml)
```

## Example

Generate change logs for the ABP repository for the 0.19 milestone:

````
.\generator.exe generate -r abpframework/abp -m "0.19" > changelog.md
````

Binary file added tools/github-changelog-generator/changelog.md
Binary file not shown.
54 changes: 54 additions & 0 deletions tools/github-changelog-generator/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
repo: abpframework/abp
# token:
milestone: 0.18.1
# since-tag: 0.18.0
# until-tag: 0.17.0
state: closed
groups:
- labels:
- breaking change
title: "Breaking Changes"

- labels:
- feature
title: "Features"

- labels:
- enhancement
title: "Enhancements"

- labels:
- bug
title: "Bug Fixes"

- labels:
title: "Others"

#template: |-
# {{if .Milestone}}## {{.Milestone.GetTitle}} ({{.Milestone.GetClosedAt.Format "2006-01-02"}}){{end -}}
# {{if .IssuesByMilestone}}
# {{range .IssuesByMilestone}}
# ### {{.Title}}
# {{range .Issues}}
# {{if .IsPullRequest -}}
# - PR [\#{{.GetNumber}}]({{.GetHTMLURL}}): {{.GetTitle}} (by [{{.GetUser.GetLogin}}]({{.GetUser.GetHTMLURL}}))
# {{- else -}}
# - ISSUE [\#{{.GetNumber}}]({{.GetHTMLURL}}): {{.GetTitle}}
# {{- end -}}
# {{end}}
# {{end}}
# {{end -}}
# {{if .SinceTagCommit}}## {{.SinceTag}}{{if .UntilTagCommit}} - {{.UntilTag}}{{end}}{{end -}}
# {{if .IssuesByTag}}
# {{range .IssuesByTag}}
# ### {{.Title}}
# {{range .Issues}}
# {{if .IsPullRequest -}}
# - PR [\#{{.GetNumber}}]({{.GetHTMLURL}}): {{.GetTitle}} (by [{{.GetUser.GetLogin}}]({{.GetUser.GetHTMLURL}}))
# {{- else -}}
# - ISSUE [\#{{.GetNumber}}]({{.GetHTMLURL}}): {{.GetTitle}}
# {{- end -}}
# {{end}}
# {{end}}
# {{- end -}}
Binary file added tools/github-changelog-generator/generator.exe
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package cmd

import (
"GithubChangelogGenerator/internal"
"GithubChangelogGenerator/pkg"
"fmt"
"io"
"os"

"github.com/google/go-github/github"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// generateCmd represents the generate command
var generateCmd = &cobra.Command{
Use: "generate",
Short: "Generate changelog",
Long: `Generates changelog based on a milestone or tag(s)
Edit the config.yaml file to customize the generated output.`,
Run: func(cmd *cobra.Command, args []string) {
c := &internal.Config{}
err := viper.Unmarshal(c)
if err != nil {
er(err)
}

repo, err := pkg.NewRepo(c.Repo, c.Token)
if err != nil {
er(err)
}

issuesByMilestone, err := repo.IssuesByMilestone(c.Milestone, c.State)
if err != nil {
er(err)
}
milestone, err := repo.Milestone(c.Milestone)
if err != nil {
er(err)
}
sinceTagCommit, err := repo.TagCommit(c.SinceTag)
if err != nil {
er(err)
}
untilTagCommit, err := repo.TagCommit(c.UntilTag)
if err != nil {
er(err)
}

var issuesByTag []*github.Issue
switch {
case sinceTagCommit != nil:
issuesByTag, err = repo.IssuesSince(sinceTagCommit.Committer.GetDate())
if err != nil {
er(err)
}
if c.UntilTag != "" {
issuesByTag = pkg.FilterUntil(issuesByTag, untilTagCommit.Committer.GetDate())
}
case untilTagCommit != nil:
issuesByTag, err = repo.AllIssues(c.State)
if err != nil {
er(err)
}
issuesByTag = pkg.FilterUntil(issuesByTag, untilTagCommit.Committer.GetDate())
}

groupedIssuesByMilestone := internal.GroupIssues(c.Groups, issuesByMilestone)
if err != nil {
er(err)
}

groupedIssuesByTag := internal.GroupIssues(c.Groups, issuesByTag)
if err != nil {
er(err)
}

err = writeChangelog(os.Stdout, &TemplateData{
Repository: repo.Repository(),
IssuesByMilestone: groupedIssuesByMilestone,
IssuesByTag: groupedIssuesByTag,
Milestone: milestone,
SinceTag: c.SinceTag,
SinceTagCommit: sinceTagCommit,
UntilTag: c.UntilTag,
UntilTagCommit: untilTagCommit,
})
if err != nil {
er(err)
}
},
}

func init() {
rootCmd.AddCommand(generateCmd)
generateCmd.Flags().StringP("repo", "r", "", "repository name to generate the Changelog for, in the form user/repo")
generateCmd.Flags().StringP("token", "t", "", "personal access token")
generateCmd.Flags().StringP("milestone", "m", "", "milestone title to get issues and pull requests for")
generateCmd.Flags().String("since-tag", "", "issues and pull requests since tag")
generateCmd.Flags().String("until-tag", "", "issues and pull requests until tag")
generateCmd.Flags().StringP("state", "s", "", "state of the issues and pull requests to get (open,closed or all)")

err := viper.BindPFlags(generateCmd.Flags())
if err != nil {
er(err)
}
}

type TemplateData struct {
Repository *github.Repository
IssuesByMilestone []*internal.GroupedIssues
IssuesByTag []*internal.GroupedIssues
Milestone *github.Milestone
SinceTag string
SinceTagCommit *github.Commit
UntilTag string
UntilTagCommit *github.Commit
}

func writeChangelog(w io.WriteCloser, td *TemplateData) error {
template := viper.GetString("template")
if template == "" {
template = `{{if .Milestone}}## {{.Milestone.GetTitle}} ({{.Milestone.GetClosedAt.Format "2006-01-02"}}){{end -}}
{{if .IssuesByMilestone}}
{{range .IssuesByMilestone}}
### {{.Title}}
{{range .Issues}}
{{if .IsPullRequest -}}
- PR [\#{{.GetNumber}}]({{.GetHTMLURL}}): {{.GetTitle}} (by [{{.GetUser.GetLogin}}]({{.GetUser.GetHTMLURL}}))
{{- else -}}
- ISSUE [\#{{.GetNumber}}]({{.GetHTMLURL}}): {{.GetTitle}}
{{- end -}}
{{end}}
{{end}}
{{end -}}
{{if .SinceTagCommit}}## {{.SinceTag}}{{if .UntilTagCommit}} - {{.UntilTag}}{{end}}{{end -}}
{{if .IssuesByTag}}
{{range .IssuesByTag}}
### {{.Title}}
{{range .Issues}}
{{if .IsPullRequest -}}
- PR [\#{{.GetNumber}}]({{.GetHTMLURL}}): {{.GetTitle}} (by [{{.GetUser.GetLogin}}]({{.GetUser.GetHTMLURL}}))
{{- else -}}
- ISSUE [\#{{.GetNumber}}]({{.GetHTMLURL}}): {{.GetTitle}}
{{- end -}}
{{end}}
{{end}}
{{- end -}}
`
}

result, err := executeTemplate(template, td)
if err != nil {
return err
}
_, err = fmt.Fprintf(w, "%s", result)
if err != nil {
return err
}

return w.Close()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"bytes"
"fmt"
"os"
"text/template"
)

func executeTemplate(tmplStr string, data interface{}) ([]byte, error) {
tmpl, err := template.New("").Parse(tmplStr)
if err != nil {
return nil, err
}

buf := new(bytes.Buffer)
err = tmpl.Execute(buf, data)
return buf.Bytes(), err
}

func er(msg interface{}) {
fmt.Println("Error:", msg)
os.Exit(1)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var cfgFile string

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "GithubChangelogGenerator",
Short: "Changelog generator",
Long: `This application is a tool to generate changelog from a Github milestone.`,
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is config.yaml)")
}

// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
viper.AddConfigPath(".")
viper.SetConfigName("config")
}

viper.AutomaticEnv() // read in environment variables that match

// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
//fmt.Println("Using config file:", viper.ConfigFileUsed())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

const version = "0.2.0"

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(version)
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
Loading

0 comments on commit 46ca79b

Please sign in to comment.