refactor: Update config and clean up code
- 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 <mfocko@redhat.com>
This commit is contained in:
parent
53deef6627
commit
ae40226d94
6 changed files with 43 additions and 17 deletions
|
@ -4,7 +4,7 @@ gitea:
|
||||||
repository: "testing-repo"
|
repository: "testing-repo"
|
||||||
|
|
||||||
language:
|
language:
|
||||||
separate_opening: true
|
on_separate_line: true
|
||||||
opening: "/**"
|
opening: "/** "
|
||||||
continuation: " ** "
|
continuation: " ** "
|
||||||
closing: " **/\n"
|
closing: "\n **/\n"
|
|
@ -4,7 +4,7 @@ gitea:
|
||||||
repository: "testing-repo"
|
repository: "testing-repo"
|
||||||
|
|
||||||
language:
|
language:
|
||||||
separate_opening: false
|
on_separate_line: false
|
||||||
opening: "-- #"
|
opening: "-- # "
|
||||||
continuation: "-- # "
|
continuation: "-- # "
|
||||||
closing: ""
|
closing: "\n"
|
|
@ -4,7 +4,7 @@ gitea:
|
||||||
repository: "testing-repo"
|
repository: "testing-repo"
|
||||||
|
|
||||||
language:
|
language:
|
||||||
separate_opening: false
|
on_separate_line: false
|
||||||
opening: "##"
|
opening: "## "
|
||||||
continuation: "## "
|
continuation: "## "
|
||||||
closing: ""
|
closing: "\n"
|
18
docs/template.yml
Normal file
18
docs/template.yml
Normal file
|
@ -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"
|
|
@ -10,17 +10,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetSeparatorForMultiline(config *Config) string {
|
func GetSeparatorForMultiline(config *Config) string {
|
||||||
if config.Language.OpeningOnSeparateLine {
|
if config.Language.OnSeparateLine {
|
||||||
return "\n"
|
return "\n"
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func FormatComment(config *Config, body string, beenWrapped bool) string {
|
func FormatComment(config *Config, body string, beenWrapped bool) string {
|
||||||
if beenWrapped && !config.Language.OpeningOnSeparateLine {
|
if beenWrapped {
|
||||||
body = strings.TrimPrefix(body, config.Language.Continuation)
|
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)
|
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",
|
strings.TrimRightFunc(config.Language.Continuation, unicode.IsSpace)+"\n",
|
||||||
-1,
|
-1,
|
||||||
)
|
)
|
||||||
|
body = strings.Replace(
|
||||||
|
body,
|
||||||
|
config.Language.Opening+"\n",
|
||||||
|
strings.TrimRightFunc(config.Language.Opening, unicode.IsSpace)+"\n",
|
||||||
|
-1,
|
||||||
|
)
|
||||||
comment.Body = FormatComment(config, body, beenWrapped)
|
comment.Body = FormatComment(config, body, beenWrapped)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,10 @@ type Config struct {
|
||||||
Token string
|
Token string
|
||||||
} `yaml:"gitea"`
|
} `yaml:"gitea"`
|
||||||
Language struct {
|
Language struct {
|
||||||
OpeningOnSeparateLine bool `yaml:"separate_opening"`
|
OnSeparateLine bool `yaml:"on_separate_line"`
|
||||||
Opening string `yaml:"opening"`
|
Opening string `yaml:"opening"`
|
||||||
Continuation string `yaml:"continuation"`
|
Continuation string `yaml:"continuation"`
|
||||||
Closing string `yaml:"closing"`
|
Closing string `yaml:"closing"`
|
||||||
} `yaml:"language"`
|
} `yaml:"language"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue