Skip to content

Instantly share code, notes, and snippets.

@tmastny
Created May 8, 2020 01:00
Show Gist options
  • Save tmastny/e3eb638c487afb7a816c7a731d730bea to your computer and use it in GitHub Desktop.
Save tmastny/e3eb638c487afb7a816c7a731d730bea to your computer and use it in GitHub Desktop.
# https://github.com/tmastny/sagemaker/blob/4d64375bdf4019cc0bf82a7ff4d6d97ea134f103/R/install.R#L29
library(stringr)
library(git2r)
library(magrittr)
print.github_url <- function(x, ...) {
cat(x)
invisible(x)
}
github_url <- function(path) {
repo_url <- git2r::remote_url() %>%
stringr::str_sub(end = -5)
head <- git2r::repository_head()
commit <- git2r::lookup_commit(head) %>%
as.data.frame()
line_url <- paste0(repo_url, "/blob/", commit$sha, "/", path)
class(line_url) <- c("github_url", class(line_url))
line_url
}
github_url("R/install.R#L29")
github_url("R/install.R") %>%
browseURL()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment