-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepo_data.r
More file actions
169 lines (145 loc) Β· 4.03 KB
/
Copy pathrepo_data.r
File metadata and controls
169 lines (145 loc) Β· 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Removing currently stored variables (ex.: from previous sessions)
rm(list=ls())
# Importing Libraries
library("ghql")
library("jsonlite")
library("dplyr")
# Private GitHub Token ( create your own here: https://github.com/settings/tokens/new )
token <- "<token>"
# GraphQL Connection Object (GitHub)
connection <- GraphqlClient$new(
url = "https://api.github.com/graphql",
headers = list(Authorization = paste0("Bearer ", token))
)
# GitHub Server doesn't has a schema at the base URL, have to manually load the schema in this case
connection$load_schema()
# Creating new Query
new_query <- Query$new()
# GraphQL Query
new_query$query('mydata', '{
repositoryOwner(login:"Luzkan") {
repositories(first: 5, orderBy: {field:PUSHED_AT,direction:DESC}, isFork:false) {
edges {
node {
name
diskUsage
forkCount
isEmpty
languages (first : 10){
edges{
size
node{
name
}
}
}
labels (first : 50){
totalCount
nodes{
name
description
updatedAt
}
}
issues (first : 20){
totalCount
edges{
node{
body
author{
login
}
}
}
}
stargazers {
totalCount
}
description
defaultBranchRef{
target{
... on Commit {
history(first : 10){
totalCount
edges{
node{
... on Commit {
message
committedDate
author{
user{
login
}
}
}
}
}
}
}
}
}
}
}
}
... on User {
bio
company
isHireable
isViewer
}
}
}')
# Execute Query
(result <- connection$exec(new_query$queries$mydata))
# Parse to more human readable form
jsonlite::fromJSON(result)
# Writing to file
write(result, "output.json")
json <- fromJSON(result)
repositoriesNames <- json$data$repositoryOwner$repositories$edges$node$name
bio <- json$data$repositoryOwner$bio
isHireable <- json$data$repositoryOwner$isHireable
emptyRepos <- json$data$repositoryOwner$repositories$edges$node$isEmpty
commitMsgE <- json$data$repositoryOwner$repositories$edges$node$defaultBranchRef$target$history$edges
commitMSGList <- list()
commitDates <- list()
for(d in commitMsgE) {
tmp <- d$node$author$user$login
for(i in 1:length(tmp)){
if( !is.na(tmp[i]) && tmp[i] == "Luzkan"){
commitDates <- c(commitDates,d$node$committedDate[i])
}
}
}
for (p in commitMsgE) {
tmp <- d$node$author$user$login
for(i in 1:length(tmp)){
if( !is.na(tmp[i]) && tmp[i] == "Luzkan"){
msg <- p$node$message[i]
if(!is.na(msg)){
commitMSGList <- c(commitMSGList, msg )
}
}
}
}
languages <- json$data$repositoryOwner$repositories$edges$node$languages$edges
languagesList <- list()
for (l in languages) {
print(l)
languagesList <- c(languagesList, l$node$name )
}
#Calculating average time between commits
time_between_commits <- list()
for(idx in seq_along(commitDates)){
if (idx+1 > length(commitDates)){
break
}
dateOne<-as.POSIXct(commitDates[[idx]], format = "%Y-%m-%dT%H:%M:%SZ")
dateTwo<-as.POSIXct(commitDates[[idx+1]], format = "%Y-%m-%dT%H:%M:%SZ")
time_between_commits[[idx]]<- as.numeric(difftime(dateOne,dateTwo, units="mins"))
}
average_time_between_commit <- mean(unlist(time_between_commits))
df <- data.frame(bio, emptyRepos, isHireable,average_time_between_commit,
c(repositoriesNames), c(languagesList), c(commitDates), c(commitMSGList))
rm(new_query)
write(result, "output.json")