MishaKav / jest-coverage-comment

Comments a pull request or commit with the jest code coverage badge, full report and tests summary
MIT License
80 stars 34 forks source link

Uncovered line link pointing to invalid page #57

Closed TobiasGoetz closed 1 year ago

TobiasGoetz commented 1 year ago

Expected Behavior

Clicking the line numbers in the added comment shows lines not covered by tests in the code.

Current Behavior

Clicking on line numbers opens another github page but that says: "The repository doesn't contain the /file.js path in '6074679594'"

Steps to Reproduce

  1. Have a private repo
  2. Have 2 branches (main, exploration)
  3. Have basically no files or code on the main branch and all on exploration
  4. Open pull request from exploration to main that triggers the action
  5. Have uncovered lines in your repo
  6. Let action create coverage comment
  7. Click uncovered line number in comment
  8. See issue

Screenshots

image image

MishaKav commented 1 year ago

I don't succeed to reproduce the issue, can you please share it with me:

TobiasGoetz commented 1 year ago

all settings that you pass to uses: MishaKav/jest-coverage-comment@main

My workflow includes the following step for generating the comment

- name: Jest Coverage Comment
        uses: MishaKav/jest-coverage-comment@main
        with:
          coverage-summary-path: ./coverage/coverage-summary.json
          coverage-path: ./coverage.txt
          junitxml-path: ./coverage/junit.xml
          title: Test Summary
          summary-title: Summary
          junitxml-title: Unit Tests

do you know if the link to the file works? or it doesn't work either?

The link to the file doesn't work either.

can you share with me the generated link for some lines? (you can replace the sensitive data if you want with some xxx)

Link to the file: https://github.com/xxx/xxx/blob/e461ec8da9e75b57b81231ccf647baa300b9b6e5/xxx/app.js Link to the lines: https://github.com/xxx/xxx/blob/e461ec8da9e75b57b81231ccf647baa300b9b6e5/xxx/routes/business.js#L79

I forgot to mention that I am running this in a private organization repo and not my private one. Don't know if that may influence the result at all.

MishaKav commented 1 year ago
TobiasGoetz commented 1 year ago
TobiasGoetz commented 1 year ago

The issue seems to be the last(third) xxx. When I remove that one the link works.

MishaKav commented 1 year ago

yes, looks like this is the problem, the action already supports this kind of problem. You just need to path the prefix directory coverage-path-prefix :

- name: Jest Coverage Comment
    uses: MishaKav/jest-coverage-comment@main
    with:
      # your cofings....
      coverage-path-prefix: XXX
TobiasGoetz commented 1 year ago

Hi @MishaKav, thanks for your response.

My issue is that there is a repository name too much at the end. The last xxx in the link (repository name) has to be removed to make it valid. Is it possible to remove part of the link with the coverage-path-prefix setting or only add additional?

MishaKav commented 1 year ago

sure, you can use the coverage-path-prefix as the regular shell command. To remove some directories use ../ before.

TobiasGoetz commented 1 year ago

Hi @MishaKav, it's been a few days and I finally came to test the coverage-path-prefix but it seems to cut off the wrong part.

I added following code to the action

coverage-path-prefix: '../'

Now it cuts of the blob and not the repo, thus it still doesn't work correctly.

Before: https://github.com/[ORG]/[REPO]/blob/599f3XXXd2b9a/[REPO2]/helper/validator.js After adding the prefix option: https://github.com/[ORG]/[REPO]/blob/[REPO2]/helper/validator.js

[ORG] := the organization name [REPO] := The repository name [REPO2] := The repository name XXX := placeholder for more letters and numbers

Is there a way to only remove [REPO2] from the url?

MishaKav commented 1 year ago

Can you try coverage-path-prefix: '../../' ?

Ugikie commented 1 year ago

Any update on this? I am also having this issue

Edit: Actually just figured out a way to get it to work for my case... Basically, my coverage report always includes coverage for the entire project, and so the line number links being based on the commit wasn't leading to the correct page. So I needed the links to include the branch name from the PR, which I managed to do by using:

coverage-path-prefix: ../${{ github.head_ref || github.ref_name }}/src/
TobiasGoetz commented 1 year ago

Can you try coverage-path-prefix: '../../' ?

Using ../../ redirects me to: https://github.com/[ORG]/[REPO]/[REPO2]/helper/validator.js?rgh-link-date=2023-02-20T12%3A08%3A47Z

Edit: The issue is that i can't remove the [REPO2] by using the coverage-path-prefix.