mirror of https://gitea.com/gitea/blog.git
Add contrib for converting PRs (#129)
Tiny check to make idempotent (more or less) Add contrib for converting PRs Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: jolheiser <john.olheiser@gmail.com> Reviewed-on: https://gitea.com/gitea/blog/pulls/129 Reviewed-by: Andrew Thornton <art27@cantab.net> Reviewed-by: 6543 <6543@noreply.gitea.io>
This commit is contained in:
parent
fc6a453f36
commit
4443d6332c
|
@ -0,0 +1,10 @@
|
|||
# pulls contrib
|
||||
|
||||
This is a Go "script" to convert all PRs like `#100` to `[#100](https://github.com/go-gitea/gitea/pull/100)`
|
||||
|
||||
### Usage
|
||||
|
||||
From the base directory
|
||||
```
|
||||
go run contrib/pulls/pulls.go --release 1.11.4
|
||||
```
|
|
@ -0,0 +1,49 @@
|
|||
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")
|
||||
}
|
Loading…
Reference in New Issue