Skip to content

Commit 9ec8bea

Browse files
committed
mv get_contributors -> get_gh_code_contribs; make new get_contributors fn
1 parent 1a940ab commit 9ec8bea

6 files changed

+115
-13
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: allcontributors
22
Title: Acknowledge all contributors in your 'README'
3-
Version: 0.0.1.047
3+
Version: 0.0.1.048
44
Authors@R:
55
person(given = "Mark",
66
family = "Padgham",

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(add_contributors)
4+
export(get_contributors)
45
export(get_gh_code_contributors)
56
export(get_gh_contrib_issue)
67
export(get_gh_issue_people)

R/github.R

+75-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,79 @@
1-
2-
#' get_gh_code_contributors
1+
#' get_contributors
32
#'
4-
#' Get list of all code contributors to a repository
3+
#' Get all contributors to a repository, including those who contribute to code,
4+
#' open issues, and contribute to discussions in issues.
55
#' @param org Github organisation name for repository
66
#' @param repo Repository within `org` for which contributors are to be
77
#' extracted
8-
#' @param alphabetical If `TRUE` contributors are alphabetically sorted by
9-
#' login.
8+
#' @inheritParams add_contributors
9+
#' @export
10+
get_contributors <- function (org, repo,
11+
type = c ("code", "issues", "discussion"),
12+
alphabetical = FALSE,
13+
quiet = FALSE) {
14+
15+
if (!quiet) {
16+
cat (cli::col_cyan (cli::symbol$star), " Extracting code contributors")
17+
utils::flush.console ()
18+
}
19+
20+
ctb_code <- get_gh_code_contributors (or$org,
21+
or$repo,
22+
alphabetical = alphabetical)
23+
ctb_code <- ctb_code [which (!is.na (ctb_code$login)), ]
24+
ctb_code$type <- "code"
25+
if (!quiet)
26+
message ("\r", cli::col_green (cli::symbol$tick),
27+
" Extracted code contributors ")
28+
29+
issue_authors <- issue_contributors <- NULL
30+
if ("issues" %in% type) {
31+
if (!quiet) {
32+
cat (cli::col_cyan (cli::symbol$star),
33+
" Extracting github issue contributors")
34+
utils::flush.console ()
35+
}
36+
ctb_issues <- get_gh_issue_people (org = or$org, repo = or$repo)
37+
38+
index <- which (!ctb_issues$authors$login %in% ctb_code$logins)
39+
ctb_issues$authors <- ctb_issues$authors [index, ]
40+
41+
index <- which (!ctb_issues$contributors$login %in%
42+
c (ctb_code$logins, ctb_issues$authors$login))
43+
ctb_issues$contributors <- ctb_issues$contributors [index, ]
44+
45+
add_na_contribs <- function (x, type) {
46+
x <- cbind (x, NA_integer_) [, c (1, 3, 2)]
47+
names (x) [2] <- "contributions"
48+
x$type <- type
49+
return (x)
50+
}
51+
if (nrow (ctb_issues$authors) > 0)
52+
issue_authors <- add_na_contribs (ctb_issues$authors,
53+
"issue_authors")
54+
if ("discussion" %in% type & nrow (ctb_issues$contributors) > 0)
55+
issue_contributors <- add_na_contribs (ctb_issues$contributors,
56+
"issue_contributors")
57+
58+
if (!quiet)
59+
message ("\r", cli::col_green (cli::symbol$tick),
60+
" Extracted github issue contributors ")
61+
}
62+
63+
ctbs <- rbind (ctb_code, issue_authors, issue_contributors)
64+
65+
ctbs$type_name <- section_names [match (ctbs$type,
66+
c ("code",
67+
"issue_authors",
68+
"issue_contributors"))]
69+
70+
retrun (ctbs)
71+
}
72+
73+
#' get_gh_code_contributors
74+
#'
75+
#' Get list of all code contributors to the code of a repository
76+
#' @inheritParams get_contributors
1077
#' @return A `data.frame` of two columns of contributor (name, login)
1178
#' @export
1279
get_gh_code_contributors <- function (org, repo, alphabetical = FALSE) {
@@ -146,7 +213,7 @@ get_issues_qry <- function (gh_cli, org, repo, end_cursor = NULL) {
146213
#' Extract lists of (1) all authors of, and (2) all contributors to, all github
147214
#' issues for nominated repository
148215
#'
149-
#' @inheritParams get_gh_code_contributors
216+
#' @inheritParams get_contributors
150217
#' @return List of (authors, contributors), each as character vector of github
151218
#' login names.
152219
#' @export
@@ -210,7 +277,7 @@ get_gh_issue_people <- function (org, repo) {
210277
#' Extract titles and numbers of all issues associated with a nominated
211278
#' repository
212279
#'
213-
#' @inheritParams get_gh_code_contributors
280+
#' @inheritParams get_contributors
214281
#' @return `data.frame` with one column of issue numbers, and one column of
215282
#' issue titles.
216283
#' @export
@@ -252,7 +319,7 @@ get_gh_issue_titles <- function (org, repo) {
252319
#' Extract contributors currently listed on an "All Contributions" issue in a
253320
#' github repository. This is much easier with the REST API than via graphql.
254321
#'
255-
#' @inheritParams get_gh_code_contributors
322+
#' @inheritParams get_contributors
256323
#' @return Character vector of github logins for all contributors listed in
257324
#' current issue
258325
#' @export

codemeta.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"codeRepository": "https://github.com/ropenscilabs/allcontributors",
1111
"issueTracker": "\n https://github.com/ropenscilabs/allcontributors/issues",
1212
"license": "https://spdx.org/licenses/GPL-3.0",
13-
"version": "0.0.1.047",
13+
"version": "0.0.1.048",
1414
"programmingLanguage": {
1515
"@type": "ComputerLanguage",
1616
"name": "R",

man/get_contributors.Rd

+34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_gh_code_contributors.Rd

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)