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

full SHA is the default - but prints out the subset #61

Merged
merged 5 commits into from
Dec 4, 2021

Conversation

muschellij2
Copy link
Contributor

This will fail the checks because the default behavior changes. There is no full_sha argument, but I simply changed the printing to first 7 characters, but the object itself still has the full SHA.

@muschellij2 muschellij2 mentioned this pull request Dec 3, 2021
@gaborcsardi
Copy link
Member

Thanks! Do you mind if I simplify the regex + replacement part? It is hard for me to read. (If I can't simplify it, then I'll just leave it as is.)

@muschellij2
Copy link
Contributor Author

Agreed. Here's a quick and dirty explanation

src <- x$source
# look for an @ symbol
# need the / because git@github.com:blah/blah@asdfasdf
  sha_regex <- ".*/(.*@.*)\\)"
  has_sha <- grepl(sha_regex, src)
  src <- src[has_sha]
# src is only those with an @ symbol
  if (any(has_sha)) {
  # Take everything past the /, including SHA
    sub_src <- sub(sha_regex, "\\1", src)
# remove the front (aka the package) or repo/package or repo/package.git
    sha <- sub(".*@", "", sub_src)
    sha <- substr(sha, 1, 7)
# now put the SHA after the @ - need mapply because not vectorized sub
    sha <- mapply(function(orig, replacement) {
      sub("@(.*)", paste0("@", replacement), x = orig)
    }, sub_src, sha)
# vectorized (1-to-1 mapping) and now put the "front" with back (e.g. front is "Github (git@github.com:user" and 
# back is repo@SHA)
    src <- mapply(function(orig, replacement) {
      sub("(.*)/(.*@.*)\\)", paste0("\\1", "/", replacement, ")"), x = orig)
    }, src, sha)
    src <- unname(src)
    x$source[has_sha] <- src
  }

@codecov-commenter
Copy link

codecov-commenter commented Dec 4, 2021

Codecov Report

Merging #61 (249d4fc) into main (473bbf2) will increase coverage by 0.16%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #61      +/-   ##
==========================================
+ Coverage   84.08%   84.24%   +0.16%     
==========================================
  Files          14       14              
  Lines         710      711       +1     
==========================================
+ Hits          597      599       +2     
+ Misses        113      112       -1     
Impacted Files Coverage Δ
R/package-info.R 88.02% <100.00%> (+0.67%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 473bbf2...249d4fc. Read the comment docs.

@gaborcsardi
Copy link
Member

Thanks for the explanation! Maybe I am missing something, but I think we can use this simple substitution, no?

  sub("([0-9a-f]{7})[0-9a-f]{33}", "\\1", x)

https://github.com/r-lib/sessioninfo/pull/61/files#diff-1bf578267d76f849c4d53b6ee6642a93ae375a84ec39b0e6421f05908c894b08R223-R225

I don't think a 40 character long hexa string can appear anywhere else, realistically.

@muschellij2
Copy link
Contributor Author

muschellij2 commented Dec 4, 2021 via email

@gaborcsardi
Copy link
Member

Thanks. Your approach is probably more robust, but I think in this restricted setting my crude approach is fine, and it'll be easier to maintain for me.

Thanks again, I'll merge once the the CI is done!

@gaborcsardi gaborcsardi merged commit 071f38f into r-lib:main Dec 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants