You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
1.6 KiB
85 lines
1.6 KiB
package cmd
|
|
|
|
import (
|
|
"github.com/urfave/cli"
|
|
"html/template"
|
|
"io"
|
|
"os"
|
|
"sort"
|
|
"strings"
|
|
)
|
|
import "code.gitea.io/sdk/gitea"
|
|
|
|
const issueTemplate = `
|
|
{{range $issue := . }}
|
|
## {{$issue.Title}}
|
|
|
|
{{range $label := $issue.Labels}}{{$label.Name}} {{end}}
|
|
|
|
{{$issue.Body}}
|
|
|
|
{{end}}
|
|
`
|
|
|
|
var ExportAll = cli.Command{
|
|
Name: "export-all",
|
|
Description: "Exports all open issues into a markdown file",
|
|
ArgsUsage: "<owner>/<repository>",
|
|
Flags: []cli.Flag{
|
|
cli.StringFlag{
|
|
Name: "output,o",
|
|
Usage: "output file",
|
|
TakesFile: true,
|
|
},
|
|
cli.StringFlag{
|
|
Name: "token",
|
|
Usage: "Gitea access token",
|
|
Required: true,
|
|
},
|
|
cli.StringFlag{
|
|
Name: "url",
|
|
Usage: "Gitea URL",
|
|
Required: true,
|
|
},
|
|
},
|
|
Action: exportAll,
|
|
}
|
|
|
|
func exportAll(ctx *cli.Context) error {
|
|
token := ctx.String("token")
|
|
url := ctx.String("url")
|
|
outputFile := ctx.String("output")
|
|
client := gitea.NewClient(url, token)
|
|
|
|
splittedArgs := strings.Split(ctx.Args().First(), "/")
|
|
|
|
issues, err := client.ListRepoIssues(splittedArgs[0], splittedArgs[1], gitea.ListIssueOption{
|
|
State: "open",
|
|
Type: "issue",
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
sort.SliceStable(issues, func(i, j int) bool {
|
|
return true
|
|
})
|
|
return writeIssues(outputFile, issues)
|
|
}
|
|
|
|
func writeIssues(outputFile string, issues []*gitea.Issue) (err error) {
|
|
var output io.Writer
|
|
if len(outputFile) > 0 {
|
|
output, err = os.Create(outputFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
} else {
|
|
output = os.Stdout
|
|
}
|
|
|
|
tmpl, err := template.New("issues").Parse(issueTemplate)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return tmpl.Execute(output, issues)
|
|
}
|
|
|