mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-12-24 12:14:40 +08:00
update release command
This commit is contained in:
@@ -5,7 +5,7 @@ Generates markdown for releases.
|
||||
|
||||
Usage:
|
||||
```bash
|
||||
go run cmd/gen-release-md/gen-release-md.go -v=0.10.0 > /tmp/release.md
|
||||
go run cmd/gen-release-md/gen-release-md.go -v=0.10.0 -u=[github-username] > /tmp/release.md
|
||||
```
|
||||
|
||||
## goose.go
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -31,9 +32,13 @@ type Issue struct {
|
||||
Labels []Label `json:"labels"`
|
||||
}
|
||||
|
||||
type Milestone struct {
|
||||
Number int `json:"number"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
const (
|
||||
apiPrefix = "https://api.github.com/repos/"
|
||||
issuesPathAndQuery = "/issues?milestone=3&state=closed"
|
||||
apiPrefix = "https://api.github.com/repos/"
|
||||
)
|
||||
|
||||
var releaseTemplate = `# Documentation
|
||||
@@ -101,26 +106,33 @@ func printMarkDown(issues []*Issue, version *string) {
|
||||
|
||||
releaseTemplate := fmt.Sprintf(releaseTemplate, *version, *version)
|
||||
fmt.Println(releaseTemplate)
|
||||
fmt.Println("# Changelog\n")
|
||||
fmt.Println("## Features\n")
|
||||
fmt.Println(sections["feat"])
|
||||
fmt.Println("## Fixes\n")
|
||||
fmt.Println(sections["fix"])
|
||||
fmt.Println("## Docs\n")
|
||||
fmt.Println(sections["docs"])
|
||||
fmt.Println("## Chores\n")
|
||||
fmt.Println(sections["chore"])
|
||||
fmt.Println("# Changelog")
|
||||
if sections["feat"] != "" {
|
||||
fmt.Println("## Features")
|
||||
fmt.Println(sections["feat"])
|
||||
}
|
||||
if sections["fix"] != "" {
|
||||
fmt.Println("## Fixes")
|
||||
fmt.Println(sections["fix"])
|
||||
}
|
||||
if sections["docs"] != "" {
|
||||
fmt.Println("## Docs")
|
||||
fmt.Println(sections["docs"])
|
||||
}
|
||||
if sections["chore"] != "" {
|
||||
fmt.Println("## Chores")
|
||||
fmt.Println(sections["chore"])
|
||||
}
|
||||
|
||||
fmt.Println("# Contributors\n")
|
||||
fmt.Println("# Contributors")
|
||||
for _, user := range contributors {
|
||||
fmt.Println(fmt.Sprintf("- <a href=\"%s\"><img src=\"%s\" width=\"12\"/> <strong>%s</strong></a> %s", user.URL, user.AvatarURL, user.Login, user.Login))
|
||||
}
|
||||
}
|
||||
|
||||
// Get issues from repository
|
||||
func getIssues(repository string, username *string) ([]*Issue, error) {
|
||||
func httpGet(url string, username *string) (*http.Response, error) {
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest(http.MethodGet, apiPrefix+repository+issuesPathAndQuery, nil)
|
||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
if username != nil {
|
||||
req.SetBasicAuth(*username, "")
|
||||
}
|
||||
@@ -129,6 +141,39 @@ func getIssues(repository string, username *string) ([]*Issue, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Get milestone by title
|
||||
func getMilestone(repository string, version, username *string) (*Milestone, error) {
|
||||
url := fmt.Sprintf("%s%s/milestones", apiPrefix, repository)
|
||||
res, err := httpGet(url, username)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
milestones := make([]*Milestone, 0)
|
||||
if err = json.NewDecoder(res.Body).Decode(&milestones); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, milestone := range milestones {
|
||||
if milestone.Title == "v"+*version {
|
||||
return milestone, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, errors.New("milestone not found")
|
||||
}
|
||||
|
||||
// Get issues from repository
|
||||
func getIssues(repository string, milestone *Milestone, username *string) ([]*Issue, error) {
|
||||
url := fmt.Sprintf("%s%s/issues?state=closed&milestone=%d", apiPrefix, repository, milestone.Number)
|
||||
res, err := httpGet(url, username)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
issues := make([]*Issue, 0)
|
||||
@@ -140,14 +185,19 @@ func getIssues(repository string, username *string) ([]*Issue, error) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
version := flag.String("v", "1.0.0", "Version of release, example: -v=1.0.0")
|
||||
version := flag.String("v", "0.11.0", "Version of release, example: -v=1.0.0")
|
||||
username := flag.String("u", "", "GitHub username for request, example: -u=octocat")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
issues := make([]*Issue, 0)
|
||||
for _, repository := range repositories {
|
||||
iss, err := getIssues(repository, username)
|
||||
mil, err := getMilestone(repository, version, username)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
iss, err := getIssues(repository, mil, username)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user