├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── NAMESPACE ├── NEWS ├── R ├── account.R ├── auth.R ├── builds.R ├── caches.R ├── environment.R ├── hooks.R ├── http.R ├── jobs.R ├── lint.R ├── repo.R ├── requests.R └── utils.R ├── README.md ├── drat.sh ├── inst └── CITATION ├── man ├── auth_travis.Rd ├── cancel_build.Rd ├── get_accounts.Rd ├── get_annotations.Rd ├── get_branch.Rd ├── get_broadcasts.Rd ├── get_builds.Rd ├── get_caches.Rd ├── get_encryption_key.Rd ├── get_env_vars.Rd ├── get_hooks.Rd ├── get_job.Rd ├── get_logs.Rd ├── get_permissions.Rd ├── get_repo.Rd ├── get_repo_settings.Rd ├── get_requests.Rd ├── get_users.Rd ├── travisHTTP.Rd ├── travis_lint.Rd └── travisci.Rd └── tests ├── testthat.R └── testthat └── tests.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | .travis.yml 2 | README.Rmd 3 | drat.sh 4 | knitreadme.sh 5 | ^.*\.Rproj$ 6 | ^\.Rproj\.user$ 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Renviron 2 | .Rproj.user 3 | .Rhistory 4 | .RData 5 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: travisci 2 | Type: Package 3 | Title: Travis-CI API Client Package 4 | Version: 0.1.10 5 | Date: 2017-07-02 6 | Authors@R: c(person("Thomas J.", "Leeper", role = c("aut", "cre"), 7 | email = "thosjleeper@gmail.com")) 8 | Maintainer: Thomas J. Leeper 9 | Description: A simple client for the Travis-CI 'API'. 10 | License: GPL (>= 2) 11 | URL: https://github.com/cloudyr/travisci 12 | BugReports: https://github.com/cloudyr/travisci/issues 13 | Imports: 14 | httr, 15 | jsonlite 16 | Enhances: devtools 17 | Suggests: 18 | testthat 19 | RoxygenNote: 6.0.1 20 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(print,travis_account) 4 | S3method(print,travis_branch) 5 | S3method(print,travis_build) 6 | S3method(print,travis_commit) 7 | S3method(print,travis_envvar) 8 | S3method(print,travis_hook) 9 | S3method(print,travis_job) 10 | S3method(print,travis_repo) 11 | S3method(print,travis_user) 12 | export(add_env_vars) 13 | export(auth_travis) 14 | export(cancel_build) 15 | export(cancel_job) 16 | export(create_annotation) 17 | export(delete_caches) 18 | export(delete_env_var) 19 | export(disable_hook) 20 | export(enable_hook) 21 | export(get_accounts) 22 | export(get_annotations) 23 | export(get_branch) 24 | export(get_broadcasts) 25 | export(get_builds) 26 | export(get_caches) 27 | export(get_encryption_key) 28 | export(get_env_vars) 29 | export(get_hooks) 30 | export(get_job) 31 | export(get_logs) 32 | export(get_permissions) 33 | export(get_repo) 34 | export(get_repo_settings) 35 | export(get_requests) 36 | export(get_users) 37 | export(restart_build) 38 | export(restart_job) 39 | export(restart_last_build) 40 | export(set_encryption_key) 41 | export(set_repo_settings) 42 | export(sync_users) 43 | export(travisHTTP) 44 | export(travis_lint) 45 | export(update_env_vars) 46 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | # CHANGES TO travisci 0.2 # 2 | 3 | * Added S3 print methods for most object classes. 4 | 5 | # CHANGES TO travisci 0.1 # 6 | 7 | * Initial release. 8 | -------------------------------------------------------------------------------- /R/account.R: -------------------------------------------------------------------------------- 1 | #' @title Travis-CI API Client 2 | #' @description This package provides functionality for interacting with the Travis-CI API. Travis-CI is a continuous integration service that allows for automated testing of software each time that software is publicly committed to a repository on GitHub. Setting up Travis-CI is quite simple, requiring only a GitHub account, some public (or private) repository hosted on GitHub, and logging into to Travis to link it to that repository. Travis-CI provides \href{http://docs.travis-ci.com/user/languages/r/}{straightforward documentation} for configuring your repository to interact with Travis via a \samp{.travis.yml} file added to your repository. 3 | #' 4 | #' Once you have your Travis-CI account configured online, you can use this package to interact with and perform all operations on your Travis builds that you would normally perform by the Travis website. This includes monitoring builds, modifying build environment settings and environment variables, and cancelling or restarting builds. 5 | #' 6 | #' Before you can use the package, you need to authenticate against the Travis-CI API using \code{\link{auth_travis}}, using your GitHub username and password, a GitHub personal access token, or a previously generated Travis API token (see examples, below). 7 | #' 8 | #' @examples 9 | #' \dontrun{ 10 | #' # authenticate using your GitHub login credentials 11 | #' auth_travis("username", "password") 12 | #' 13 | #' # authenticate using a GitHub token explicitly 14 | #' auth_travis(gh_token = "githubtokenvalue") 15 | #' 16 | #' # authenticate using a stored environment variables 17 | #' Sys.setenv("GITHUB_TOKEN" = "githubtokenvalue") 18 | #' 19 | #' # check to see if you've authenticated correctly 20 | #' get_accounts() 21 | #' } 22 | #' 23 | #' @docType package 24 | #' @seealso \code{\link{auth_travis}}, \code{\link{get_accounts}}, \code{\link{get_repo}} 25 | #' @name travisci 26 | NULL 27 | 28 | #' @title Get Broadcasts 29 | #' @description Retrieve Travis-CI broadcasts 30 | #' @details This is not particularly useful from an R perspective, but it will retrieve \dQuote{broadcasts} or news from Travis-CI. 31 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 32 | #' @return A list. 33 | #' @examples 34 | #' \dontrun{ 35 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 36 | #' auth_travis() 37 | #' 38 | #' # get broadcasts 39 | #' get_broadcasts() 40 | #' } 41 | #' @export 42 | get_broadcasts <- function(...) { 43 | travisHTTP("GET", path = "/broadcasts") 44 | } 45 | 46 | #' @title Get Travis Accounts 47 | #' @description Retrieve GitHub accounts linked to the authenticated Travis user. 48 | #' @details This is probably the closest thing to a \dQuote{Hello World!} on the API. It provides information about what accounts have been linked between GitHub and Travis, such as organization accounts that the user is a member of. 49 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 50 | #' @return A list. 51 | #' @examples 52 | #' \dontrun{ 53 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 54 | #' auth_travis() 55 | #' 56 | #' # get travis accounts 57 | #' get_accounts() 58 | #' } 59 | #' @seealso \code{\link{get_users}}, \code{\link{get_permissions}} 60 | #' @export 61 | get_accounts <- function(...) { 62 | lapply(travisHTTP("GET", path = "/accounts", ...)$accounts, `class<-`, "travis_account") 63 | } 64 | 65 | #' @export 66 | print.travis_account <- function(x, ...) { 67 | cat("Account (", x$id, "): ", x$name, "\n", sep = "") 68 | cat("Type: ", x$type, "\n", sep = "") 69 | cat("Login: ", x$login, "\n", sep = "") 70 | cat("Repos: ", x$repos_count, "\n", sep = "") 71 | invisible(x) 72 | } 73 | 74 | #' @title Get GitHub Permissions 75 | #' @description Retrieve GitHub permissions that have been authorized to Travis-CI. 76 | #' @details This can be useful for checking what access rights have been granted to Travis-CI by GitHub. If for some reason Travis-CI isn't working, this might be useful for troubleshooting but probably not otherwise. 77 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 78 | #' @return A list. 79 | #' @examples 80 | #' \dontrun{ 81 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 82 | #' auth_travis() 83 | #' 84 | #' # get travis accounts 85 | #' get_permissions() 86 | #' } 87 | #' @seealso \code{\link{get_accounts}}, \code{\link{get_users}}, \code{\link{get_requests}} (to troubleshoot specific code pushes) 88 | #' @export 89 | get_permissions <- function(...) { 90 | travisHTTP("GET", path = "/users/permissions", ...) 91 | } 92 | 93 | 94 | #' @title Travis CI Users 95 | #' @description Retrieve and sync Travis CI users 96 | #' @details \code{get_users} retrieves information about GitHub users attached to a Travis account. \code{sync_users} syncs Travis's local cache of users against GitHub. 97 | #' @param user Optionally, an integer specifying a user ID, or a character string specifying a user login, or a \dQuote{travis_user} object. If missing, all users are returned. 98 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 99 | #' @return A list. 100 | #' @examples 101 | #' \dontrun{ 102 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 103 | #' auth_travis() 104 | #' 105 | #' # sync users 106 | #' sync_users() 107 | #' 108 | #' # get travis users 109 | #' get_users() 110 | #' 111 | #' # get specific user 112 | #' get_user("userid") 113 | #' } 114 | #' @seealso \code{\link{get_accounts}}, \code{\link{get_permissions}} 115 | #' @export 116 | get_users <- function(user, ...) { 117 | if (!missing(user)) { 118 | if (inherits(user, "travis_user")) { 119 | user <- user$id 120 | } else if (inherits(user, "character")) { 121 | users <- get_users(...) 122 | logins <- lapply(users, `[[`, "login") 123 | user <- users[[which(logins == user)]][["id"]] 124 | } 125 | out <- travisHTTP("GET", path = paste0("/users/", user), ...) 126 | } else { 127 | out <- travisHTTP("GET", path = paste0("/users"), ...) 128 | } 129 | lapply(out, `class<-`, "travis_user") 130 | } 131 | 132 | #' @export 133 | print.travis_user <- function(x, ...) { 134 | cat("User (", x$id, "): ", x$name, "\n", sep = "") 135 | cat("Login: ", x$login, "\n", sep = "") 136 | cat("Email: ", x$email, "\n", sep = "") 137 | cat("Correct scopes: ", as.character(x$correct_scopes), "\n", sep = "") 138 | invisible(x) 139 | } 140 | 141 | #' @export 142 | #' @rdname get_users 143 | sync_users <- function(...) { 144 | travisHTTP("POST", path = paste0("/users/sync"), ...)$result 145 | } 146 | -------------------------------------------------------------------------------- /R/auth.R: -------------------------------------------------------------------------------- 1 | #' @title Authorize Travis-CI API 2 | #' @description Initialize a Travis-CI API token 3 | #' @param username A character string containing a GitHub username. 4 | #' @param password A character string containing a GitHub password for account \code{username}. 5 | #' @param setenv A logical indicating whether to set the \env{TRAVIS_CI_TOKEN} environment variable. If \code{FALSE}, this will have to be passed to all other functions. 6 | #' @param clean A logical specifying whether to delete the temporarily generated GitHub personal access token from the GitHub account. Deafult is \code{TRUE} if \code{username} is specified. This is ignored if passing a GitHub token directly. 7 | #' @param force A logical indicating whether to force the operation and override an already stored value in \env{TRAVIS_CI_TOKEN}. 8 | #' @param gh_token An optional character string specifying a GitHub personal access token. This is ignored if \code{username} is supplied. 9 | #' @param base A character string specifying the base URL for the API. By default this is \url{https://api.travis-ci.org}, but may need to be changed if using a Travis Pro or enterprise account. 10 | #' @details Using the Travis-CI API requires an API token (see \href{http://docs.travis-ci.com/api/#authentication}{API documentation} for details). This function implements a sort of handshake that uses a GitHub personal access token to generate a Travis token (to store in an environment variable, \env{TRAVIS_CI_TOKEN}) or, alternatively, uses a GitHub username and password pair to generate such a token, conduct the handshake, and then cleanup the generated, temporary token. The easiest way to use the function is to set the \env{GITHUB_TOKEN} and \env{GITHUB_PAT} environment variables, then simply call \code{auth_travis()} with no arguments, but see examples. 11 | #' @return A character string containing the Travis-CI API token, invisibly. 12 | #' @examples 13 | #' \dontrun{ 14 | #' # authenticate using GitHub login credentials 15 | #' auth_travis("username", "password") 16 | #' 17 | #' # authenticate using a GitHub personal access token 18 | #' auth_travis(gh_token = "example token") 19 | #' 20 | #' # set GITHUB_TOKEN environment variable to authenticate 21 | #' Sys.setenv("GITHUB_TOKEN" = "example token") 22 | #' auth_travis() 23 | #' } 24 | #' 25 | #' @seealso \code{\link{travisHTTP}} 26 | #' @export 27 | auth_travis <- 28 | function(username, 29 | password, 30 | setenv = TRUE, 31 | clean = !missing(username), 32 | force = FALSE, 33 | gh_token = c(Sys.getenv("GITHUB_TOKEN"), Sys.getenv("GITHUB_PAT")), 34 | base = c("https://api.travis-ci.org", "https://api.travis-ci.com")) { 35 | if (Sys.getenv("TRAVIS_CI_TOKEN") != "" && !isTRUE(force)) { 36 | message("Environment variable 'TRAVIS_CI_TOKEN' is already set.") 37 | return(invisible(NULL)) 38 | } 39 | gh <- gh_token[gh_token != ""][1] 40 | if (!missing(username)) { 41 | b <- list(scopes = c("read:org", "user:email", "repo_deployment", "repo:status", "write:repo_hook"), 42 | note = "temporary token to auth against travis") 43 | p <- httr::POST("https://api.github.com/authorizations", 44 | httr::authenticate(username, password), 45 | body = b, encode = "json") 46 | gh <- httr::content(p)$token 47 | if (clean) { 48 | on.exit(httr::DELETE(paste0("https://api.github.com/authorizations/", 49 | httr::content(p)[["id"]]), 50 | httr::authenticate(username, password), encode = "json")) 51 | } 52 | } 53 | if (is.na(gh) || gh == "") { 54 | stop("No value supplied for 'gh_token' or available\n in environment variable 'GITHUB_TOKEN'", call. = FALSE) 55 | } 56 | base <- match.arg(base) 57 | r <- httr::POST(paste0(base, "/auth/github"), 58 | httr::add_headers(Accept = "application/vnd.travis-ci.2+json"), 59 | body = list(github_token = gh), encode = "json") 60 | travis_token <- jsonlite::fromJSON(httr::content(r, "text", encoding = "UTF-8"))[["access_token"]] 61 | if (setenv) { 62 | Sys.setenv("TRAVIS_CI_TOKEN" = travis_token) 63 | } 64 | return(invisible(travis_token)) 65 | } 66 | -------------------------------------------------------------------------------- /R/builds.R: -------------------------------------------------------------------------------- 1 | #' @title Get Builds 2 | #' @description Retrieve Travis Builds 3 | #' @details This can retrieve a list of recent builds (across all repos), recent builds for a specific repo (if \code{repo} is specified), or information about a specific build if \code{build} is (or both \code{repo} and \code{build} are) specified. 4 | #' @param repo Optionally, a numeric repository ID (such as returned by this function), a character string specifying a GitHub repository \dQuote{slug} (e.g., \samp{ghusername/ghreponame}), or an object of class \dQuote{travis_repo}. 5 | #' @param build Optionally, a numeric value specifying a build number, or an object of class \dQuote{travis_build}. 6 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 7 | #' @return A list. 8 | #' @seealso \code{\link{cancel_build}}, \code{\link{restart_build}} 9 | #' @examples 10 | #' \dontrun{ 11 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 12 | #' auth_travis() 13 | #' 14 | #' # get all recent builds 15 | #' g <- get_builds() 16 | #' 17 | #' # get builds for a specific repo 18 | #' get_builds(repo = "cloudyr/travisci") 19 | #' get_builds(repo = g[[1]]$repository_id) 20 | #' 21 | #' # get a specific build 22 | #' get_builds(build = g[[1]]$id) 23 | #' } 24 | #' @seealso \code{\link{cancel_build}}, \code{\link{get_repo}}, \code{\link{get_branch}} 25 | #' @export 26 | get_builds <- function(repo, build, ...) { 27 | if (!missing(repo) & !missing(build)) { 28 | repo <- slug_to_id(repo) 29 | if (inherits(build, "travis_build")) { 30 | build <- build$id 31 | } 32 | out <- travisHTTP("GET", path = paste0("/repos/", repo, "/builds/", build), ...) 33 | structure(list(build = `class<-`(out$builds, "travis_build"), 34 | commit = `class<-`(out$commit, "travis_commit"), 35 | jobs = lapply(out$jobs, `class<-`, "travis_job"), 36 | annotations = out$annotations)) 37 | } else if (!missing(repo)) { 38 | repo <- slug_to_id(repo) 39 | out <- travisHTTP("GET", path = paste0("/repos/", repo, "/builds"), ...) 40 | structure(list(builds = lapply(out$builds, `class<-`, "travis_build"), 41 | commits = lapply(out$commits, `class<-`, "travis_commit"))) 42 | } else if (!missing(build)) { 43 | if (inherits(build, "travis_build")) { 44 | build <- build$id 45 | } 46 | out <- travisHTTP("GET", path = paste0("/builds/", build), ...) 47 | structure(list(build = `class<-`(out$builds, "travis_build"), 48 | commit = `class<-`(out$commit, "travis_commit"), 49 | jobs = lapply(out$jobs, `class<-`, "travis_job"), 50 | annotations = out$annotations)) 51 | } else { 52 | out <- travisHTTP("GET", path = "/builds", ...) 53 | structure(list(builds = lapply(out$builds, `class<-`, "travis_build"), 54 | commits = lapply(out$commits, `class<-`, "travis_commit"))) 55 | 56 | } 57 | } 58 | 59 | #' @export 60 | print.travis_build <- function(x, ...) { 61 | cat("Build (", x$id, ") state: ", x$state, "\n", sep = "") 62 | cat("Type: ", x$event_type, "\n", sep = "") 63 | if (x$pull_request) { 64 | cat(" PR (", x$pull_request_number, "): ", x$pull_request_title, "\n", sep = "") 65 | } 66 | cat("Repo: ", x$repository_id, "\n", sep = "") 67 | cat("Commit: ", x$commit_id, "\n", sep = "") 68 | cat("Started: ", x$started_at, "\n", sep = "") 69 | cat("Finished: ", x$finished_at, "\n", sep = "") 70 | invisible(x) 71 | } 72 | 73 | #' @export 74 | print.travis_commit <- function(x, ...) { 75 | cat("Commit (", x$id, "): ", x$message, "\n", sep = "") 76 | cat("Author: ", x$author_name, " (", x$author_email, ")\n", sep = "") 77 | cat("SHA: ", x$sha, "\n", sep = "") 78 | cat("Commited: ", x$committed_at, "\n", sep = "") 79 | invisible(x) 80 | } 81 | 82 | #' @export 83 | print.travis_job <- function(x, ...) { 84 | cat("Job (", x$id, ") state: ", x$state, "\n", sep = "") 85 | cat("Repo (", x$repository_id, "): ", x$repository_slug, "\n", sep = "") 86 | cat("Build: ", x$build_id, ", Commit: ", x$commit_id, "\n", sep = "") 87 | cat("Started: ", x$started_at, "\n", sep = "") 88 | cat("Finished: ", x$finished_at, "\n", sep = "") 89 | invisible(x) 90 | } 91 | 92 | #' @title Cancel and Restart Builds 93 | #' @description Cancel and restart Travis-CI builds 94 | #' @details \code{cancel_build} will cancel a given build. \code{restart_build} will restart a cancelled build. 95 | #' @param build A numeric value specifying a build number or an object of class \dQuote{travis_build}. (For \code{restart_last_build}, this can also be a character string specifying a GitHub repository, such as \dQuote{user/repo}.) 96 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 97 | #' @return For \code{cancel_build} and \code{restart_build}, a logical that is \code{TRUE} if the operation succeeded. For \code{restart_last_build}, the build number is stored in the \code{build_id} attributes. 98 | #' @seealso \code{\link{get_builds}} 99 | #' @examples 100 | #' \dontrun{ 101 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 102 | #' auth_travis() 103 | #' 104 | #' # get all recent builds for this repo 105 | #' g <- get_builds(repo = "cloudyr/travisci") 106 | #' 107 | #' # cancel most recent build 108 | #' cancel_build(g[[1]]$id) 109 | #' 110 | #' # restart that build 111 | #' restart_build(g[[1]]$id) 112 | #' } 113 | #' @export 114 | cancel_build <- function(build, ...) { 115 | if (inherits(build, "travis_build")) { 116 | build <- build$id 117 | } 118 | out <- travisHTTP("POST", path = paste0("/builds/", build, "/cancel"), ...) 119 | if (is.null(out)) { 120 | TRUE 121 | } else { 122 | FALSE 123 | } 124 | } 125 | 126 | #' @rdname cancel_build 127 | #' @export 128 | restart_build <- function(build, ...) { 129 | if (inherits(build, "travis_build")) { 130 | build <- build$id 131 | } 132 | out <- travisHTTP("POST", path = paste0("/builds/", build, "/restart"), ...) 133 | if (out$result) { 134 | TRUE 135 | } else { 136 | FALSE 137 | } 138 | } 139 | 140 | #' @rdname cancel_build 141 | #' @export 142 | restart_last_build <- function(build, ...) { 143 | if (inherits(build, "travis_build")) { 144 | b <- build$id 145 | } else if (is.numeric(build)) { 146 | b <- build 147 | } else { 148 | b <- get_builds(build)$builds[[1]]$id 149 | } 150 | structure(restart_build(b), build_id = b) 151 | } 152 | -------------------------------------------------------------------------------- /R/caches.R: -------------------------------------------------------------------------------- 1 | #' @title Get and Delete Cache 2 | #' @description Retrieve the Travis-CI cache, or delete it. 3 | #' @details \code{get_caches} retrieves caches for a repository. \code{delete_caches} deletes all caches for a repository. 4 | #' @param repo A numeric repository ID (such as returned by this function), a character string specifying a GitHub repository \dQuote{slug} (e.g., \samp{ghusername/ghreponame}), or an object of class \dQuote{travis_repo}. 5 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 6 | #' @return A list. 7 | #' @examples 8 | #' \dontrun{ 9 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 10 | #' auth_travis() 11 | #' 12 | #' # get caches for a repo 13 | #' get_caches("cloudyr/travisci") 14 | #' 15 | #' # delete caches 16 | #' delete_caches("cloudyr/travisci") 17 | #' } 18 | #' @export 19 | get_caches <- function(repo, ...) { 20 | repo <- slug_to_id(repo) 21 | travisHTTP("GET", path = paste0("/repos/", repo, "/caches"), ...) 22 | } 23 | 24 | #' @export 25 | #' @rdname get_caches 26 | delete_caches <- function(repo, ...) { 27 | repo <- slug_to_id(repo) 28 | travisHTTP("DELETE", path = paste0("/repos/", repo, "/caches"), ...) 29 | } 30 | -------------------------------------------------------------------------------- /R/environment.R: -------------------------------------------------------------------------------- 1 | #' @title Manage environment variables 2 | #' @description These functions retrieve and modify environment variables for the Travis-CI build environment, as a possible alternative to specifying them in a \samp{.travis.yml} file. 3 | #' @details This can be useful for checking, creating, updating, or deleting environment variables used as build settings. See href{http://docs.travis-ci.com/user/environment-variables/}{the API documentation} for full details. 4 | #' @param repo A character string specifying a repo slug (i.e., \samp{cloudyr/travisci}) a numeric Travis-CI repository ID, or an object of class \dQuote{travis_repo}. If a slug is used, it will be implicitly converted to a repository ID in some cases where only the latter is accepted. 5 | #' @param id An alphanumeric ID for a given environment variable or an object of class \dQuote{travis_envvar}, for example as returned by one of these functions. 6 | #' @param evar A list of environment variables as key-value pairs. 7 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 8 | #' @return A list of objects of class \dQuote{travis_envvar}, except for \code{delete_env_vars}, which returns a logical. 9 | #' @seealso \code{\link{get_encryption_key}}, for handling encrypted environment variables 10 | #' @examples 11 | #' \dontrun{ 12 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 13 | #' auth_travis() 14 | #' 15 | #' # get environment variables for a repo 16 | #' get_env_vars("cloudyr/travisci") 17 | #' 18 | #' # get a specific environment variable based on its ID 19 | #' get_env_vars("cloudyr/travisci", id = 12345) 20 | #' 21 | #' # set environment variables 22 | #' e <- add_env_vars("cloudyr/travisci", var = list(VAR1 = "value1", VAR2 = "value2")) 23 | #' 24 | #' # update an environment variable 25 | #' update_env_vars("cloudyr/travisci", id = e$id, 26 | #' var = list(VAR1 = "newvalue") 27 | #' 28 | #' # delete an environment variable 29 | #' delete_env_vars("cloudyr/travisci", id = e$id) 30 | #' 31 | #' } 32 | #' @export 33 | get_env_vars <- function(repo, id, ...) { 34 | if (missing(id)) { 35 | out <- travisHTTP("GET", path = paste0("/settings/env_vars"), query = list(repository_id = slug_to_id(repo)), ...) 36 | } else { 37 | out <- travisHTTP("GET", path = paste0("/settings/env_vars/", id), query = list(repository_id = slug_to_id(repo)), ...) 38 | } 39 | if (length(out[[1]])) { 40 | lapply(out[[1]], `class<-`, "travis_envvar") 41 | } else { 42 | out[[1]] 43 | } 44 | } 45 | 46 | #' @export 47 | #' @rdname get_env_vars 48 | add_env_vars <- function(repo, evar, public = TRUE, ...) { 49 | out <- travisHTTP("POST", path = paste0("/settings/env_vars"), query = list(repository_id = slug_to_id(repo)), 50 | body = list("env_var" = list(name = names(evar), value = as.character(evar), public = public)), 51 | encode = "json", ...) 52 | list(structure(out[[1]], class = "travis_envvar")) 53 | } 54 | 55 | #' @export 56 | #' @rdname get_env_vars 57 | update_env_vars <- function(repo, id, evar, public, ...) { 58 | if (inherits(id, "travis_envvar")) { 59 | repo <- id[["repository_id"]] 60 | if (missing(evar)) { 61 | b <- list("env_var" = list(name = id[["name"]], value = id[["value"]])) 62 | } else { 63 | b <- list("env_var" = list(name = names(evar), value = as.character(evar))) 64 | } 65 | if (missing(public)) { 66 | b[[1]][["public"]] <- id[["public"]] 67 | } else { 68 | b[[1]][["public"]] <- public 69 | } 70 | id <- id[["id"]] 71 | } else { 72 | b <- list("env_var" = list(name = names(evar), value = as.character(evar), public = public)) 73 | } 74 | out <- travisHTTP("PATCH", path = paste0("/settings/env_vars/", id), query = list(repository_id = slug_to_id(repo)), 75 | body = b, 76 | encode = "json", ...) 77 | list(structure(out[[1]], class = "travis_envvar")) 78 | } 79 | 80 | #' @export 81 | #' @rdname get_env_vars 82 | delete_env_var <- function(repo, id, ...) { 83 | if (inherits(id, "travis_envvar")) { 84 | repo <- id[["repository_id"]] 85 | id <- id[["id"]] 86 | } 87 | travisHTTP("DELETE", path = paste0("/settings/env_vars/", id), query = list(repository_id = slug_to_id(repo)), ...) 88 | } 89 | 90 | #' @export 91 | print.travis_envvar <- function(x, ...) { 92 | cat("Repo:", x[["repository_id"]], "\n") 93 | cat("Environment Variable (id):", x[["id"]], "\n") 94 | cat(x[["name"]], ": ", x[["value"]], "\n", sep = "") 95 | cat("Public?", x[["public"]], "\n") 96 | invisible(x) 97 | } 98 | 99 | #' @title Manage encrypted environment variables 100 | #' @description Retrieve and refresh the public key used for encryption. 101 | #' @details These functions retrieve and refresh the public key used for encrypting secure environment variables for the Travis-CI build environment. This is probably more easily handled using the travis command-line tools, but it is also an implemented feature of the API and the functionality may be expanded in the future. See href{http://docs.travis-ci.com/user/encryption-keys/}{the API documentation} for full details. \code{get_encryption_key} retrieves the current, repository-specific public key. \code{set_encryption_key} resets the key and returns its value. 102 | #' @param repo A character string specifying a repo slug (i.e., \samp{cloudyr/travisci}), a numeric Travis-CI repository ID, or an object of class \dQuote{travis_repo}. If a slug is used, it will be implicitly converted to a repository ID in some cases where only the latter is accepted. 103 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 104 | #' @return A list. 105 | #' @seealso \code{\link{get_env_vars}} 106 | #' @examples 107 | #' \dontrun{ 108 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 109 | #' auth_travis() 110 | #' 111 | #' # get current public key 112 | #' get_encryption_key("cloudyr/travisci") 113 | #' 114 | #' # reset public key and retrieve the new value 115 | #' set_encryption_key("cloudyr/travisci") 116 | #' } 117 | #' @export 118 | get_encryption_key <- function(repo, ...) { 119 | travisHTTP("GET", path = paste0("/repos/", slug_to_id(repo), "/key"), ...) 120 | } 121 | 122 | #' @export 123 | #' @rdname get_encryption_key 124 | set_encryption_key <- function(repo, ...) { 125 | travisHTTP("POST", path = paste0("/repos/", slug_to_id(repo), "/key"), ...) 126 | } 127 | -------------------------------------------------------------------------------- /R/hooks.R: -------------------------------------------------------------------------------- 1 | #' @title Get Hooks 2 | #' @description Retrieve a list of Travis-CI web hooks. 3 | #' @details \code{get_hooks} retrieves a list of hooks (i.e., repositories that are linked to Travis CI). \code{enable_hook} and \code{disable_hook} enable and disable hooks, respectively. 4 | #' @param hook A numeric hook ID, or an object of class \dQuote{travis_hook}. 5 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 6 | #' @return A list. 7 | #' @examples 8 | #' \dontrun{ 9 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 10 | #' auth_travis() 11 | #' 12 | #' # get list of hooks 13 | #' get_hooks() 14 | #' 15 | #' # disable a hook 16 | #' disable_hook("12345") 17 | #' 18 | #' # enable a hook 19 | #' enable_hook("1235") 20 | #' } 21 | #' @export 22 | get_hooks <- function(...) { 23 | out <- travisHTTP("GET", path = paste0("/hooks"), ...)$hooks 24 | lapply(out, `class<-`, "travis_hook") 25 | } 26 | 27 | #' @export 28 | print.travis_hook <- function(x, ...) { 29 | cat("Hook (", x$id, "): ", x$name, "\n", sep = "") 30 | cat("Owner: ", x$owner_name, "\n", sep = "") 31 | cat("Description: ", x$description, "\n", sep = "") 32 | cat("Active: ", as.character(x$active), "\n", sep = "") 33 | cat("Private: ", as.character(x$active), "\n", sep = "") 34 | cat("Admin: ", as.character(x$active), "\n", sep = "") 35 | invisible(x) 36 | } 37 | 38 | #' @export 39 | #' @rdname get_hooks 40 | enable_hook <- function(hook, ...) { 41 | if (inherits(hook, "travis_hook")) { 42 | hook <- hook$id 43 | } 44 | travisHTTP("PUT", path = paste0("/hooks/"), 45 | body = list(hook = list(id = hook, active = "true")), 46 | encode = "json", ...)$result 47 | } 48 | 49 | #' @export 50 | #' @rdname get_hooks 51 | disable_hook <- function(hook, ...) { 52 | if (inherits(hook, "travis_hook")) { 53 | hook <- hook$id 54 | } 55 | travisHTTP("PUT", path = paste0("/hooks/"), 56 | body = list(hook = list(id = hook, active = "false")), 57 | encode = "json", ...)$result 58 | } 59 | -------------------------------------------------------------------------------- /R/http.R: -------------------------------------------------------------------------------- 1 | #' @title Travis-CI HTTP Requests 2 | #' @description This is the workhorse function for executing API requests for Travis-CI. 3 | #' @details This is mostly an internal function for executing API requests. In almost all cases, users do not need to access this directly. 4 | #' @param verb A character string containing an HTTP verb, defaulting to \dQuote{GET}. 5 | #' @param path A character string with the API endpoint (should begin with a slash). 6 | #' @param query A list specifying any query string arguments to pass to the API. 7 | #' @param body A character string of request body data. 8 | #' @param base A character string specifying the base URL for the API. 9 | #' @param token A character string containing a Travis-CI API token. If missing, defaults to value stored in environment variable \env{TRAVIS_CI_TOKEN}. 10 | #' @param ... Additional arguments passed to an HTTP request function, such as \code{\link[httr]{GET}}. 11 | #' @return A list. 12 | #' @export 13 | travisHTTP <- function(verb = "GET", 14 | path = "", 15 | query = list(), 16 | body = "", 17 | base = c("https://api.travis-ci.org", "https://api.travis-ci.com"), 18 | token = Sys.getenv("TRAVIS_CI_TOKEN"), 19 | ...) { 20 | base <- match.arg(base) 21 | url <- paste0(base, path) 22 | h <- httr::add_headers("Accept" = "application/vnd.travis-ci.2+json", 23 | "Authorization" = paste("token", token)) 24 | if (!length(query)) query <- NULL 25 | if (verb == "GET") { 26 | r <- httr::GET(url, query = query, h, ...) 27 | } else if (verb == "DELETE") { 28 | r <- httr::DELETE(url, query = query, h, ...) 29 | s <- httr::http_status(r) 30 | if (s$category %in% c("Success","success")) { 31 | return(TRUE) 32 | } else { 33 | message(s$message) 34 | return(FALSE) 35 | } 36 | } else if (verb == "POST") { 37 | if(body == "") { 38 | r <- httr::POST(url, query = query, h, ...) 39 | } else { 40 | r <- httr::POST(url, body = body, query = query, h, ...) 41 | } 42 | } else if (verb == "PUT") { 43 | if(body == "") { 44 | r <- httr::PUT(url, query = query, h, ...) 45 | } else { 46 | r <- httr::PUT(url, body = body, query = query, h, ...) 47 | } 48 | } else if (verb == "PATCH") { 49 | if(body == "") { 50 | r <- httr::PATCH(url, query = query, h, ...) 51 | } else { 52 | r <- httr::PATCH(url, body = body, query = query, h, ...) 53 | } 54 | } else { 55 | stop("Unrecognized HTTP verb") 56 | } 57 | httr::stop_for_status(r) 58 | out <- httr::content(r, "parsed", encoding = "UTF-8") 59 | if (!is.null(names(out)) && "error" %in% names(out)) { 60 | warning(out$error$message) 61 | } 62 | out 63 | } 64 | -------------------------------------------------------------------------------- /R/jobs.R: -------------------------------------------------------------------------------- 1 | #' @title Get Job 2 | #' @description Retrieve a Travis-CI job 3 | #' @details \code{get_job} retrieves a list of details about a given job. \code{cancel_job} cancels and \code{restart_job} restarts a given job. 4 | #' @param job A numeric job ID, or an object of class \dQuote{travis_job}. 5 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 6 | #' @return A list. 7 | #' @examples 8 | #' \dontrun{ 9 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 10 | #' auth_travis() 11 | #' 12 | #' # get a job 13 | #' get_job("12345") 14 | #' 15 | #' # cancel a job 16 | #' cancel_job("12345") 17 | #' 18 | #' # restart a job 19 | #' restart_job("1235") 20 | #' } 21 | #' @seealso \code{\link{get_annotations}}, \code{\link{get_logs}} 22 | #' @export 23 | get_job <- function(job, ...) { 24 | if (inherits(job, "travis_job")) { 25 | job <- job$id 26 | } 27 | out <- travisHTTP("GET", path = paste0("/jobs/", job), ...) 28 | structure(list(job = `class<-`(out$job, "travis_job"), 29 | commit = `class<-`(out$commit, "travis_commit"), 30 | annotations = lapply(out$annotations, `class<-`, "travis_annotation"))) 31 | } 32 | 33 | #' @export 34 | #' @rdname get_job 35 | cancel_job <- function(job, ...) { 36 | travisHTTP("POST", path = paste0("/jobs/", job, "/cancel"), ...) 37 | } 38 | 39 | #' @export 40 | #' @rdname get_job 41 | restart_job <- function(job, ...) { 42 | travisHTTP("POST", path = paste0("/jobs/", job, "/restart"), ...) 43 | } 44 | 45 | 46 | #' @title Job Annotations 47 | #' @description Retrieve and create job Travis CI annotations 48 | #' @details \code{get_annotations} retrieves any annotations attached to a Travis CI job. \code{create_annotation} creates a new annotation for a job. Note: As of October, 2015 support for annotations is considered \dQuote{experimental}. 49 | #' @param job A numeric job ID, or an object of class \dQuote{travis_job}. 50 | #' @param body A list of arguments specifying the annotation. See \href{http://docs.travis-ci.com/api/#annotations}{API documentation} for details. 51 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 52 | #' @return A list. 53 | #' @seealso \code{\link{get_job}} 54 | #' @examples 55 | #' \dontrun{ 56 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 57 | #' auth_travis() 58 | #' 59 | #' # get annotations for a job 60 | #' get_annotations(12345) 61 | #' 62 | #' # create a new annotation 63 | #' create_annotations(12345, body = list(description = "job description", status = "passed")) 64 | #' } 65 | #' @seealso \code{\link{get_job}}, \code{\link{get_logs}} 66 | #' @export 67 | get_annotations <- function(job, ...) { 68 | if (inherits(job, "travis_job")) { 69 | job <- job$id 70 | } 71 | travisHTTP("GET", path = paste0("/jobs/", job, "/annotations"), ...) 72 | } 73 | 74 | #' @export 75 | #' @rdname get_annotations 76 | create_annotation <- function(job, body = list(), ...) { 77 | if (inherits(job, "travis_job")) { 78 | job <- job$id 79 | } 80 | travisHTTP("GET", path = paste0("/jobs/", job, "/annotations"), body = body, encode = "json", ...) 81 | } 82 | 83 | 84 | #' @title Job Logs 85 | #' @description Retrieve logs for Travis CI jobs 86 | #' @details This can retrieve logs for a given job or a specific log by its job ID. 87 | #' @param job A numeric job ID, or an object of class \dQuote{travis_job}. Must specify \code{job} or \code{log}. 88 | #' @param log A numeric log ID. Must specify \code{job} or \code{log}. 89 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 90 | #' @return A list. 91 | #' @seealso \code{\link{get_job}} 92 | #' @examples 93 | #' \dontrun{ 94 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 95 | #' auth_travis() 96 | #' 97 | #' # get logs for a job 98 | #' get_logs(job = 12345) 99 | #' } 100 | #' @seealso \code{\link{get_job}}, \code{\link{get_annotations}} 101 | #' @export 102 | get_logs <- function(job, log, ...) { 103 | if (!missing(log)) { 104 | travisHTTP("GET", path = paste0("/logs/", log), ...) 105 | } else { 106 | if (inherits(job, "travis_job")) { 107 | job <- job$id 108 | } 109 | travisHTTP("GET", path = paste0("/jobs/", job, "/logs"), ...) 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /R/lint.R: -------------------------------------------------------------------------------- 1 | #' @title Linting 2 | #' @description Lint a .travis.yml file 3 | #' @details This can validate a \samp{.travis.yml} file and identify possible errors. 4 | #' @param file A character string specifying a path to a \samp{.travis.yml} file. 5 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 6 | #' @return A list. 7 | #' @examples 8 | #' \dontrun{ 9 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 10 | #' auth_travis() 11 | #' 12 | #' # validate .travis.yml 13 | #' travis_lint("./.travis.yml") 14 | #' } 15 | #' @seealso \code{\link{get_permissions}} to check GitHub permissions 16 | #' @export 17 | travis_lint <- function(file, ...) { 18 | travisHTTP("GET", path = paste0("/lint"), 19 | body = httr::upload_file(file), encode = "raw", ...) 20 | } 21 | -------------------------------------------------------------------------------- /R/repo.R: -------------------------------------------------------------------------------- 1 | #' @title Get Repo 2 | #' @description Retrieve a Travis-CI repository 3 | #' @details This retrieves a list of details about a given repository. 4 | #' @param repo A numeric repository ID (such as returned by this function), a character string specifying a GitHub repository \dQuote{slug} (e.g., \samp{ghusername/ghreponame}), or an object of class \dQuote{travis_repo}. 5 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 6 | #' @return A list. 7 | #' @seealso \code{\link{get_builds}} 8 | #' @examples 9 | #' \dontrun{ 10 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 11 | #' auth_travis() 12 | #' 13 | #' # get a repo 14 | #' get_repo(repo = "cloudyr/travisci") 15 | #' 16 | #' # get a specific branch 17 | #' get_branch(repo = "cloudyr/travisci", "master") 18 | #' 19 | #' # get recent builds for that repo 20 | #' get_builds(repo = "cloudyr/travisci") 21 | #' } 22 | #' @seealso \code{\link{get_builds}}, \code{\link{get_branch}} 23 | #' @export 24 | get_repo <- function(repo, ...) { 25 | if (inherits(repo, "travis_repo")) { 26 | repo <- slug_to_id(repo) 27 | } 28 | structure(travisHTTP("GET", path = paste0("/repos/", repo), ...)$repo, class = "travis_repo") 29 | } 30 | 31 | #' @export 32 | print.travis_repo <- function(x, ...) { 33 | cat("Repo (", x$id, "): ", x$slug, "\n", sep = "") 34 | cat("Active: ", as.character(x$active), "\n", sep = "") 35 | cat("Description: ", x$description, "\n", sep = "") 36 | cat("Language: ", x$github_language, "\n", sep = "") 37 | cat("Last Build (", x$last_build_id, ") Status: ", x$last_build_state, "\n", sep = "") 38 | cat("Last Build Finished: ", x$last_build_finished_at, "\n\n", sep = "") 39 | invisible(x) 40 | } 41 | 42 | #' @title Get Branch 43 | #' @description Retrieve branches for a repo 44 | #' @details This can retrieve a list of recent branches for a given repo, or if \code{branch} is specified, details about a specific branch. 45 | #' @param repo A numeric repository ID (such as returned by this function), a character string specifying a GitHub repository \dQuote{slug} (e.g., \samp{ghusername/ghreponame}), or an object of class \dQuote{travis_repo}. 46 | #' @param branch Optionally, a character string specifying the name of a branch. 47 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 48 | #' @return A list. 49 | #' @seealso \code{\link{get_builds}} 50 | #' @examples 51 | #' \dontrun{ 52 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 53 | #' auth_travis() 54 | #' 55 | #' # get branches for a given repo 56 | #' get_branch(repo = "cloudyr/travisci") 57 | #' 58 | #' # get a specific branch 59 | #' get_branch(repo = "cloudyr/travisci", "master") 60 | #' } 61 | #' @seealso \code{\link{get_repo}}, \code{\link{get_builds}} 62 | #' @export 63 | get_branch <- function(repo, branch, ...) { 64 | repo <- slug_to_id(repo) 65 | if (missing(branch)) { 66 | out <- travisHTTP("GET", path = paste0("/repos/", repo, "/branches"), ...) 67 | structure(list(branches = lapply(out$branches, `class<-`, "travis_branch"), 68 | commits = lapply(out$commits, `class<-`, "travis_commit"))) 69 | } else { 70 | out <- travisHTTP("GET", path = paste0("/repos/", repo, "/branches/", branch), ...) 71 | structure(list(branch = `class<-`(out$branches, "travis_branch"), 72 | commits = `class<-`(out$commits, "travis_commit"))) 73 | } 74 | } 75 | 76 | #' @export 77 | print.travis_branch <- function(x, ...) { 78 | cat("Branch (", x$id, ") state: ", x$state, "\n", sep = "") 79 | cat("Repo: ", x$repository_id, "\n", sep = "") 80 | cat("Commit: ", x$commit_id, "\n", sep = "") 81 | cat("Started: ", x$started_at, "\n", sep = "") 82 | cat("Finished: ", x$finished_at, "\n", sep = "") 83 | invisible(x) 84 | } 85 | 86 | #' @title Get/Set Repo Settings 87 | #' @description Get or set repository settings 88 | #' @details \code{get_repo_settings} retrieves Travis-CI settings for a given repository. \code{set_repo_settings} modifies those settings based upon a list of input values. Use \code{\link{get_env_vars}} and \code{\link{add_env_vars}} to modify environment variables used in a build. Most of these features can also be modified using a \samp{.travis.yml} file in the GitHub repository itself (see \href{http://docs.travis-ci.com/user/languages/r/}{Building an R Project} in the Travis CI documentation for details). 89 | #' @param repo A numeric repository ID (such as returned by this function), a character string specifying a GitHub repository \dQuote{slug} (e.g., \samp{ghusername/ghreponame}), or an object of class \dQuote{travis_repo}. 90 | #' @param settings A list containing named settings and their values. See results of \code{get_repo_settings} and \href{http://docs.travis-ci.com/api/#settings:-general}{the API documentation} for details. The response from either \code{get_repo_settings} or \code{set_repo_settings} can be passed directly as the value of this argument. 91 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 92 | #' @return A list of settings. 93 | #' @seealso \code{\link{get_builds}} 94 | #' @examples 95 | #' \dontrun{ 96 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 97 | #' auth_travis() 98 | #' 99 | #' # get settings 100 | #' g <- get_repo_settings(repo = "cloudyr/travisci") 101 | #' 102 | #' # pass modified settings list 103 | #' g[[1]] <- TRUE 104 | #' set_repo_settings(repo = "cloudyr/travisci", g) 105 | #' 106 | #' # specify new settings individually 107 | #' set_repo_settings(repo = "cloudyr/travisci", list("builds_only_with_travis_yml" = FALSE)) 108 | #' } 109 | #' @seealso \code{\link{get_repo}}, \code{\link{get_env_vars}} 110 | #' @export 111 | get_repo_settings <- function(repo, ...) { 112 | repo <- slug_to_id(repo) 113 | travisHTTP("GET", path = paste0("/repos/", repo, "/settings"), ...)$settings 114 | } 115 | 116 | #' @rdname get_repo_settings 117 | #' @export 118 | set_repo_settings <- function(repo, settings = list(), ...) { 119 | # builds_only_with_travis_yml 120 | # build_pushes 121 | # build_pull_requests 122 | # maximum_number_of_builds 123 | s <- c("builds_only_with_travis_yml", 124 | "build_pushes", 125 | "build_pull_requests", 126 | "maximum_number_of_builds") 127 | settings <- settings[names(settings) %in% s] 128 | repo <- slug_to_id(repo) 129 | travisHTTP("PATCH", path = paste0("/repos/", repo, "/settings"), 130 | body = list(settings = settings), encode = "json", ...)$settings 131 | } 132 | -------------------------------------------------------------------------------- /R/requests.R: -------------------------------------------------------------------------------- 1 | #' @title GitHub Requests 2 | #' @description Examine requests from GitHub to Travis CI 3 | #' @details This can examine requests made by GitHub to initiate builds on Travis-CI, perhaps when a push fails to execute a build. 4 | #' @param repo Optionally, a numeric repository ID (such as returned by this function), a character string specifying a GitHub repository \dQuote{slug} (e.g., \samp{ghusername/ghreponame}), or an object of class \dQuote{travis_repo}. Must specify either \code{repo} or \code{request}. 5 | #' @param request Optionally, a numeric request ID. Must specify either \code{repo} or \code{request}. 6 | #' @param ... Additional arguments passed to \code{\link{travisHTTP}}. 7 | #' @return A list. 8 | #' @examples 9 | #' \dontrun{ 10 | #' # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 11 | #' auth_travis() 12 | #' 13 | #' # get a list of requests 14 | #' get_requests() 15 | #' 16 | #' # get a specific request 17 | #' get_requests(12345) 18 | #' } 19 | #' @seealso \code{\link{get_permissions}} to check GitHub permissions 20 | #' @export 21 | get_requests <- function(repo, request, ...) { 22 | if (missing(request)) { 23 | if (inherits(repo, "travis_rep")) { 24 | repo <- repo$id 25 | } else if (is.numeric(repo)) { 26 | query <- list(slug = repo) 27 | } else { 28 | query <- list(repository_id = repo) 29 | } 30 | travisHTTP("GET", path = paste0("/requests"), query = query, ...) 31 | } else { 32 | travisHTTP("GET", path = paste0("/requests/", request), ...) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | slug_to_id <- function(slug, ...) { 2 | if (inherits(slug, "travis_repo")) { 3 | slug[["id"]] 4 | } else if (is.numeric(slug)) { 5 | slug 6 | } else if (is.character(slug)) { 7 | get_repo(slug, ...)[["id"]] 8 | } else { 9 | stop("Cannot coerce value to repo id") 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This package is no longer maintained. Please use https://github.com/ropenscilabs/travis instead. 2 | -------------------------------------------------------------------------------- /drat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -o errexit -o nounset 3 | addToDrat(){ 4 | mkdir drat; cd drat 5 | 6 | ## Set up Repo parameters 7 | git init 8 | git config user.name "leeper" 9 | git config user.email "thosjleeper@gmail.com" 10 | git config --global push.default simple 11 | 12 | ## Get drat repo 13 | git remote add upstream "https://$GH_TOKEN@github.com/cloudyr/cloudyr.github.io.git" 14 | git fetch upstream 15 | git checkout master 16 | 17 | Rscript -e "drat::insertPackage('../$PKG_TARBALL', repodir = './drat')" 18 | git add --all 19 | git commit -m "add $PKG_TARBALL (build $TRAVIS_BUILD_ID)" 20 | git push 21 | 22 | } 23 | addToDrat 24 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citHeader("To cite package 'travisci' in publications use:") 2 | 3 | year <- sub(".*(2[[:digit:]]{3})-.*", "\\1", meta$Date, perl = TRUE) 4 | vers <- paste("R package version", meta$Version) 5 | 6 | citEntry(entry="Manual", 7 | title = "travisci: Travis-CI API Client", 8 | author = personList(as.person("Thomas J. Leeper")), 9 | year = year, 10 | note = vers, 11 | textVersion = 12 | paste("Thomas J. Leeper (", 13 | year, 14 | "). travisci: Travis-CI API Client. ", 15 | vers, ".", sep="")) 16 | -------------------------------------------------------------------------------- /man/auth_travis.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/auth.R 3 | \name{auth_travis} 4 | \alias{auth_travis} 5 | \title{Authorize Travis-CI API} 6 | \usage{ 7 | auth_travis(username, password, setenv = TRUE, clean = !missing(username), 8 | force = FALSE, gh_token = c(Sys.getenv("GITHUB_TOKEN"), 9 | Sys.getenv("GITHUB_PAT")), base = c("https://api.travis-ci.org", 10 | "https://api.travis-ci.com")) 11 | } 12 | \arguments{ 13 | \item{username}{A character string containing a GitHub username.} 14 | 15 | \item{password}{A character string containing a GitHub password for account \code{username}.} 16 | 17 | \item{setenv}{A logical indicating whether to set the \env{TRAVIS_CI_TOKEN} environment variable. If \code{FALSE}, this will have to be passed to all other functions.} 18 | 19 | \item{clean}{A logical specifying whether to delete the temporarily generated GitHub personal access token from the GitHub account. Deafult is \code{TRUE} if \code{username} is specified. This is ignored if passing a GitHub token directly.} 20 | 21 | \item{force}{A logical indicating whether to force the operation and override an already stored value in \env{TRAVIS_CI_TOKEN}.} 22 | 23 | \item{gh_token}{An optional character string specifying a GitHub personal access token. This is ignored if \code{username} is supplied.} 24 | 25 | \item{base}{A character string specifying the base URL for the API. By default this is \url{https://api.travis-ci.org}, but may need to be changed if using a Travis Pro or enterprise account.} 26 | } 27 | \value{ 28 | A character string containing the Travis-CI API token, invisibly. 29 | } 30 | \description{ 31 | Initialize a Travis-CI API token 32 | } 33 | \details{ 34 | Using the Travis-CI API requires an API token (see \href{http://docs.travis-ci.com/api/#authentication}{API documentation} for details). This function implements a sort of handshake that uses a GitHub personal access token to generate a Travis token (to store in an environment variable, \env{TRAVIS_CI_TOKEN}) or, alternatively, uses a GitHub username and password pair to generate such a token, conduct the handshake, and then cleanup the generated, temporary token. The easiest way to use the function is to set the \env{GITHUB_TOKEN} and \env{GITHUB_PAT} environment variables, then simply call \code{auth_travis()} with no arguments, but see examples. 35 | } 36 | \examples{ 37 | \dontrun{ 38 | # authenticate using GitHub login credentials 39 | auth_travis("username", "password") 40 | 41 | # authenticate using a GitHub personal access token 42 | auth_travis(gh_token = "example token") 43 | 44 | # set GITHUB_TOKEN environment variable to authenticate 45 | Sys.setenv("GITHUB_TOKEN" = "example token") 46 | auth_travis() 47 | } 48 | 49 | } 50 | \seealso{ 51 | \code{\link{travisHTTP}} 52 | } 53 | -------------------------------------------------------------------------------- /man/cancel_build.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/builds.R 3 | \name{cancel_build} 4 | \alias{cancel_build} 5 | \alias{restart_build} 6 | \alias{restart_last_build} 7 | \title{Cancel and Restart Builds} 8 | \usage{ 9 | cancel_build(build, ...) 10 | 11 | restart_build(build, ...) 12 | 13 | restart_last_build(build, ...) 14 | } 15 | \arguments{ 16 | \item{build}{A numeric value specifying a build number or an object of class \dQuote{travis_build}. (For \code{restart_last_build}, this can also be a character string specifying a GitHub repository, such as \dQuote{user/repo}.)} 17 | 18 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 19 | } 20 | \value{ 21 | For \code{cancel_build} and \code{restart_build}, a logical that is \code{TRUE} if the operation succeeded. For \code{restart_last_build}, the build number is stored in the \code{build_id} attributes. 22 | } 23 | \description{ 24 | Cancel and restart Travis-CI builds 25 | } 26 | \details{ 27 | \code{cancel_build} will cancel a given build. \code{restart_build} will restart a cancelled build. 28 | } 29 | \examples{ 30 | \dontrun{ 31 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 32 | auth_travis() 33 | 34 | # get all recent builds for this repo 35 | g <- get_builds(repo = "cloudyr/travisci") 36 | 37 | # cancel most recent build 38 | cancel_build(g[[1]]$id) 39 | 40 | # restart that build 41 | restart_build(g[[1]]$id) 42 | } 43 | } 44 | \seealso{ 45 | \code{\link{get_builds}} 46 | } 47 | -------------------------------------------------------------------------------- /man/get_accounts.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/account.R 3 | \name{get_accounts} 4 | \alias{get_accounts} 5 | \title{Get Travis Accounts} 6 | \usage{ 7 | get_accounts(...) 8 | } 9 | \arguments{ 10 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 11 | } 12 | \value{ 13 | A list. 14 | } 15 | \description{ 16 | Retrieve GitHub accounts linked to the authenticated Travis user. 17 | } 18 | \details{ 19 | This is probably the closest thing to a \dQuote{Hello World!} on the API. It provides information about what accounts have been linked between GitHub and Travis, such as organization accounts that the user is a member of. 20 | } 21 | \examples{ 22 | \dontrun{ 23 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 24 | auth_travis() 25 | 26 | # get travis accounts 27 | get_accounts() 28 | } 29 | } 30 | \seealso{ 31 | \code{\link{get_users}}, \code{\link{get_permissions}} 32 | } 33 | -------------------------------------------------------------------------------- /man/get_annotations.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/jobs.R 3 | \name{get_annotations} 4 | \alias{get_annotations} 5 | \alias{create_annotation} 6 | \title{Job Annotations} 7 | \usage{ 8 | get_annotations(job, ...) 9 | 10 | create_annotation(job, body = list(), ...) 11 | } 12 | \arguments{ 13 | \item{job}{A numeric job ID, or an object of class \dQuote{travis_job}.} 14 | 15 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 16 | 17 | \item{body}{A list of arguments specifying the annotation. See \href{http://docs.travis-ci.com/api/#annotations}{API documentation} for details.} 18 | } 19 | \value{ 20 | A list. 21 | } 22 | \description{ 23 | Retrieve and create job Travis CI annotations 24 | } 25 | \details{ 26 | \code{get_annotations} retrieves any annotations attached to a Travis CI job. \code{create_annotation} creates a new annotation for a job. Note: As of October, 2015 support for annotations is considered \dQuote{experimental}. 27 | } 28 | \examples{ 29 | \dontrun{ 30 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 31 | auth_travis() 32 | 33 | # get annotations for a job 34 | get_annotations(12345) 35 | 36 | # create a new annotation 37 | create_annotations(12345, body = list(description = "job description", status = "passed")) 38 | } 39 | } 40 | \seealso{ 41 | \code{\link{get_job}} 42 | 43 | \code{\link{get_job}}, \code{\link{get_logs}} 44 | } 45 | -------------------------------------------------------------------------------- /man/get_branch.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/repo.R 3 | \name{get_branch} 4 | \alias{get_branch} 5 | \title{Get Branch} 6 | \usage{ 7 | get_branch(repo, branch, ...) 8 | } 9 | \arguments{ 10 | \item{repo}{A numeric repository ID (such as returned by this function), a character string specifying a GitHub repository \dQuote{slug} (e.g., \samp{ghusername/ghreponame}), or an object of class \dQuote{travis_repo}.} 11 | 12 | \item{branch}{Optionally, a character string specifying the name of a branch.} 13 | 14 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 15 | } 16 | \value{ 17 | A list. 18 | } 19 | \description{ 20 | Retrieve branches for a repo 21 | } 22 | \details{ 23 | This can retrieve a list of recent branches for a given repo, or if \code{branch} is specified, details about a specific branch. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 28 | auth_travis() 29 | 30 | # get branches for a given repo 31 | get_branch(repo = "cloudyr/travisci") 32 | 33 | # get a specific branch 34 | get_branch(repo = "cloudyr/travisci", "master") 35 | } 36 | } 37 | \seealso{ 38 | \code{\link{get_builds}} 39 | 40 | \code{\link{get_repo}}, \code{\link{get_builds}} 41 | } 42 | -------------------------------------------------------------------------------- /man/get_broadcasts.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/account.R 3 | \name{get_broadcasts} 4 | \alias{get_broadcasts} 5 | \title{Get Broadcasts} 6 | \usage{ 7 | get_broadcasts(...) 8 | } 9 | \arguments{ 10 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 11 | } 12 | \value{ 13 | A list. 14 | } 15 | \description{ 16 | Retrieve Travis-CI broadcasts 17 | } 18 | \details{ 19 | This is not particularly useful from an R perspective, but it will retrieve \dQuote{broadcasts} or news from Travis-CI. 20 | } 21 | \examples{ 22 | \dontrun{ 23 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 24 | auth_travis() 25 | 26 | # get broadcasts 27 | get_broadcasts() 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /man/get_builds.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/builds.R 3 | \name{get_builds} 4 | \alias{get_builds} 5 | \title{Get Builds} 6 | \usage{ 7 | get_builds(repo, build, ...) 8 | } 9 | \arguments{ 10 | \item{repo}{Optionally, a numeric repository ID (such as returned by this function), a character string specifying a GitHub repository \dQuote{slug} (e.g., \samp{ghusername/ghreponame}), or an object of class \dQuote{travis_repo}.} 11 | 12 | \item{build}{Optionally, a numeric value specifying a build number, or an object of class \dQuote{travis_build}.} 13 | 14 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 15 | } 16 | \value{ 17 | A list. 18 | } 19 | \description{ 20 | Retrieve Travis Builds 21 | } 22 | \details{ 23 | This can retrieve a list of recent builds (across all repos), recent builds for a specific repo (if \code{repo} is specified), or information about a specific build if \code{build} is (or both \code{repo} and \code{build} are) specified. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 28 | auth_travis() 29 | 30 | # get all recent builds 31 | g <- get_builds() 32 | 33 | # get builds for a specific repo 34 | get_builds(repo = "cloudyr/travisci") 35 | get_builds(repo = g[[1]]$repository_id) 36 | 37 | # get a specific build 38 | get_builds(build = g[[1]]$id) 39 | } 40 | } 41 | \seealso{ 42 | \code{\link{cancel_build}}, \code{\link{restart_build}} 43 | 44 | \code{\link{cancel_build}}, \code{\link{get_repo}}, \code{\link{get_branch}} 45 | } 46 | -------------------------------------------------------------------------------- /man/get_caches.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/caches.R 3 | \name{get_caches} 4 | \alias{get_caches} 5 | \alias{delete_caches} 6 | \title{Get and Delete Cache} 7 | \usage{ 8 | get_caches(repo, ...) 9 | 10 | delete_caches(repo, ...) 11 | } 12 | \arguments{ 13 | \item{repo}{A numeric repository ID (such as returned by this function), a character string specifying a GitHub repository \dQuote{slug} (e.g., \samp{ghusername/ghreponame}), or an object of class \dQuote{travis_repo}.} 14 | 15 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 16 | } 17 | \value{ 18 | A list. 19 | } 20 | \description{ 21 | Retrieve the Travis-CI cache, or delete it. 22 | } 23 | \details{ 24 | \code{get_caches} retrieves caches for a repository. \code{delete_caches} deletes all caches for a repository. 25 | } 26 | \examples{ 27 | \dontrun{ 28 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 29 | auth_travis() 30 | 31 | # get caches for a repo 32 | get_caches("cloudyr/travisci") 33 | 34 | # delete caches 35 | delete_caches("cloudyr/travisci") 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /man/get_encryption_key.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/environment.R 3 | \name{get_encryption_key} 4 | \alias{get_encryption_key} 5 | \alias{set_encryption_key} 6 | \title{Manage encrypted environment variables} 7 | \usage{ 8 | get_encryption_key(repo, ...) 9 | 10 | set_encryption_key(repo, ...) 11 | } 12 | \arguments{ 13 | \item{repo}{A character string specifying a repo slug (i.e., \samp{cloudyr/travisci}), a numeric Travis-CI repository ID, or an object of class \dQuote{travis_repo}. If a slug is used, it will be implicitly converted to a repository ID in some cases where only the latter is accepted.} 14 | 15 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 16 | } 17 | \value{ 18 | A list. 19 | } 20 | \description{ 21 | Retrieve and refresh the public key used for encryption. 22 | } 23 | \details{ 24 | These functions retrieve and refresh the public key used for encrypting secure environment variables for the Travis-CI build environment. This is probably more easily handled using the travis command-line tools, but it is also an implemented feature of the API and the functionality may be expanded in the future. See href{http://docs.travis-ci.com/user/encryption-keys/}{the API documentation} for full details. \code{get_encryption_key} retrieves the current, repository-specific public key. \code{set_encryption_key} resets the key and returns its value. 25 | } 26 | \examples{ 27 | \dontrun{ 28 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 29 | auth_travis() 30 | 31 | # get current public key 32 | get_encryption_key("cloudyr/travisci") 33 | 34 | # reset public key and retrieve the new value 35 | set_encryption_key("cloudyr/travisci") 36 | } 37 | } 38 | \seealso{ 39 | \code{\link{get_env_vars}} 40 | } 41 | -------------------------------------------------------------------------------- /man/get_env_vars.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/environment.R 3 | \name{get_env_vars} 4 | \alias{get_env_vars} 5 | \alias{add_env_vars} 6 | \alias{update_env_vars} 7 | \alias{delete_env_var} 8 | \title{Manage environment variables} 9 | \usage{ 10 | get_env_vars(repo, id, ...) 11 | 12 | add_env_vars(repo, evar, public = TRUE, ...) 13 | 14 | update_env_vars(repo, id, evar, public, ...) 15 | 16 | delete_env_var(repo, id, ...) 17 | } 18 | \arguments{ 19 | \item{repo}{A character string specifying a repo slug (i.e., \samp{cloudyr/travisci}) a numeric Travis-CI repository ID, or an object of class \dQuote{travis_repo}. If a slug is used, it will be implicitly converted to a repository ID in some cases where only the latter is accepted.} 20 | 21 | \item{id}{An alphanumeric ID for a given environment variable or an object of class \dQuote{travis_envvar}, for example as returned by one of these functions.} 22 | 23 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 24 | 25 | \item{evar}{A list of environment variables as key-value pairs.} 26 | } 27 | \value{ 28 | A list of objects of class \dQuote{travis_envvar}, except for \code{delete_env_vars}, which returns a logical. 29 | } 30 | \description{ 31 | These functions retrieve and modify environment variables for the Travis-CI build environment, as a possible alternative to specifying them in a \samp{.travis.yml} file. 32 | } 33 | \details{ 34 | This can be useful for checking, creating, updating, or deleting environment variables used as build settings. See href{http://docs.travis-ci.com/user/environment-variables/}{the API documentation} for full details. 35 | } 36 | \examples{ 37 | \dontrun{ 38 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 39 | auth_travis() 40 | 41 | # get environment variables for a repo 42 | get_env_vars("cloudyr/travisci") 43 | 44 | # get a specific environment variable based on its ID 45 | get_env_vars("cloudyr/travisci", id = 12345) 46 | 47 | # set environment variables 48 | e <- add_env_vars("cloudyr/travisci", var = list(VAR1 = "value1", VAR2 = "value2")) 49 | 50 | # update an environment variable 51 | update_env_vars("cloudyr/travisci", id = e$id, 52 | var = list(VAR1 = "newvalue") 53 | 54 | # delete an environment variable 55 | delete_env_vars("cloudyr/travisci", id = e$id) 56 | 57 | } 58 | } 59 | \seealso{ 60 | \code{\link{get_encryption_key}}, for handling encrypted environment variables 61 | } 62 | -------------------------------------------------------------------------------- /man/get_hooks.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/hooks.R 3 | \name{get_hooks} 4 | \alias{get_hooks} 5 | \alias{enable_hook} 6 | \alias{disable_hook} 7 | \title{Get Hooks} 8 | \usage{ 9 | get_hooks(...) 10 | 11 | enable_hook(hook, ...) 12 | 13 | disable_hook(hook, ...) 14 | } 15 | \arguments{ 16 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 17 | 18 | \item{hook}{A numeric hook ID, or an object of class \dQuote{travis_hook}.} 19 | } 20 | \value{ 21 | A list. 22 | } 23 | \description{ 24 | Retrieve a list of Travis-CI web hooks. 25 | } 26 | \details{ 27 | \code{get_hooks} retrieves a list of hooks (i.e., repositories that are linked to Travis CI). \code{enable_hook} and \code{disable_hook} enable and disable hooks, respectively. 28 | } 29 | \examples{ 30 | \dontrun{ 31 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 32 | auth_travis() 33 | 34 | # get list of hooks 35 | get_hooks() 36 | 37 | # disable a hook 38 | disable_hook("12345") 39 | 40 | # enable a hook 41 | enable_hook("1235") 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /man/get_job.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/jobs.R 3 | \name{get_job} 4 | \alias{get_job} 5 | \alias{cancel_job} 6 | \alias{restart_job} 7 | \title{Get Job} 8 | \usage{ 9 | get_job(job, ...) 10 | 11 | cancel_job(job, ...) 12 | 13 | restart_job(job, ...) 14 | } 15 | \arguments{ 16 | \item{job}{A numeric job ID, or an object of class \dQuote{travis_job}.} 17 | 18 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 19 | } 20 | \value{ 21 | A list. 22 | } 23 | \description{ 24 | Retrieve a Travis-CI job 25 | } 26 | \details{ 27 | \code{get_job} retrieves a list of details about a given job. \code{cancel_job} cancels and \code{restart_job} restarts a given job. 28 | } 29 | \examples{ 30 | \dontrun{ 31 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 32 | auth_travis() 33 | 34 | # get a job 35 | get_job("12345") 36 | 37 | # cancel a job 38 | cancel_job("12345") 39 | 40 | # restart a job 41 | restart_job("1235") 42 | } 43 | } 44 | \seealso{ 45 | \code{\link{get_annotations}}, \code{\link{get_logs}} 46 | } 47 | -------------------------------------------------------------------------------- /man/get_logs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/jobs.R 3 | \name{get_logs} 4 | \alias{get_logs} 5 | \title{Job Logs} 6 | \usage{ 7 | get_logs(job, log, ...) 8 | } 9 | \arguments{ 10 | \item{job}{A numeric job ID, or an object of class \dQuote{travis_job}. Must specify \code{job} or \code{log}.} 11 | 12 | \item{log}{A numeric log ID. Must specify \code{job} or \code{log}.} 13 | 14 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 15 | } 16 | \value{ 17 | A list. 18 | } 19 | \description{ 20 | Retrieve logs for Travis CI jobs 21 | } 22 | \details{ 23 | This can retrieve logs for a given job or a specific log by its job ID. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 28 | auth_travis() 29 | 30 | # get logs for a job 31 | get_logs(job = 12345) 32 | } 33 | } 34 | \seealso{ 35 | \code{\link{get_job}} 36 | 37 | \code{\link{get_job}}, \code{\link{get_annotations}} 38 | } 39 | -------------------------------------------------------------------------------- /man/get_permissions.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/account.R 3 | \name{get_permissions} 4 | \alias{get_permissions} 5 | \title{Get GitHub Permissions} 6 | \usage{ 7 | get_permissions(...) 8 | } 9 | \arguments{ 10 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 11 | } 12 | \value{ 13 | A list. 14 | } 15 | \description{ 16 | Retrieve GitHub permissions that have been authorized to Travis-CI. 17 | } 18 | \details{ 19 | This can be useful for checking what access rights have been granted to Travis-CI by GitHub. If for some reason Travis-CI isn't working, this might be useful for troubleshooting but probably not otherwise. 20 | } 21 | \examples{ 22 | \dontrun{ 23 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 24 | auth_travis() 25 | 26 | # get travis accounts 27 | get_permissions() 28 | } 29 | } 30 | \seealso{ 31 | \code{\link{get_accounts}}, \code{\link{get_users}}, \code{\link{get_requests}} (to troubleshoot specific code pushes) 32 | } 33 | -------------------------------------------------------------------------------- /man/get_repo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/repo.R 3 | \name{get_repo} 4 | \alias{get_repo} 5 | \title{Get Repo} 6 | \usage{ 7 | get_repo(repo, ...) 8 | } 9 | \arguments{ 10 | \item{repo}{A numeric repository ID (such as returned by this function), a character string specifying a GitHub repository \dQuote{slug} (e.g., \samp{ghusername/ghreponame}), or an object of class \dQuote{travis_repo}.} 11 | 12 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 13 | } 14 | \value{ 15 | A list. 16 | } 17 | \description{ 18 | Retrieve a Travis-CI repository 19 | } 20 | \details{ 21 | This retrieves a list of details about a given repository. 22 | } 23 | \examples{ 24 | \dontrun{ 25 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 26 | auth_travis() 27 | 28 | # get a repo 29 | get_repo(repo = "cloudyr/travisci") 30 | 31 | # get a specific branch 32 | get_branch(repo = "cloudyr/travisci", "master") 33 | 34 | # get recent builds for that repo 35 | get_builds(repo = "cloudyr/travisci") 36 | } 37 | } 38 | \seealso{ 39 | \code{\link{get_builds}} 40 | 41 | \code{\link{get_builds}}, \code{\link{get_branch}} 42 | } 43 | -------------------------------------------------------------------------------- /man/get_repo_settings.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/repo.R 3 | \name{get_repo_settings} 4 | \alias{get_repo_settings} 5 | \alias{set_repo_settings} 6 | \title{Get/Set Repo Settings} 7 | \usage{ 8 | get_repo_settings(repo, ...) 9 | 10 | set_repo_settings(repo, settings = list(), ...) 11 | } 12 | \arguments{ 13 | \item{repo}{A numeric repository ID (such as returned by this function), a character string specifying a GitHub repository \dQuote{slug} (e.g., \samp{ghusername/ghreponame}), or an object of class \dQuote{travis_repo}.} 14 | 15 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 16 | 17 | \item{settings}{A list containing named settings and their values. See results of \code{get_repo_settings} and \href{http://docs.travis-ci.com/api/#settings:-general}{the API documentation} for details. The response from either \code{get_repo_settings} or \code{set_repo_settings} can be passed directly as the value of this argument.} 18 | } 19 | \value{ 20 | A list of settings. 21 | } 22 | \description{ 23 | Get or set repository settings 24 | } 25 | \details{ 26 | \code{get_repo_settings} retrieves Travis-CI settings for a given repository. \code{set_repo_settings} modifies those settings based upon a list of input values. Use \code{\link{get_env_vars}} and \code{\link{add_env_vars}} to modify environment variables used in a build. Most of these features can also be modified using a \samp{.travis.yml} file in the GitHub repository itself (see \href{http://docs.travis-ci.com/user/languages/r/}{Building an R Project} in the Travis CI documentation for details). 27 | } 28 | \examples{ 29 | \dontrun{ 30 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 31 | auth_travis() 32 | 33 | # get settings 34 | g <- get_repo_settings(repo = "cloudyr/travisci") 35 | 36 | # pass modified settings list 37 | g[[1]] <- TRUE 38 | set_repo_settings(repo = "cloudyr/travisci", g) 39 | 40 | # specify new settings individually 41 | set_repo_settings(repo = "cloudyr/travisci", list("builds_only_with_travis_yml" = FALSE)) 42 | } 43 | } 44 | \seealso{ 45 | \code{\link{get_builds}} 46 | 47 | \code{\link{get_repo}}, \code{\link{get_env_vars}} 48 | } 49 | -------------------------------------------------------------------------------- /man/get_requests.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/requests.R 3 | \name{get_requests} 4 | \alias{get_requests} 5 | \title{GitHub Requests} 6 | \usage{ 7 | get_requests(repo, request, ...) 8 | } 9 | \arguments{ 10 | \item{repo}{Optionally, a numeric repository ID (such as returned by this function), a character string specifying a GitHub repository \dQuote{slug} (e.g., \samp{ghusername/ghreponame}), or an object of class \dQuote{travis_repo}. Must specify either \code{repo} or \code{request}.} 11 | 12 | \item{request}{Optionally, a numeric request ID. Must specify either \code{repo} or \code{request}.} 13 | 14 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 15 | } 16 | \value{ 17 | A list. 18 | } 19 | \description{ 20 | Examine requests from GitHub to Travis CI 21 | } 22 | \details{ 23 | This can examine requests made by GitHub to initiate builds on Travis-CI, perhaps when a push fails to execute a build. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 28 | auth_travis() 29 | 30 | # get a list of requests 31 | get_requests() 32 | 33 | # get a specific request 34 | get_requests(12345) 35 | } 36 | } 37 | \seealso{ 38 | \code{\link{get_permissions}} to check GitHub permissions 39 | } 40 | -------------------------------------------------------------------------------- /man/get_users.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/account.R 3 | \name{get_users} 4 | \alias{get_users} 5 | \alias{sync_users} 6 | \title{Travis CI Users} 7 | \usage{ 8 | get_users(user, ...) 9 | 10 | sync_users(...) 11 | } 12 | \arguments{ 13 | \item{user}{Optionally, an integer specifying a user ID, or a character string specifying a user login, or a \dQuote{travis_user} object. If missing, all users are returned.} 14 | 15 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 16 | } 17 | \value{ 18 | A list. 19 | } 20 | \description{ 21 | Retrieve and sync Travis CI users 22 | } 23 | \details{ 24 | \code{get_users} retrieves information about GitHub users attached to a Travis account. \code{sync_users} syncs Travis's local cache of users against GitHub. 25 | } 26 | \examples{ 27 | \dontrun{ 28 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 29 | auth_travis() 30 | 31 | # sync users 32 | sync_users() 33 | 34 | # get travis users 35 | get_users() 36 | 37 | # get specific user 38 | get_user("userid") 39 | } 40 | } 41 | \seealso{ 42 | \code{\link{get_accounts}}, \code{\link{get_permissions}} 43 | } 44 | -------------------------------------------------------------------------------- /man/travisHTTP.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/http.R 3 | \name{travisHTTP} 4 | \alias{travisHTTP} 5 | \title{Travis-CI HTTP Requests} 6 | \usage{ 7 | travisHTTP(verb = "GET", path = "", query = list(), body = "", 8 | base = c("https://api.travis-ci.org", "https://api.travis-ci.com"), 9 | token = Sys.getenv("TRAVIS_CI_TOKEN"), ...) 10 | } 11 | \arguments{ 12 | \item{verb}{A character string containing an HTTP verb, defaulting to \dQuote{GET}.} 13 | 14 | \item{path}{A character string with the API endpoint (should begin with a slash).} 15 | 16 | \item{query}{A list specifying any query string arguments to pass to the API.} 17 | 18 | \item{body}{A character string of request body data.} 19 | 20 | \item{base}{A character string specifying the base URL for the API.} 21 | 22 | \item{token}{A character string containing a Travis-CI API token. If missing, defaults to value stored in environment variable \env{TRAVIS_CI_TOKEN}.} 23 | 24 | \item{...}{Additional arguments passed to an HTTP request function, such as \code{\link[httr]{GET}}.} 25 | } 26 | \value{ 27 | A list. 28 | } 29 | \description{ 30 | This is the workhorse function for executing API requests for Travis-CI. 31 | } 32 | \details{ 33 | This is mostly an internal function for executing API requests. In almost all cases, users do not need to access this directly. 34 | } 35 | -------------------------------------------------------------------------------- /man/travis_lint.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lint.R 3 | \name{travis_lint} 4 | \alias{travis_lint} 5 | \title{Linting} 6 | \usage{ 7 | travis_lint(file, ...) 8 | } 9 | \arguments{ 10 | \item{file}{A character string specifying a path to a \samp{.travis.yml} file.} 11 | 12 | \item{...}{Additional arguments passed to \code{\link{travisHTTP}}.} 13 | } 14 | \value{ 15 | A list. 16 | } 17 | \description{ 18 | Lint a .travis.yml file 19 | } 20 | \details{ 21 | This can validate a \samp{.travis.yml} file and identify possible errors. 22 | } 23 | \examples{ 24 | \dontrun{ 25 | # authenticate based on Sys.setenv("GITHUB_TOKEN" = "sometoken") 26 | auth_travis() 27 | 28 | # validate .travis.yml 29 | travis_lint("./.travis.yml") 30 | } 31 | } 32 | \seealso{ 33 | \code{\link{get_permissions}} to check GitHub permissions 34 | } 35 | -------------------------------------------------------------------------------- /man/travisci.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/account.R 3 | \docType{package} 4 | \name{travisci} 5 | \alias{travisci} 6 | \alias{travisci-package} 7 | \title{Travis-CI API Client} 8 | \description{ 9 | This package provides functionality for interacting with the Travis-CI API. Travis-CI is a continuous integration service that allows for automated testing of software each time that software is publicly committed to a repository on GitHub. Setting up Travis-CI is quite simple, requiring only a GitHub account, some public (or private) repository hosted on GitHub, and logging into to Travis to link it to that repository. Travis-CI provides \href{http://docs.travis-ci.com/user/languages/r/}{straightforward documentation} for configuring your repository to interact with Travis via a \samp{.travis.yml} file added to your repository. 10 | 11 | Once you have your Travis-CI account configured online, you can use this package to interact with and perform all operations on your Travis builds that you would normally perform by the Travis website. This includes monitoring builds, modifying build environment settings and environment variables, and cancelling or restarting builds. 12 | 13 | Before you can use the package, you need to authenticate against the Travis-CI API using \code{\link{auth_travis}}, using your GitHub username and password, a GitHub personal access token, or a previously generated Travis API token (see examples, below). 14 | } 15 | \examples{ 16 | \dontrun{ 17 | # authenticate using your GitHub login credentials 18 | auth_travis("username", "password") 19 | 20 | # authenticate using a GitHub token explicitly 21 | auth_travis(gh_token = "githubtokenvalue") 22 | 23 | # authenticate using a stored environment variables 24 | Sys.setenv("GITHUB_TOKEN" = "githubtokenvalue") 25 | 26 | # check to see if you've authenticated correctly 27 | get_accounts() 28 | } 29 | 30 | } 31 | \seealso{ 32 | \code{\link{auth_travis}}, \code{\link{get_accounts}}, \code{\link{get_repo}} 33 | } 34 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library("testthat") 2 | library("travisci") 3 | 4 | test_check("travisci") 5 | -------------------------------------------------------------------------------- /tests/testthat/tests.R: -------------------------------------------------------------------------------- 1 | context("authentication") 2 | 3 | test_that("basic login", { 4 | auth_travis() 5 | }) 6 | 7 | 8 | context("Accounts") 9 | 10 | test_that("check accounts", { 11 | expect_true(is.list(get_accounts())) 12 | }) 13 | 14 | 15 | context("Users") 16 | 17 | test_that("check users", { 18 | expect_true(sync_users()) 19 | expect_true(is.list(get_users())) 20 | }) 21 | 22 | 23 | context("repo") 24 | 25 | test_that("get repo", { 26 | (r <- get_repo("cloudyr/travisci")) 27 | expect_true(inherits(r, "travis_repo")) 28 | }) 29 | 30 | test_that("slug to id", { 31 | expect_true(is.numeric(travisci:::slug_to_id("cloudyr/travisci"))) 32 | }) 33 | 34 | 35 | test_that("Enable/Disable repo hook", { 36 | expect_true(disable_hook("cloudyr/travisci"), "Disable repo hook") 37 | expect_true(enable_hook("cloudyr/travisci"), "Enable repo hook") 38 | }) 39 | 40 | 41 | test_that("get repo settings", { 42 | (s <- get_repo_settings("cloudyr/travisci")) 43 | expect_true(is.list(s)) 44 | }) 45 | 46 | test_that("environment variables", { 47 | # set environment variables 48 | a <- add_env_vars("cloudyr/travisci", list(TESTVAR = 1)) 49 | expect_true(inherits(a[[1]], "travis_envvar")) 50 | # update environment variables 51 | expect_true(inherits(update_env_vars("cloudyr/travisci", id = a[[1]], list(TESTVAR = 2))[[1]], "travis_envvar")) 52 | # get environment variables 53 | expect_true(inherits(get_env_vars("cloudyr/travisci")[[1]], "travis_envvar")) 54 | # delete environment variables 55 | expect_true(delete_env_var("cloudyr/travisci", id = a[[1]])) 56 | }) 57 | 58 | test_that("get branch", { 59 | b <- get_branch("cloudyr/travisci", "master") 60 | }) 61 | 62 | 63 | test_that("get all builds", { 64 | g <- get_builds() 65 | expect_true(is.list(g)) 66 | }) 67 | 68 | test_that("get specific build", { 69 | (b <- get_builds(86424608)) 70 | expect_true(inherits(b$build, "travis_build")) 71 | }) 72 | 73 | test_that("restart and cancel build", { 74 | expect_true(restart_build(86424608)) 75 | expect_true(cancel_build(86424608)) 76 | }) 77 | 78 | test_that("restart last build by slug", { 79 | #r <- restart_last_build("cloudyr/travisci") 80 | #expect_true(r) 81 | #cancel_build(attributes(r, "build_id")) 82 | TRUE 83 | }) 84 | 85 | 86 | test_that("get requests", { 87 | TRUE 88 | }) 89 | 90 | 91 | 92 | context("cache") 93 | 94 | test_that("get cache", { 95 | TRUE 96 | }) 97 | 98 | 99 | context("logs") 100 | 101 | test_that("get logs", { 102 | TRUE 103 | }) 104 | 105 | context("lint") 106 | 107 | test_that("lint", { 108 | TRUE 109 | }) 110 | --------------------------------------------------------------------------------