GuangchuangYu/badger

broken link with badger::badge_codecov() - lack codecov token?

fontikar opened this issue ยท 12 comments

Hi @GuangchuangYu! Firstly, thank you for making such a convenient package! I use it regularly for package devs!

I am trying to establish a workflow for setting up:

  • codecov for a simple, public R package using use_coverage(type ="codecov")
  • GitHub Actions CI workflow test-coverage using usethis::use_github_action("test-coverage")
  • a badge for code coverage using badger::badge_codecov(branch="gha")

Unfortunately when I use the output for badger::badge_codecov(branch="gha") e.g. d9e2987 in the README, the badge"shows "unknown: Knitting locally shows the same thing. However navigating to: https://codecov.io/gh/fontikar/ohwhaley/branch/gha/graph/badge.svg, gives me a perfect 100% badge.

I then tried using the codecov badge found in the settings section of the repo which contains my codecov token https://codecov.io/gh/fontikar/ohwhaley/branch/gha/graph/badge.svg?token=XXXXXXXX and it was successful e.g. 701020d

Am I missing a step? I tried adding the codecov token in my codecov.yaml but that didn't work either e.g. 7cd93db

Your advice would be greatly appreciated!

Been having the same issue myself for a while. Do you know what might be going on here @GuangchuangYu ? Thanks!

Hi @GuangchuangYu @wleoncio @rossellhayes, was wondering if any of you (or any of the other Contributors) could speak to this?

Seems to even be an issue on the README of badger:
Screenshot 2023-01-12 at 13 20 12

What happens if you hardcode both ref and branch? Using the example above, I only get a valid output if I specify both:

badger::badge_codecov("rcannood/princurve", branch = "master")
#> [1] "[![](https://app.codecov.io/gh/rcannood/princurve/branch/master/graph/badge.svg)](https://app.codecov.io/gh/rcannood/princurve)"

Created on 2023-01-12 with reprex v2.0.2

Thanks for the reply @wleoncio

Use case 1: princurve

In the case of princurve, I think you get the wrong output with badger::badge_codecov("princurve") because the necessary information can't be pulled from the DESCRIPTION file, and some assumptions are made about the URL (ie omitting the owner's name rcannood). Though leaving ref as the default yield the same result:

out1=badger::badge_codecov("rcannood/princurve", branch = "master")
out2=badger::badge_codecov("rcannood/princurve")

out1==out2
# TRUE

However, when I add the output you generated to a README.Rmd file and try to render it as markdown, it yields a broken link:

Raw markdown text

[![](https://app.codecov.io/gh/rcannood/princurve/branch/master/graph/badge.svg)](https://app.codecov.io/gh/rcannood/princurve)

Markdown rendering

Screenshot 2023-01-12 at 13 58 52

This is odd since navigating to the svg link does indeed show a valid badge:
https://app.codecov.io/gh/rcannood/princurve/branch/master/graph/badge.svg

However, it appears this repo has been deactivated on CodeCov:
https://app.codecov.io/gh/rcannood/princurve

So maybe the issue in this case is the repo being used as example? Though in theory, as long as the badge icon exists, it should still render (it'll just lead to an invalid codecov page).

Use case 2: rworkflows

Let's try with my package instead, rworkflows.
It is currently activated on CodeCov:
https://app.codecov.io/gh/neurogenomics/rworkflows

This yields the wrong link, as it omits the owner name ("neurogenomics"):

badger::badge_codecov(ref="rworkflows")
#  "[![](https://app.codecov.io/gh/rworkflows/branch/master/graph/badge.svg)](https://app.codecov.io/gh/rworkflows)"

This yields the correct link, including the owner name:

badger::badge_codecov()
# "[![](https://app.codecov.io/gh/neurogenomics/rworkflows/branch/master/graph/badge.svg)](https://app.codecov.io/gh/neurogenomics/rworkflows)"

As does specifying the owner/repo explicitly:

badger::badge_codecov(ref="neurogenomics/rworkflows)
#  "[![](https://app.codecov.io/gh/neurogenomics/rworkflows/branch/master/graph/badge.svg)](https://app.codecov.io/gh/neurogenomics/rworkflows)"

The badge icon does indeed exist:
Screenshot 2023-01-12 at 14 10 09

As does the link:
Screenshot 2023-01-12 at 14 10 59

However, just like the princurve output, the badge does not render in markdown.
This also appears to be an issue in html pages, as in my documentation website (notice the broken links in between other badges).
https://neurogenomics.github.io/rworkflows/

Is this a simple markdown syntax issue with the output of badger::badge_codecov? If so, I can't seem to figure it out.

Ok, so I took a look at another repo of mine where the badge works. I don't remember how I figure this out, but dropping app. from the URL works, i.e.:

[![](https://codecov.io/gh/rcannood/princurve/branch/master/graph/badge.svg)](https://codecov.io/gh/rcannood/princurve)

yields

Doing the same for your repo also seems to work:

[![](https://codecov.io/gh/neurogenomics/rworkflows/branch/master/graph/badge.svg)](https://codecov.io/gh/neurogenomics/rworkflows)

outputs

Ah, excellent! Thanks so much for this @wleoncio

So it seems this is just a matter of badger updating the CodeCov domain name. Would you (or one of the other developers) possibly be able to make a push to GitHub and CRAN adding this?

Sure think, I'll issue the PR right away. As for the CRAN release, we're dependent on the maintainer (@GuangchuangYu).

Awesome, thanks @wleoncio !

In the meantime, I'm wrapping a fix around the function when using it within my packages:

gsub("app.codecov.io","codecov.io", ## fix domain name
                         badger::badge_codecov()
                         )

@fontikar, can you confirm that the proposal on PR #46 would solve this issue?

Hi folks! Thanks for everyones efforts and investigations! Its been a while since I looked at this but the issue seemed to resolve itself when I just tried it again

Using badger::badge_codecov() and pasting its output in my README seemed to work well: https://github.com/fontikar/ohwhaley

Recently I taught a [R packages workshop ](https://fontikar.github.io/DIY_Rpkg_GHA/#Covering_your_bases_%F0%9F%AA%A4_with_codecov)which involved setting up CodeCov and adding a badge. The participant's badge all initially didn't render, some says unknown, but after granting third party access and waiting a little while, everyone badge was ok?

Sorry I don't have any further issues and can't provide anything reproducible either at this stage so happy for the PR to go ahead!

That's perfectly fine, thanks for the input! Fingers crossed the fix gets merged and published soon. :)

merge and will be soon available on cran with v = 0.2.3.