Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could use_travis() turn on repo automatically? #971

Closed
hadley opened this issue Nov 5, 2015 · 4 comments
Closed

Could use_travis() turn on repo automatically? #971

hadley opened this issue Nov 5, 2015 · 4 comments
Labels
feature a feature request or enhancement usethis

Comments

@hadley
Copy link
Member

hadley commented Nov 5, 2015

via github authentication from GITHUB_PAT

@hadley
Copy link
Member Author

hadley commented Jan 12, 2016

Reading https://docs.travis-ci.com/api#with-a-github-token suggests this code should work:

  req <- httr::POST("https://api.travis-ci.org/auth/github", 
    body = list(github_token = github_pat()),
    httr::accept("application/vnd.travis-ci.2+json"),
    httr::verbose(),
    encode = "json"
  )
  httr::content(req, "text")

But it doesn't, and the error recommends contacting support. Since travis support never replies with anything useful, this doesn't seem worth pursuing at this time.

@hadley hadley closed this as completed Jan 12, 2016
@hadley
Copy link
Member Author

hadley commented Feb 4, 2016

Critical bit seems to be using the same user agent as their example:

req <- httr::POST("https://api.travis-ci.org/auth/github", 
                  body = list(github_token = github_pat()),
                  httr::accept("application/vnd.travis-ci.2+json"),
                  httr::verbose(),
                  httr::user_agent("MyClient/1.0.0"),
                  encode = "json"
)
httr::content(req)

@hadley hadley reopened this Feb 4, 2016
@hadley
Copy link
Member Author

hadley commented Feb 4, 2016

Complete process:

library(httr)

# Get auth token using Github PAT -----------------------------------------
travis_token <- function() {
  req <- POST("https://api.travis-ci.org/auth/github", 
    body = list(github_token = github_pat()),
    accept("application/vnd.travis-ci.2+json"),
    user_agent("MyClient/1.0.0"),
    encode = "json"
  )
  stop_for_status(req)
  token <- httr::content(req)$access_token

  add_headers(Authorization = paste0("token ", token))
}
token <- travis_token()

# Determine repo id -------------------------------------------------------
repos <- content(GET("https://api.travis-ci.org/repos", token, query = list(slug = "hadley/monads")))
id <- repos[[1]]$id

# Set hook to active ------------------------------------------------------
req <- PUT("https://api.travis-ci.org/hooks", 
  body = list(hook = list(id = id, active = TRUE)), 
  encode = "json", 
  token
)
stop_for_status(req)
content(req)

# library(purrr)
# hooks <- content(GET("https://api.travis-ci.org/hooks", token))
# hooks %>% map_chr("uid")
# hooks %>% keep(~.$name == "monads") %>% str()

@lock
Copy link

lock bot commented Sep 18, 2018

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Sep 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement usethis
Projects
None yet
Development

No branches or pull requests

1 participant