pr-resolution #3

Merged
mfocko merged 7 commits from pr-resolution into main 2021-09-11 22:36:41 +02:00
2 changed files with 35 additions and 27 deletions
Showing only changes of commit 6afe39397f - Show all commits

27
main.go
View file

@ -3,7 +3,6 @@ package main
import (
"bufio"
"fmt"
"io"
"os"
"sort"
"strconv"
@ -11,19 +10,6 @@ import (
"code.gitea.io/sdk/gitea"
)
type ByLineNum []*gitea.PullReviewComment
func (a ByLineNum) Len() int { return len(a) }
func (a ByLineNum) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByLineNum) Less(i, j int) bool { return a[i].LineNum < a[j].LineNum }
func ExitOnError(err error) {
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func RetrieveComments(client *gitea.Client, prID, reviewID int64) []*gitea.PullReviewComment {
comments, _, err := client.ListPullReviewComments(
config.Gitea.Owner, config.Gitea.Repository, prID, reviewID,
@ -49,19 +35,6 @@ func SplitByFile(
return splitComments
}
func BackUpSource(filepath string) {
inputFile, err := os.Open(filepath)
ExitOnError(err)
defer inputFile.Close()
BackUpSourceFile, err := os.Create(filepath + ".bck")
ExitOnError(err)
defer BackUpSourceFile.Close()
_, err = io.Copy(BackUpSourceFile, inputFile)
ExitOnError(err)
}
func WriteCommentsInFile(
outputFile *os.File,
lineNum uint64,

35
utils.go Normal file
View file

@ -0,0 +1,35 @@
package main
import (
"fmt"
"io"
"os"
"code.gitea.io/sdk/gitea"
)
type ByLineNum []*gitea.PullReviewComment
func (a ByLineNum) Len() int { return len(a) }
func (a ByLineNum) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByLineNum) Less(i, j int) bool { return a[i].LineNum < a[j].LineNum }
func ExitOnError(err error) {
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func BackUpSource(filepath string) {
inputFile, err := os.Open(filepath)
ExitOnError(err)
defer inputFile.Close()
BackUpSourceFile, err := os.Create(filepath + ".bck")
ExitOnError(err)
defer BackUpSourceFile.Close()
_, err = io.Copy(BackUpSourceFile, inputFile)
ExitOnError(err)
}