Merge pull request 'docs' (#4) from docs into main
Reviewed-on: mfocko/frag-review#4
This commit is contained in:
commit
8c2e478ae9
7 changed files with 59 additions and 22 deletions
15
README.md
Normal file
15
README.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
# `frag-review`
|
||||
|
||||
This tool allows syncing reviews from pull requests back into the source files.
|
||||
|
||||
## Configuration
|
||||
|
||||
For each repository you should have separate config that decides which repository is the upstream and
|
||||
how are the review comments to be formatted.
|
||||
|
||||
## Environment variables
|
||||
|
||||
### `GITEA_TOKEN`
|
||||
|
||||
`GITEA_TOKEN` is the only environment variable that is used for Gitea API of the specific instance
|
||||
configured in config.
|
|
@ -4,7 +4,7 @@ gitea:
|
|||
repository: "testing-repo"
|
||||
|
||||
language:
|
||||
separate_opening: true
|
||||
opening: "/**"
|
||||
on_separate_line: true
|
||||
opening: "/** "
|
||||
continuation: " ** "
|
||||
closing: " **/\n"
|
||||
closing: "\n **/\n"
|
|
@ -4,7 +4,7 @@ gitea:
|
|||
repository: "testing-repo"
|
||||
|
||||
language:
|
||||
separate_opening: false
|
||||
opening: "-- #"
|
||||
on_separate_line: false
|
||||
opening: "-- # "
|
||||
continuation: "-- # "
|
||||
closing: ""
|
||||
closing: "\n"
|
|
@ -4,7 +4,7 @@ gitea:
|
|||
repository: "testing-repo"
|
||||
|
||||
language:
|
||||
separate_opening: false
|
||||
opening: "##"
|
||||
on_separate_line: false
|
||||
opening: "## "
|
||||
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,18 +10,18 @@ import (
|
|||
)
|
||||
|
||||
func GetSeparatorForMultiline(config *Config) string {
|
||||
if config.Language.OpeningOnSeparateLine {
|
||||
if config.Language.OnSeparateLine {
|
||||
return "\n"
|
||||
}
|
||||
return " "
|
||||
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)
|
||||
}
|
||||
if !beenWrapped && !config.Language.OpeningOnSeparateLine && !strings.HasSuffix(body, "\n") {
|
||||
body = body + "\n"
|
||||
body = strings.TrimRightFunc(body, unicode.IsSpace)
|
||||
}
|
||||
return fmt.Sprintf("%s%s%s", config.Language.Opening, body, config.Language.Closing)
|
||||
}
|
||||
|
@ -32,8 +32,6 @@ func ProcessComment(config *Config, wrapper *wrap.Wrapper, comment *gitea.PullRe
|
|||
beenWrapped := len(body)+len(config.Language.Opening)+len(config.Language.Closing) > 100
|
||||
if beenWrapped {
|
||||
body = GetSeparatorForMultiline(config) + wrapper.Wrap(body, 100)
|
||||
} else {
|
||||
body = " " + body
|
||||
}
|
||||
|
||||
body = strings.Replace(body, "\r", "", -1)
|
||||
|
@ -43,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)
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ type Config struct {
|
|||
Token string
|
||||
} `yaml:"gitea"`
|
||||
Language struct {
|
||||
OpeningOnSeparateLine bool `yaml:"separate_opening"`
|
||||
OnSeparateLine bool `yaml:"on_separate_line"`
|
||||
Opening string `yaml:"opening"`
|
||||
Continuation string `yaml:"continuation"`
|
||||
Closing string `yaml:"closing"`
|
||||
|
|
Loading…
Reference in a new issue