1+ # Process grade-related things....
2+ #
3+ #
4+ # # Participation grade
5+ # #
6+ # #
7+
8+ library(tidyverse )
9+ library(tidyjson )
10+ library(foreach )
11+ source(" grades/secrets.R" )
12+
13+
14+ # Get OAuth credentials
15+ github_token <- oauth2.0_token(oauth_endpoints(" github" ), myapp )
16+
17+ # Use API
18+ gtoken <- config(token = github_token )
19+ req <- GET(" https://api.github.com/users/AdamWilsonLabEDU/repos?per_page=1000" , gtoken )
20+
21+ # Take action on http error
22+ stop_for_status(req )
23+
24+ # Extract content from a request
25+ json1 = content(req )
26+
27+ # Convert to a data.frame
28+ d = jsonlite :: fromJSON(jsonlite :: toJSON(json1 ))%> %
29+ select(- c(`owner` , `mirror_url` , `license` , `permissions` ))%> %
30+ select(c(`full_name` , `html_url` , `forks_url` , `collaborators_url` ,`commits_url` ,`pulls_url` ,`pushed_at` ,`homepage` ,`size` ,`forks_count` ))%> %
31+ as.tibble()%> %
32+ mutate(type = ifelse(grepl(" finalproject" ,full_name ),
33+ " final_project" ," class" ),
34+ user = gsub(" AdamWilsonLabEDU/geo503-2018-" ," " ,gsub(" finalproject-" ," " ,full_name )))
35+
36+ class = d %> %
37+ filter(type == " class" )
38+
39+ project = d %> %
40+ filter(type == " final_project" )
41+
42+
43+ # copy repository structure repo somewhere
44+ setwd(" ~/Documents/Work/courses/201809/GEO511/repos/" )
45+ i = 1
46+ # system(paste("git remote add -f",class$user[i]," ",class$html_url[i]))
47+ # system("git remote update")
48+ # system(paste0("git diff master remotes/",class$user[i],"/master"))
49+ # system(paste("git remote rm ",class$user[i]))
50+
51+ # check out repository diffs, one by one
52+ if (F ){
53+ for (i in 1 : nrow(class ))
54+ system(paste0(" meld SpatialDataScience_Structure GEO503-2018-12-07-2018-10-23-37/" ,class $ user [i ]," &" ))
55+ }
56+
57+ # get class contents
58+ class_summary <- foreach(i = 1 : nrow(class )) %do % {
59+ content <- GET(" https://api.github.com/repos/AdamWilsonLabEDU/geo503-2018-acerpovicz/contents/week_04/case_study" , gtoken )%> %
60+ content()%> %toJSON()%> %fromJSON()%> %
61+ select(name ,path )%> %filter(name != " README.md" )%> %
62+ mutate(user = class $ user [i ])
63+ }
64+
65+
66+
67+ # summarize pull requests?
68+ # get class contents
69+ repo_url = " https://api.github.com/repos/AdamWilsonLabEDU/geo503-2018-finalproject-acerpovicz"
70+ repo_url = project $ pulls_url [3 ]
71+
72+ fpull = function (repo_url ){
73+
74+ print(repo_url )
75+ pull_requests <- GET(paste0(gsub(" \\ {\\ /number\\ }" ," " ,repo_url )), gtoken )%> %
76+ content()%> %toJSON()%> %fromJSON()
77+ if (length(pull_requests )== 0 ) return (NA )
78+
79+ comments_url = pull_requests $ review_comments_url
80+ pull_comments =
81+ lapply(comments_url ,FUN = function (j ){
82+ pull_comments <- GET(j [[1 ]], gtoken )%> %
83+ content()%> %toJSON()%> %fromJSON()
84+ unlist(pull_comments $ body )
85+ })
86+
87+ results = data.frame (
88+ reviewed = gsub(" ^.*project-" ," " ,gsub(" \\ /p.*$" ," " ,repo_url )),
89+ reviewer = unlist(pull_requests $ user $ login ),
90+ description = paste(unlist(pull_requests $ body )),
91+ comment = unlist(lapply(pull_comments ,FUN = paste ,collapse = " ;" )),
92+ comment_count = unlist(lapply(pull_comments ,FUN = length )),stringsAsFactors = F )%> %
93+ mutate(
94+ description_words = lengths(strsplit(description , " \\ W+" )),
95+ comments_words = lengths(strsplit(comment , " \\ W+" )),
96+ total_words = description_words )%> %
97+ select(- description_words ,- comments_words )
98+
99+ return (results )
100+ }
101+
102+ # get and
103+ review = do.call(rbind.data.frame ,lapply(project $ pulls_url ,FUN = fpull ))
104+
105+ review %> %
106+ group_by(reviewer )%> %
107+ summarize(pull_requests = n(),comments = sum(comment_count ),words = sum(total_words ))
108+
109+
110+ filter(review ,reviewer == " acerpovicz" )
111+
0 commit comments