21 changed files with 331 additions and 20 deletions
@ -0,0 +1,7 @@ |
|||
httr::user_agent( |
|||
sprintf( |
|||
"sourcehut package v%s: (<%s>)", |
|||
utils::packageVersion("sourcehut"), |
|||
utils::packageDescription("sourcehut")[["URL"]] |
|||
) |
|||
) -> .SOURCEHUT_UA |
@ -0,0 +1,3 @@ |
|||
sh_authorize <- function(pat = sourcehut_pat()) { |
|||
httr::add_headers(`Authorization` = glue::glue("token {pat}")) |
|||
} |
@ -0,0 +1,37 @@ |
|||
#' Retrieve metadata about yourself or another SourceHut user |
|||
#' |
|||
#' @param username if not `NULL` then a valid SourceHut username |
|||
#' @param pat see [sourcehut_pat()] |
|||
#' @references <https://man.sr.ht/git.sr.ht/api.md> |
|||
#' @export |
|||
git_user <- function(username = NULL, pat = sourcehut_pat()) { |
|||
|
|||
username <- if (!is.null(username)) glue::glue("/{make_canonical(username)}") else "" |
|||
|
|||
route_url <- glue::glue("https://git.sr.ht/api/user{username}") |
|||
|
|||
res <- make_get_request(route_url = route_url, pat = pat) |
|||
process_response(res) |
|||
|
|||
} |
|||
|
|||
#' Retrieve metadata about repositories |
|||
#' |
|||
#' @param username if not `NULL` then a valid SourceHut username |
|||
#' @param next_id if there is a `next` field in the API response and you wish |
|||
#' to paginate through the results, feed the value of `next` to |
|||
#' the `next_id` parameter. |
|||
#' @param pat see [sourcehut_pat()] |
|||
#' @references <https://man.sr.ht/git.sr.ht/api.md> |
|||
#' @export |
|||
git_repos <- function(username = NULL, next_id = 1, pat = sourcehut_pat()) { |
|||
|
|||
username <- if (!is.null(username)) glue::glue("/{make_canonical(username)}") else "" |
|||
|
|||
route_url <- glue::glue("https://git.sr.ht/api{username}/repos") |
|||
|
|||
res <- make_get_request(route_url = route_url, next_id = next_id, pat = pat) |
|||
process_response(res) |
|||
|
|||
} |
|||
|
@ -0,0 +1,3 @@ |
|||
make_canonical <- function(username) { |
|||
if (!startsWith(username, "~")) glue::glue("~{username}") else username |
|||
} |
@ -0,0 +1,17 @@ |
|||
make_get_request <- function(route_url, next_id = NULL, query = list(), ..., pat = sourcehut_pat()) { |
|||
|
|||
if (!is.null(next_id)) { |
|||
if (next_id > 1) { |
|||
query[["start"]] = next_id |
|||
} |
|||
} |
|||
|
|||
httr::GET( |
|||
url = route_url, |
|||
sh_authorize(pat), |
|||
.SOURCEHUT_UA, |
|||
query = query, |
|||
... |
|||
) |
|||
|
|||
} |
@ -0,0 +1,66 @@ |
|||
#' Retrieve metadata about yourself |
|||
#' |
|||
#' @param pat see [sourcehut_pat()] |
|||
#' @references <https://man.sr.ht/meta.sr.ht/user-api.md> |
|||
#' @export |
|||
meta_profile <- function(pat = sourcehut_pat()) { |
|||
|
|||
route_url <- "https://meta.sr.ht/api/user/profile" |
|||
|
|||
res <- make_get_request(route_url = route_url, pat = pat) |
|||
process_response(res) |
|||
|
|||
} |
|||
|
|||
#' Retrieve your audit log |
|||
#' |
|||
#' @inheritParams meta_profile |
|||
#' @export |
|||
meta_audit <- function(pat = sourcehut_pat()) { |
|||
|
|||
route_url <- "https://meta.sr.ht/api/user/audit-log" |
|||
|
|||
res <- make_get_request(route_url = route_url, pat = pat) |
|||
process_response(res) |
|||
|
|||
} |
|||
|
|||
#' Retrieve your SSH keys |
|||
#' |
|||
#' @inheritParams meta_profile |
|||
#' @param id if not `NULL` then a valid key ID |
|||
#' @param next_id if there is a `next` field in the API response and you wish |
|||
#' to paginate through the results, feed the value of `next` to |
|||
#' the `next_id` parameter. |
|||
#' @export |
|||
meta_ssh_keys <- function(id = NULL, next_id = 1, pat = sourcehut_pat()) { |
|||
|
|||
id <- if (!is.null(id)) glue::glue("/{id}") else "" |
|||
|
|||
route_url <- glue::glue("https://meta.sr.ht/api/user/ssh-keys{id}") |
|||
|
|||
res <- make_get_request(route_url = route_url, next_id = next_id, pat = pat) |
|||
process_response(res) |
|||
|
|||
} |
|||
|
|||
#' Retrieve your PGP keys |
|||
#' |
|||
#' @inheritParams meta_profile |
|||
#' @inheritParams meta_ssh_keys |
|||
#' @rdname meta_profile |
|||
#' @export |
|||
meta_pgp_keys <- function(id = NULL, next_id = 1, pat = sourcehut_pat()) { |
|||
|
|||
id <- if (!is.null(id)) glue::glue("/{id}") else "" |
|||
|
|||
route_url <- glue::glue("https://meta.sr.ht/api/user/pgp-keys{id}") |
|||
|
|||
res <- make_get_request(route_url = route_url, next_id = next_id, pat = pat) |
|||
process_response(res) |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,10 @@ |
|||
process_response <- function(res) { |
|||
|
|||
httr::stop_for_status(res) |
|||
|
|||
out <- httr::content(res, as = "text", encoding = "UTF-8") |
|||
out <- jsonlite::fromJSON(out) |
|||
|
|||
out |
|||
|
|||
} |
@ -0,0 +1,32 @@ |
|||
#' Get or set SourceHut Personal Access Token |
|||
#' |
|||
#' @param force force setting a new SourceHut Personal Access Token |
|||
#' @return atomic character vector containing the SourceHut Personal Access Token |
|||
#' @references <https://meta.sr.ht/oauth/personal-token> |
|||
#' @export |
|||
sourcehut_pat <- function(force = FALSE) { |
|||
|
|||
pat <- Sys.getenv('SOURCEHUT_PAT') |
|||
if (!identical(pat, "") && !force) { |
|||
return(pat) |
|||
} |
|||
|
|||
if (!interactive()) { |
|||
stop("Please set env var SOURCEHUT_PAT to your SourceHut Personal Access Token", |
|||
call. = FALSE) |
|||
} |
|||
|
|||
message("Couldn't find env var SOURCEHUT_PAT See ?sourcehut_pat for more details.") |
|||
message("Please enter your SourceHut personal access token and press enter:") |
|||
pat <- readline(": ") |
|||
|
|||
if (identical(pat, "")) { |
|||
stop("SourceHut personal access token entry failed", call. = FALSE) |
|||
} |
|||
|
|||
message("Updating SOURCEHUT_PAT env var") |
|||
Sys.setenv(SOURCEHUT_PAT = pat) |
|||
|
|||
pat |
|||
|
|||
} |
@ -0,0 +1,23 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/git.R |
|||
\name{git_repos} |
|||
\alias{git_repos} |
|||
\title{Retrieve metadata about repositories} |
|||
\usage{ |
|||
git_repos(username = NULL, next_id = 1, pat = sourcehut_pat()) |
|||
} |
|||
\arguments{ |
|||
\item{username}{if not \code{NULL} then a valid SourceHut username} |
|||
|
|||
\item{next_id}{if there is a \code{next} field in the API response and you wish |
|||
to paginate through the results, feed the value of \code{next} to |
|||
the \code{next_id} parameter.} |
|||
|
|||
\item{pat}{see \code{\link[=sourcehut_pat]{sourcehut_pat()}}} |
|||
} |
|||
\description{ |
|||
Retrieve metadata about repositories |
|||
} |
|||
\references{ |
|||
\url{https://man.sr.ht/git.sr.ht/api.md} |
|||
} |
@ -0,0 +1,19 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/git.R |
|||
\name{git_user} |
|||
\alias{git_user} |
|||
\title{Retrieve metadata about yourself or another SourceHut user} |
|||
\usage{ |
|||
git_user(username = NULL, pat = sourcehut_pat()) |
|||
} |
|||
\arguments{ |
|||
\item{username}{if not \code{NULL} then a valid SourceHut username} |
|||
|
|||
\item{pat}{see \code{\link[=sourcehut_pat]{sourcehut_pat()}}} |
|||
} |
|||
\description{ |
|||
Retrieve metadata about yourself or another SourceHut user |
|||
} |
|||
\references{ |
|||
\url{https://man.sr.ht/git.sr.ht/api.md} |
|||
} |
@ -0,0 +1,14 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/meta.R |
|||
\name{meta_audit} |
|||
\alias{meta_audit} |
|||
\title{Retrieve your audit log} |
|||
\usage{ |
|||
meta_audit(pat = sourcehut_pat()) |
|||
} |
|||
\arguments{ |
|||
\item{pat}{see \code{\link[=sourcehut_pat]{sourcehut_pat()}}} |
|||
} |
|||
\description{ |
|||
Retrieve your audit log |
|||
} |
@ -0,0 +1,28 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/meta.R |
|||
\name{meta_profile} |
|||
\alias{meta_profile} |
|||
\alias{meta_pgp_keys} |
|||
\title{Retrieve metadata about yourself} |
|||
\usage{ |
|||
meta_profile(pat = sourcehut_pat()) |
|||
|
|||
meta_pgp_keys(id = NULL, next_id = 1, pat = sourcehut_pat()) |
|||
} |
|||
\arguments{ |
|||
\item{pat}{see \code{\link[=sourcehut_pat]{sourcehut_pat()}}} |
|||
|
|||
\item{id}{if not \code{NULL} then a valid key ID} |
|||
|
|||
\item{next_id}{if there is a \code{next} field in the API response and you wish |
|||
to paginate through the results, feed the value of \code{next} to |
|||
the \code{next_id} parameter.} |
|||
} |
|||
\description{ |
|||
Retrieve metadata about yourself |
|||
|
|||
Retrieve your PGP keys |
|||
} |
|||
\references{ |
|||
\url{https://man.sr.ht/meta.sr.ht/user-api.md} |
|||
} |
@ -0,0 +1,20 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/meta.R |
|||
\name{meta_ssh_keys} |
|||
\alias{meta_ssh_keys} |
|||
\title{Retrieve your SSH keys} |
|||
\usage{ |
|||
meta_ssh_keys(id = NULL, next_id = 1, pat = sourcehut_pat()) |
|||
} |
|||
\arguments{ |
|||
\item{id}{if not \code{NULL} then a valid key ID} |
|||
|
|||
\item{next_id}{if there is a \code{next} field in the API response and you wish |
|||
to paginate through the results, feed the value of \code{next} to |
|||
the \code{next_id} parameter.} |
|||
|
|||
\item{pat}{see \code{\link[=sourcehut_pat]{sourcehut_pat()}}} |
|||
} |
|||
\description{ |
|||
Retrieve your SSH keys |
|||
} |
@ -0,0 +1,20 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/sourcehut-pat.R |
|||
\name{sourcehut_pat} |
|||
\alias{sourcehut_pat} |
|||
\title{Get or set SourceHut Personal Access Token} |
|||
\usage{ |
|||
sourcehut_pat(force = FALSE) |
|||
} |
|||
\arguments{ |
|||
\item{force}{force setting a new SourceHut Personal Access Token} |
|||
} |
|||
\value{ |
|||
atomic character vector containing the SourceHut Personal Access Token |
|||
} |
|||
\description{ |
|||
Get or set SourceHut Personal Access Token |
|||
} |
|||
\references{ |
|||
\url{https://meta.sr.ht/oauth/personal-token} |
|||
} |
Loading…
Reference in new issue