pull expand tool: add tea mode (#153)

as title

Reviewed-on: https://gitea.com/gitea/blog/pulls/153
Reviewed-by: Norwin <noerw@noreply.gitea.io>
Reviewed-by: John Olheiser <john.olheiser@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
Co-committed-by: 6543 <6543@obermui.de>
This commit is contained in:
6543 2021-03-13 23:10:58 +08:00 committed by John Olheiser
parent 1664d17b22
commit b377b5d8d5
2 changed files with 18 additions and 3 deletions

View File

@ -8,3 +8,5 @@ From the base directory
```
go run contrib/pulls/pulls.go --release 1.11.4
```
To convert tea release posts, switch to tea mode via `--tea` flag.

View File

@ -9,13 +9,16 @@ import (
)
var (
pullURL = "https://github.com/go-gitea/gitea/pull/"
pullRegex = regexp.MustCompile(`#(\d+)\)`)
pullGiteaURL = "https://github.com/go-gitea/gitea/pull/"
pullTeaURL = "https://gitea.com/gitea/tea/pulls/"
pullRegex = regexp.MustCompile(`#(\d+)\)`)
)
func main() {
var release string
var tea bool
flag.StringVar(&release, "release", "", "The release to target")
flag.BoolVar(&tea, "tea", false, "switch to tea mode")
flag.Parse()
if release == "" {
@ -23,7 +26,12 @@ func main() {
return
}
fi, err := os.OpenFile(fmt.Sprintf("content/post/release-of-%s.md", release), os.O_RDWR, os.ModePerm)
post := fmt.Sprintf("content/post/release-of-%s.md", release)
if tea {
post = fmt.Sprintf("content/post/release-of-tea-%s.md", release)
}
fi, err := os.OpenFile(post, os.O_RDWR, os.ModePerm)
if os.IsNotExist(err) {
fmt.Printf("could not find content/post/release-of-%s.md\n", release)
return
@ -39,6 +47,11 @@ func main() {
return
}
pullURL := pullGiteaURL
if tea {
pullURL = pullTeaURL
}
repl := pullRegex.ReplaceAll(data, []byte(`[#$1](`+pullURL+`$1))`))
if _, err := fi.WriteAt(repl, 0); err != nil {
fmt.Println(err)