Skip to content

First stab at automated comments #208

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

Merged
merged 29 commits into from
Apr 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
dcbe441
First stab at automated comments
cpsievert Apr 25, 2015
102ed00
moved location of test scripts
cpsievert Apr 25, 2015
28073b3
fun with paths
cpsievert Apr 25, 2015
2fa7d76
bug fix
cpsievert Apr 25, 2015
071a455
Can only access pull ID from Travis env var on pull request
cpsievert Apr 25, 2015
048df20
Try issues, not pulls
cpsievert Apr 26, 2015
a21506f
Pass GH_TOKEN to POST Authentication header
cpsievert Apr 26, 2015
9df06f5
Pass string straight to body argument
cpsievert Apr 26, 2015
7dcf6b9
try toJSON
cpsievert Apr 26, 2015
0e3d5ca
experimenting
cpsievert Apr 27, 2015
2ccefd1
Rely on GitHub API rather than git for test table info
cpsievert Apr 27, 2015
7e4a041
no git log
cpsievert Apr 27, 2015
f894b13
Move more shell code to R for consistency
cpsievert Apr 27, 2015
d8bd763
Avoid re-clone of plotly; dev branch column will now reflect result *…
cpsievert Apr 27, 2015
53e91d3
Ugh. 404 is back
cpsievert Apr 27, 2015
88dc459
Fix url link
cpsievert Apr 27, 2015
3e0991b
Gotta install plotly before making test table
cpsievert Apr 27, 2015
2c0b3c8
almost there
cpsievert Apr 27, 2015
20dab8e
git add only allows one file argument
cpsievert Apr 28, 2015
6d62f2e
debugging travis isn't fun
cpsievert Apr 28, 2015
d60157c
derp
cpsievert Apr 28, 2015
9a8c2e8
replace head SHA from API with TRAVIS_COMMIT since we want representi…
cpsievert Apr 28, 2015
ab1967e
More informative comment
cpsievert Apr 28, 2015
38a8fb0
Make message more bot-like
cpsievert Apr 28, 2015
581aa04
Line breaks
cpsievert Apr 28, 2015
aa50cb0
sep not collapse
cpsievert Apr 28, 2015
8011a96
Use blockquote, not code blocks
cpsievert Apr 28, 2015
fec9743
Ugh, need 2 line breaks
cpsievert Apr 28, 2015
f3b40a7
Add link to Travis build
cpsievert Apr 29, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions .push_test_table.sh

This file was deleted.

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ r_packages:
- httr

before_script:
- chmod 755 ./.push_test_table.sh
- chmod 755 inst/testscripts/.push_test_table.sh

after_success:
- ./.push_test_table.sh
- inst/testscripts/.push_test_table.sh

notifications:
slack:
Expand Down
29 changes: 29 additions & 0 deletions inst/testscripts/.push_test_table.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# exit on error
set -e

# -----------------------------------------------------------------------
# Travis does two types of builds:
#
# (1) A so-called "push". This essentially does a checkout on the most
# recent commit of the pull request, but *doesn't* merge with master.
# In this case, $TRAVIS_PULL_REQUEST = "false"
# (2) A so-called "pr" (pull request). This *does* merge with master.
# In this case, $TRAVIS_PULL_REQUEST contains the pull request number.
# -----------------------------------------------------------------------

# We need the pull request number to talk to the GitHub API, make comments, etc.
[ "${TRAVIS_PULL_REQUEST}" = "false" ] && exit 0

git config --global user.name "cpsievert"
git config --global user.email "[email protected]"

cd ..
git clone https://github.com/ropensci/plotly-test-table.git
cd plotly-test-table
git checkout gh-pages

# Read more about Travis environment variables --
# http://docs.travis-ci.com/user/ci-environment/
Rscript ../plotly/inst/testscripts/comment.R $TRAVIS_PULL_REQUEST $TRAVIS_BUILD_ID $TRAVIS_COMMIT $GH_TOKEN
74 changes: 74 additions & 0 deletions inst/testscripts/comment.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# first argument is the pull request number (TRAVIS_PULL_REQUEST)
# second is travis build ID (TRAVIS_BUILD_ID)
# third is the commit SHA1 currently being tested (TRAVIS_COMMIT)
# fourth is the github authentication token
a <- commandArgs(TRUE)
# gistr is a good reference for talking to the github API via httr
# https://github.com/ropensci/gistr/blob/master/R/zzz.R
library("httr")
base <- 'https://api.github.com/repos/ropensci/plotly/'
pr <- sprintf(paste0(base, 'pulls/%s'), a[1])
header <- add_headers(`User-Agent` = "plotly",
`Accept` = 'application/vnd.github.v3+json',
`Authorization` = paste0("token ", a[4]))
# Must be successful since we grab the branch name for this pull request
# and SHA1 info from the request content
res <- GET(url = pr, header)
stop_for_status(res)
info <- content(res)
# find the branch name for this pull request
# http://stackoverflow.com/questions/15096331/github-api-how-to-find-the-branches-of-a-pull-request
branch <- strsplit(info$head$label, ":")[[1]][2]

# plotly-test-table build script assumes we've checkout the dev branch.
# Note that travis does something like this for "pr" build:
#$ git fetch origin +refs/pull/number/merge:
#$ git checkout -qf FETCH_HEAD
# this leaves HEAD in a detached state, but we should be able to do:
# git checkout -b new_branch_name
setwd("../plotly")
if (system(paste("git checkout -b", branch)) != 0L)
stop(paste("Failed to 'git checkout -b'", branch, "branch"))
devtools::install()
setwd("../plotly-test-table")
cat("user,SHA1,label", file = "code_commits.csv")
row1 <- paste0("\nropensci,", info$base$sha, ",master")
cat(row1, file = "code_commits.csv", append = TRUE)
row2 <- paste0("\nropensci,", a[3], ",", branch)
cat(row2, file = "code_commits.csv", append = TRUE)

# copy over file (created during Rscript)
# with sha/branch info for building test table
system("touch table.R")
if (system("make") != 0L) stop("Failed to 'make' test table")

# add, commit, push to gh-pages branch of plotly-test-table
system("git add index.html")
system("git add tables/*/*.html")
system("git add data/*/*.png")
system("git add data/*/*.log")
build_link <- paste0('https://travis-ci.org/ropensci/plotly/builds/', a[2])
commit_msg <- paste0('"Pushed from ', build_link, '"')
system(paste('git commit -m', commit_msg))
# This post explains how this works -- http://rmflight.github.io/posts/2014/11/travis_ci_gh_pages.html
repo <- sprintf("https://%[email protected]/ropensci/plotly-test-table.git", a[4])
system(paste("git pull -q", repo, "gh-pages"))
system(paste("git push -q", repo, "gh-pages"))

# post comment if a link to this SHA doesn't exist
# (needed since Travis randomly re-builds stuff)
tbl_link <- sprintf("http://ropensci.github.io/plotly-test-table/tables/%s/index.html", a[3])
msg <- sprintf("On TravisCI, commit %s was successfully merged with %s (master) to create %s. A visual testing table comparing %s with %s can be found here:\n %s",
info$head$sha, info$base$sha, a[3], info$base$sha, a[3], tbl_link)
msg <- paste("> The message below was automatically generated after build", build_link, "\n\n", msg)
commentz <- sprintf(paste0(base, 'issues/%s/comments'), a[1])
res <- GET(commentz, header)
warn_for_status(res)
info <- content(res)
old_body <- unlist(lapply(info, "[", "body"))
if (!any(grepl(tbl_link, old_body))) {
json <- jsonlite::toJSON(list(body = msg), auto_unbox = TRUE)
httr::POST(url = commentz, header, body = json, encode = "json")
} else {
message("Link already posted")
}