r-lib / devtools

Tools to make an R developer's life easier
https://devtools.r-lib.org
Other
2.39k stars 758 forks source link

grab issues information from a github repo #354

Closed romainfrancois closed 10 years ago

romainfrancois commented 10 years ago

Would be interesting to have something that would list issues from a github repo. Something like:

github_issues( "hadley/devtools" )

poking into github's api, i.e. https://api.github.com/repos/hadley/devtools/issues

and structuring the results somehow.

romainfrancois commented 10 years ago

Something like this:

github_issues <- function(repo="devtools", user = getOption( "github.user" )){
    if( isTRUE(grepl("/", repo)) ){
        rx <- "^(.*)/(.*)$"
        user <- sub( rx, "\\1", repo )
        repo <- sub( rx, "\\2", repo )
    }
    url <- sprintf( "https://api.github.com/repos/%s/%s/issues", user, repo )
    json <- GET(url)
    fromJSON(json)    
}

But further manipulating the json output to make it look nice and useful. But I'm getting a ouch when using rjson::fromJSON:

> github_issues( "hadley/devtools")
Erreur dans fromJSON(json) :
  STRING_ELT() can only be applied to a 'character vector', not a 'list'

So I guess I'd need to patch rjson first.

hadley commented 10 years ago

You need to either do fromJSON(content(json, "text")) or content(json, "parsed")

romainfrancois commented 10 years ago

I have this in my ~/bin/github_issues:

#!/usr/bin/Rscript 
library(methods)
library(devtools)
library(rjson) 
library(httr)

github_issues <- function(repo="devtools", user = getOption( "github.user" )){
  if( isTRUE(grepl("/", repo)) ){
      rx <- "^(.*)/(.*)$"
      user <- sub( rx, "\\1", repo )
      repo <- sub( rx, "\\2", repo )
  }
  url <- sprintf( "https://api.github.com/repos/%s/%s/issues", user, repo )
  json <- content(GET(url), "text" )
  data <- fromJSON(json)
  out <- data.frame( 
    number = sapply( data, function(x) x$number ), 
    user   = sapply( data, function(x) x$user$login ),
    title  = sapply( data, function(x) x$title ), 
    labels = sapply( data, function(x) { 
      lab <- x[["labels"]] 
      paste( sapply( lab, function(.) .$name ), collapse = ", " )
    })
  )
  out
}

args <- commandArgs(TRUE)

options( width = 200 )
github_issues( tail( args, 1L) )

So that I can do:

$ github_issues hadley/dplyr
   number           user                                                         title                labels
1      98         hadley                                   Setup databases with travis           enhancement
2      97         hadley                                               Unique operator           enhancement
3      96         hadley                           Implement right join and outer join           enhancement
4      95 romainfrancois                                             Hybrid evaluation enhancement, internal
5      94         hadley                 Make sure all vignettes work from R CMD check                   bug
6      93         hadley               Document and implement "col aligning operators"           enhancement
7      91         hadley                                                MySQL problems                   bug
8      82         hadley                  equal_data_frame should be more configurable           enhancement
9      78         hadley Provide version of equal_data_frame that works like all.equal           enhancement
10     62 romainfrancois                                      Registration of reducers              internal
11     57 romainfrancois                                     Support more result types              internal
12     44         hadley                               Strict version of translate_sql           enhancement
13     43         hadley                  Consistent interface for windowing functions           enhancement
14     40         hadley                                        Should tbl_dt be lazy?           enhancement
15     37         hadley                                  Implement ganalytics backend           enhancement
16     35         hadley                                        Simplify generated sql           enhancement
17     29         hadley                                            Plyr compatibility           enhancement
18     14         hadley                                       Other types of grouping           enhancement
19      8         hadley                                               MonetDB backend           enhancement

Maybe it does not need to go on devtools. One thing I though we could do is settle on some convention about chunk of code that goes in an issue, so that we could do something like this:

test_github_issue( "hadley/dplyr/#95" )

This would grab code from the issue, and just run it. Would be a nice way to go about "did I fix this issue ?". Now what I do is copy and paste the code into some temp file and run this temp file.

romainfrancois commented 10 years ago

Closing this as siesta now offers a way to do it.