Repository navigation
Expand file tree
/
Copy pathorgs_repos_members_files_LB.R
More file actions
152 lines (130 loc) · 4.52 KB
/
Copy pathorgs_repos_members_files_LB.R
File metadata and controls
152 lines (130 loc) · 4.52 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
### New GH-API-R functions, created by Lukas Borke
## basic functions
#' Get all organizations
#'
#' @param ... extra parameters, see \url{http://developer.github.com/v3/repos/}
#'
#' @param ctx the github context object
#'
#' @return information on all organizations
get.all.orgs <- function(..., ctx = get.github.context())
.api.get.request(ctx, c("organizations"), params=list(...))
#' Get list of public members of given organization
#'
#' @param ... extra parameters, see \url{http://developer.github.com/v3/repos/}
#'
#' @param org the given organization
#'
#' @param ctx the github context object
#'
#' @return list of public members
get.organization.public.members.pagination <- function(..., org, ctx = get.github.context())
.api.get.request(ctx, c("orgs", org, "public_members"), params=list(...))
#' Create a new file
#'
#' @param owner the repo owner (user, org, etc)
#'
#' @param repo the name of the repo
#'
#' @param path the file path
#'
#' @param content the content(?)
#'
#' @param ctx the github context object
create.file <- function(owner, repo, path, content, ctx = get.github.context())
.api.put.request(ctx, c("repos", owner, repo, "contents", path), body = content)
# Update an existing file
#update.file <- function(owner, repo, path, content, ctx = get.github.context())
# .api.put.request(ctx, c("repos", owner, repo, "contents", path), body = content)
## helping functions
#' API Wrapper for file creation
#'
#' @param user_name the user name
#'
#' @param repo_name the name of the repo
#'
#' @param file_path the file path
#'
#' @param file_name the file name
#'
#' @param file_string_content the file content
#'
#' @param api_create_message the message with the status on file creation
create.file.content.on.github = function(user_name, repo_name, file_path, file_name, file_string_content, api_create_message) {
path_name = paste(file_path, file_name, sep = "/")
cont_base64 = base64encode(charToRaw(file_string_content))
ready_content = list(message = api_create_message, content = cont_base64)
result = create.file(user_name, repo_name, path_name, ready_content, ctx = get.github.context())
return(result)
}
#' Get information on the remaining API ratelimit
#'
#' @param org_name the organization name
get.api.ratelimit = function(org_name) {
get.organization(org_name)$headers$'x-ratelimit-remaining'
}
#' Get information on public members of given organization
#'
#' @param org_name the organization name
#'
#' @return list with information on public members
get.organization.public.members.fulllist = function(org_name) {
all_memb_list = vector()
i = 1
org_memb = get.organization.public.members.pagination(org = org_name, per_page = 100, page = i)$content
while (length(org_memb) > 0) {
for (k in 1:length(org_memb)) {
all_memb_list = c(all_memb_list, org_memb[[k]]$login)
}
i = i + 1
org_memb = get.organization.public.members.pagination(org = org_name, per_page = 100, page = i)$content
}
return(all_memb_list)
}
#' Get information on repositories of given organization
#'
#' @param org_name the organization name
#'
#' @param public_repos_nr the number of public repositories
#'
#' @return list with information on repositories
get.repositories.full.description = function(org_name, public_repos_nr) {
found_software = vector()
full_rep_desc = ""
result_api = list()
if (public_repos_nr == 0) { return(NULL) }
quotient = public_repos_nr %/% 100
remainder = public_repos_nr %% 100
page_iter = quotient
if (remainder > 0) {page_iter = page_iter + 1}
for (i in 1:page_iter){
org_rep = get.organization.repositories(org = org_name, type = "public", per_page = 100, page = i)$content
for (k in 1:length(org_rep)) {
full_rep_desc = paste(full_rep_desc, org_rep[[k]]$description, "; ", sep = "")
found_software = c(found_software, org_rep[[k]]$language)
}
}
result_api$desc = full_rep_desc
result_api$sw = sort(unique(found_software))
return(result_api)
}
## CRAN helping functions
#' Get list of public repositories of given organization
#'
#' @param org_name the organization name
#'
#' @return list of public repositories
get.organization.public.repos.fulllist = function(org_name) {
all_repo_list = vector()
i = 1
org_repos = get.organization.repositories(org = org_name, per_page = 100, page = i)$content
while (length(org_repos) > 0) {
for (k in 1:length(org_repos)) {
all_repo_list = c(all_repo_list, org_repos[[k]]$name)
}
i = i + 1
org_repos = get.organization.repositories(org = org_name, per_page = 100, page = i)$content
}
return(all_repo_list)
}
### ENDE New GH-API functions