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 37 additions and 31 deletions
Showing only changes of commit bc793b7162 - Show all commits

35
configuration.go Normal file
View file

@ -0,0 +1,35 @@
package main
import (
"os"
"gopkg.in/yaml.v2"
)
type Config struct {
Gitea struct {
InstanceURL string `yaml:"instance_url"`
Owner string `yaml:"owner"`
Repository string `yaml:"repository"`
} `yaml:"gitea"`
Language struct {
OpeningOnSeparateLine bool `yaml:"separate_opening"`
Opening string `yaml:"opening"`
Continuation string `yaml:"continuation"`
Closing string `yaml:"closing"`
} `yaml:"language"`
}
func LoadConfig(config *Config, filename string) {
if filename == "" {
filename = ".frag_review.yml"
}
configFile, err := os.Open(filename)
ExitOnError(err)
defer configFile.Close()
decoder := yaml.NewDecoder(configFile)
err = decoder.Decode(&config)
ExitOnError(err)
}

33
main.go
View file

@ -9,25 +9,8 @@ import (
"strconv" "strconv"
"code.gitea.io/sdk/gitea" "code.gitea.io/sdk/gitea"
"gopkg.in/yaml.v2"
) )
type Config struct {
Gitea struct {
InstanceURL string `yaml:"instance_url"`
Owner string `yaml:"owner"`
Repository string `yaml:"repository"`
} `yaml:"gitea"`
Language struct {
OpeningOnSeparateLine bool `yaml:"separate_opening"`
Opening string `yaml:"opening"`
Continuation string `yaml:"continuation"`
Closing string `yaml:"closing"`
} `yaml:"language"`
}
var config Config = Config{}
type ByLineNum []*gitea.PullReviewComment type ByLineNum []*gitea.PullReviewComment
func (a ByLineNum) Len() int { return len(a) } func (a ByLineNum) Len() int { return len(a) }
@ -138,23 +121,11 @@ func GetReviewsPerPR(client *gitea.Client, prID int64) []int64 {
return result return result
} }
func LoadConfig(filename string) { var config Config = Config{}
if filename == "" {
filename = ".frag_review.yml"
}
configFile, err := os.Open(filename)
ExitOnError(err)
defer configFile.Close()
decoder := yaml.NewDecoder(configFile)
err = decoder.Decode(&config)
ExitOnError(err)
}
func main() { func main() {
token := os.Getenv("GITEA_TOKEN") token := os.Getenv("GITEA_TOKEN")
LoadConfig(os.Getenv("FRAG_REVIEW_CONFIG")) LoadConfig(&config, os.Getenv("FRAG_REVIEW_CONFIG"))
client, err := gitea.NewClient(config.Gitea.InstanceURL, gitea.SetToken(token)) client, err := gitea.NewClient(config.Gitea.InstanceURL, gitea.SetToken(token))
ExitOnError(err) ExitOnError(err)