Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Parser comments as a Single Line #106

Closed
anirudhbagri opened this issue Sep 16, 2020 · 10 comments
Closed

Generic Parser comments as a Single Line #106

anirudhbagri opened this issue Sep 16, 2020 · 10 comments
Labels

Comments

@anirudhbagri
Copy link
Contributor

Actual: The violation generated by GenericParser is a POST as a single line whatever might be the source.
Excepted: The comments must be multi-lined if the source has them as multi-lined.

@tomasbjerre
Copy link
Owner

When using Bitbucket Server?

Have you tried passing the -comment-template parameter and surrounding message with ``` before and after ?

The template is documented here:
https://github.com/tomasbjerre/violation-comments-lib

@anirudhbagri
Copy link
Contributor Author

anirudhbagri commented Sep 16, 2020

Yes, bitbucket server.

I am have tried using

-comment-template "```{{violation.message}}```"

and

-comment-template "{{violation.message}}"

both didn't work.

@tomasbjerre
Copy link
Owner

tomasbjerre commented Sep 16, 2020

Turns out this is a feature in Mustache. You can use tripple {{{ and }}} to avoid escaping:

npx violation-comments-to-bitbucket-server-command-line \
 -server-url http://localhost:7990 \
 -username admin \
 -password admin \
 -pk PROJ \
 -rs REPO \
 -prid 1 \
 -keep-old-comments true \
 -create-single-file-comments false \
 -create-comment-with-all-single-file-comments true \
 -comment-only-changed-files false \
 -v "GENERIC" "." ".*eneric\.txt$" "Generic" \
 -comment-template "
message: {{{violation.message}}}
"

image

@anirudhbagri
Copy link
Contributor Author

anirudhbagri commented Sep 18, 2020

This did partially what I expected.

 -comment-template "message: {{{violation.message}}}"

BUT, My file is having lines with multiple spaces in a single line.. like this:

Name                                           Stmts   Miss  Cover
------------------------------------------------------------------
file1                                              0      0   100%
path/to/file2                                      0      0   100%
a/long/file/path/herefile3                        47      5    89%
------------------------------------------------------------------
TOTAL                                            100      8    92%

But, the comment that is posted, has all the white space and line with ---- removed.

This is that I get as comment.

Name Stmts Miss Cover

file1 0 0 100%
path/to/file2 0 0 100%
a/long/file/path/herefile3 47 5 89%

TOTAL 100 8 92%

@tomasbjerre
Copy link
Owner

I created such a file:

Name                                           Stmts   Miss  Cover
------------------------------------------------------------------
file1                                              0      0   100%
path/to/file2                                      0      0   100%
a/long/file/path/herefile3                        47      5    89%
------------------------------------------------------------------
TOTAL                                            100      8    92%

here:
https://github.com/tomasbjerre/violations-test/blob/feature/addingcrap/generic.txt

Reported with

npx violation-comments-to-bitbucket-server-command-line \
 -server-url http://localhost:7990 \
 -username admin \
 -password admin \
 -pk PROJ \
 -rs REPO \
 -prid 1 \
 -keep-old-comments false \
 -create-single-file-comments false \
 -create-comment-with-all-single-file-comments true \
 -comment-only-changed-files false \
 -v "GENERIC" "." ".*eneric\.txt$" "Generic" \
 -comment-template "
message: 
\\\`\\\`\\\`
{{{violation.message}}}
\\\`\\\`\\\`
"

Here:
https://github.com/tomasbjerre/violations-test/blob/feature/addingcrap/report-to-bitbucket-server.sh#L12

And I get:
image

@anirudhbagri
Copy link
Contributor Author

anirudhbagri commented Sep 18, 2020

This is not working for me :(
Instead, it printed like this

message:
`` `
Name Stmts Miss Cover
........

TOTAL 100 8 92%
`` `

BTW, I am pushing this from Jenkins Job script.

This is the exact command:

echo "Posting Test Coverage Report" 
java -jar violation.jar \
-project-key $project_key \
-pull-request-id $pr_id \
-repo-slug $repo_slug \
-server-url $server \
-keep-old-comments false \
-create-single-file-comments false \
-create-comment-with-all-single-file-comments true \
-comment-only-changed-files false \
-keystore-path $path \
-keystore-pass $pass \
-v GENERIC "." ".*/coverage_report\.txt\$" "Code Coverage Reporter" \
-comment-template "
message: 
\\\`\\\`\\\`
{{{violation.message}}}
\\\`\\\`\\\`"
echo "Finished Posting Test Coverage Report"

@anirudhbagri
Copy link
Contributor Author

I see half of the content becoming bold?

image

This is the command I used:

Java -jar violation.jar \ 
 -server-url $server \
 -pk $proj \
 -rs $repo \
 -prid $pr \
 -keep-old-comments false \
 -create-single-file-comments false \
 -create-comment-with-all-single-file-comments true \
 -comment-only-changed-files false \
 -v "GENERIC" "." ".*coverage_report\.txt$" "Generic" \
 -keystore-path $PATH \
 -keystore-pass $PASS \
  -comment-template "
message:
\\\`\\\`\\\`
{{{violation.message}}}
\\\`\\\`\\\`
"

@tomasbjerre
Copy link
Owner

Strange... And if you manually edit the comment, is it still missing spaces?

@anirudhbagri
Copy link
Contributor Author

Yes.

@anirudhbagri
Copy link
Contributor Author

Managed to get it done using this:

Java -jar violation.jar \ 
 -server-url $server \
 -pk $proj \
 -rs $repo \
 -prid $pr \
 -keep-old-comments false \
 -create-single-file-comments false \
 -create-comment-with-all-single-file-comments true \
 -comment-only-changed-files false \
 -v "GENERIC" "." ".*coverage_report\.txt$" "Generic" \
 -keystore-path $PATH \
 -keystore-pass $PASS \
  -comment-template "
message:
~~~
{{{violation.message}}}
~~~
"

Thank you so much @tomasbjerre for helping me out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants