gitea-blog/contrib/pulls/pulls.go
John Olheiser dfb1a52977 Blog post 1.11.6 and 1.11.7 (#131)
Missed some things in 1.11.7

Blog post 1.11.6 and 1.11.7

Also fixes contrib

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Co-authored-by: jolheiser <john.olheiser@gmail.com>
Reviewed-on: gitea/blog#131
Reviewed-by: lafriks <lafriks@noreply.gitea.io>
Reviewed-by: 6543 <6543@noreply.gitea.io>
2020-06-18 16:27:22 +00:00

50 lines
918 B
Go

package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"regexp"
)
var (
pullURL = "https://github.com/go-gitea/gitea/pull/"
pullRegex = regexp.MustCompile(`#(\d+)\)`)
)
func main() {
var release string
flag.StringVar(&release, "release", "", "The release to target")
flag.Parse()
if release == "" {
fmt.Println("missing --release flag")
return
}
fi, err := os.OpenFile(fmt.Sprintf("content/post/release-of-%s.md", release), os.O_RDWR, os.ModePerm)
if os.IsNotExist(err) {
fmt.Printf("could not find content/post/release-of-%s.md\n", release)
return
} else if err != nil {
fmt.Println(err)
return
}
defer fi.Close()
data, err := ioutil.ReadAll(fi)
if err != nil {
fmt.Println(err)
return
}
repl := pullRegex.ReplaceAll(data, []byte(`[#$1](`+pullURL+`$1))`))
if _, err := fi.WriteAt(repl, 0); err != nil {
fmt.Println(err)
return
}
fmt.Println("conversion complete")
}