From ae40226d94e9c659b73438c2222201e936c54118 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sat, 11 Sep 2021 23:34:25 +0200 Subject: [PATCH] refactor: Update config and clean up code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Change naming in the config - Add a template for config - Try to fix an issue with «multi-line» vs «single-line» comments Signed-off-by: Matej Focko --- docs/cpp_config.yml | 6 +++--- docs/haskell_config.yml | 6 +++--- docs/python_config.yml | 6 +++--- docs/template.yml | 18 ++++++++++++++++++ src/core/comments.go | 16 ++++++++++++---- src/core/configuration.go | 8 ++++---- 6 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 docs/template.yml diff --git a/docs/cpp_config.yml b/docs/cpp_config.yml index e4dc794..dcda18b 100644 --- a/docs/cpp_config.yml +++ b/docs/cpp_config.yml @@ -4,7 +4,7 @@ gitea: repository: "testing-repo" language: - separate_opening: true - opening: "/**" + on_separate_line: true + opening: "/** " continuation: " ** " - closing: " **/\n" \ No newline at end of file + closing: "\n **/\n" \ No newline at end of file diff --git a/docs/haskell_config.yml b/docs/haskell_config.yml index a8ec22b..589ec54 100644 --- a/docs/haskell_config.yml +++ b/docs/haskell_config.yml @@ -4,7 +4,7 @@ gitea: repository: "testing-repo" language: - separate_opening: false - opening: "-- #" + on_separate_line: false + opening: "-- # " continuation: "-- # " - closing: "" \ No newline at end of file + closing: "\n" \ No newline at end of file diff --git a/docs/python_config.yml b/docs/python_config.yml index caa4678..b53e6c0 100644 --- a/docs/python_config.yml +++ b/docs/python_config.yml @@ -4,7 +4,7 @@ gitea: repository: "testing-repo" language: - separate_opening: false - opening: "##" + on_separate_line: false + opening: "## " continuation: "## " - closing: "" \ No newline at end of file + closing: "\n" \ No newline at end of file diff --git a/docs/template.yml b/docs/template.yml new file mode 100644 index 0000000..a3117cf --- /dev/null +++ b/docs/template.yml @@ -0,0 +1,18 @@ +gitea: + # instance URL with both protocol and port, if necessary + instance_url: "‹fill in›" + # owner of the repository, usually user's login, i.e. namespace of the repository + owner: "‹fill in›" + # repository name + repository: "‹fill in›" + +language: + # boolean value that is used to decide if multiline review comments have opening and closing + # symbols on the separate line + on_separate_line: true + # sequence that opens comment + opening: "/** " + # sequence that is used for multiline comments, i.e. prefixing the lines + continuation: " ** " + # sequence that closes off the comment, including newline + closing: "\n **/\n" \ No newline at end of file diff --git a/src/core/comments.go b/src/core/comments.go index 25e8526..12a95ef 100644 --- a/src/core/comments.go +++ b/src/core/comments.go @@ -10,17 +10,19 @@ import ( ) func GetSeparatorForMultiline(config *Config) string { - if config.Language.OpeningOnSeparateLine { + if config.Language.OnSeparateLine { return "\n" } return "" } func FormatComment(config *Config, body string, beenWrapped bool) string { - if beenWrapped && !config.Language.OpeningOnSeparateLine { - body = strings.TrimPrefix(body, config.Language.Continuation) + if beenWrapped { + if !config.Language.OnSeparateLine { + body = strings.TrimPrefix(body, config.Language.Continuation) + } + body = strings.TrimRightFunc(body, unicode.IsSpace) } - body = strings.TrimRightFunc(body, unicode.IsSpace) return fmt.Sprintf("%s%s%s", config.Language.Opening, body, config.Language.Closing) } @@ -39,6 +41,12 @@ func ProcessComment(config *Config, wrapper *wrap.Wrapper, comment *gitea.PullRe strings.TrimRightFunc(config.Language.Continuation, unicode.IsSpace)+"\n", -1, ) + body = strings.Replace( + body, + config.Language.Opening+"\n", + strings.TrimRightFunc(config.Language.Opening, unicode.IsSpace)+"\n", + -1, + ) comment.Body = FormatComment(config, body, beenWrapped) } diff --git a/src/core/configuration.go b/src/core/configuration.go index 379041e..0e0f0ab 100644 --- a/src/core/configuration.go +++ b/src/core/configuration.go @@ -14,10 +14,10 @@ type Config struct { Token string } `yaml:"gitea"` Language struct { - OpeningOnSeparateLine bool `yaml:"separate_opening"` - Opening string `yaml:"opening"` - Continuation string `yaml:"continuation"` - Closing string `yaml:"closing"` + OnSeparateLine bool `yaml:"on_separate_line"` + Opening string `yaml:"opening"` + Continuation string `yaml:"continuation"` + Closing string `yaml:"closing"` } `yaml:"language"` }