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:
John Olheiser 2020-04-02 19:52:59 +00:00
parent fc6a453f36
commit 4443d6332c
2 changed files with 59 additions and 0 deletions

10
contrib/pulls/README.md Normal file
View File

@ -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
```

49
contrib/pulls/pulls.go Normal file
View File

@ -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")
}