Skip to content

Commit 715e312

Browse files
authored
Merge pull request #76 from ropensci-review-tools/authors
fix primary maintainer identification for #68
2 parents c208a60 + 5608902 commit 715e312

File tree

5 files changed

+83
-27
lines changed

5 files changed

+83
-27
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: orgmetrics
22
Title: Metrics for Your GitHub Organization
3-
Version: 0.1.2.103
3+
Version: 0.1.2.106
44
Authors@R:
55
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-2172-5265"))

R/data-cm-orgs.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ models_over_end_dates <-
88
orgmetrics_collate_org_data <- function (pkgs_json, end_date = Sys.Date (), num_years = 3) {
99

1010
requireNamespace ("jsonlite", quietly = TRUE)
11+
requireNamespace ("desc", quietly = TRUE)
1112

1213
# Suppress no visible binding notes:
1314
is_r_pkg <- NULL
@@ -39,6 +40,7 @@ orgmetrics_collate_org_data <- function (pkgs_json, end_date = Sys.Date (), num_
3940
)
4041
dat_i <- list (
4142
repo = dat_repo_to_end_date (dat_repo, end_date = end_date),
43+
authors = dat_repo_authors (dat_repo),
4244
metrics = metrics_over_end_dates (
4345
pkgs_dat$path [i],
4446
end_date = end_date,
@@ -105,6 +107,31 @@ rm_tmp_pkg_files <- function (pkgs) {
105107
}
106108
}
107109

110+
dat_repo_authors <- function (dat_repo) {
111+
112+
auts <- NULL
113+
desc_path <- fs::path (repo$pkgcheck$pkg$path, "DESCRIPTION")
114+
115+
if (fs::file_exists (desc_path)) {
116+
auts <- tryCatch (
117+
desc::desc_get_authors (desc_path),
118+
error = function (e) NULL
119+
)
120+
if (is.null (auts)) {
121+
auts <- tryCatch (
122+
desc::desc_get_maintainer (desc_path),
123+
error = function (e) NULL
124+
)
125+
}
126+
}
127+
128+
if (!is.null (auts)) {
129+
dat_repo$authors <- auts
130+
}
131+
132+
return (dat_repo)
133+
}
134+
108135
dat_repo_to_end_date <- function (dat_repo, end_date = Sys.Date ()) {
109136

110137
# Suppress no visible binding notes:

R/quarto-dashboard-org.R

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,42 @@ dashboard_data_repo_metrics <- function (data_metrics, dates) {
160160
return (repo_metrics)
161161
}
162162

163-
dashboard_data_contributors <- function (data_org) {
163+
match_names <- utils::getFromNamespace ("match_names", "repometrics")
164+
165+
dashboard_data_contributors <- function (data_org, desc_name_match = 0.8) {
164166

165167
# Suppress no visible binding notes:
166168
name <- login <- contributions <- NULL
167169

168170
data_contributors <- lapply (data_org$repos, function (repo) {
169-
ctbs_gh <- repo$rm$contribs_from_gh_api |>
170-
dplyr::select (login, name, contributions)
171-
repo$rm$contributors |>
172-
dplyr::left_join (ctbs_gh, by = c ("gh_handle" = "login", "name")) |>
173-
dplyr::filter (!name == "GitHub Actions") |>
174-
dplyr::arrange (dplyr::desc (contributions))
171+
172+
auts <- gsub ("(\\s?)(\\[|<).*$", "", repo$authors)
173+
ctbs <- repo$rm$contribs_from_gh_api |>
174+
dplyr::select (login, name, contributions) |>
175+
dplyr::filter (!grepl ("github\\-actions|\\[bot\\]", login))
176+
aut_matches <- do.call (rbind, lapply (
177+
auts,
178+
function (a) {
179+
rbind (
180+
cbind (match_names (a, ctbs$name) [1, ], what = "name"),
181+
cbind (match_names (a, ctbs$login) [1, ], what = "login")
182+
)
183+
}
184+
))
185+
login_matches <- dplyr::filter (aut_matches, what == "login")
186+
aut_matches <- aut_matches |>
187+
dplyr::filter (what == "name") |>
188+
dplyr::filter (match >= desc_name_match)
189+
if (nrow (aut_matches) == 0) {
190+
desc_name_match <- desc_name_match * max (login_matches$match)
191+
}
192+
login_matches <- login_matches |>
193+
dplyr::filter (match >= desc_name_match)
194+
195+
ctbs$is_author <- ctbs$name %in% aut_matches$name |
196+
ctbs$login %in% login_matches
197+
198+
return (ctbs)
175199
})
176200
names (data_contributors) <- gsub ("^.*\\/", "", names (data_contributors))
177201

codemeta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"codeRepository": "https://github.com/ropensci-review-tools/orgmetrics",
99
"issueTracker": "https://github.com/ropensci-review-tools/orgmetrics/issues",
1010
"license": "https://spdx.org/licenses/GPL-3.0",
11-
"version": "0.1.2.103",
11+
"version": "0.1.2.106",
1212
"programmingLanguage": {
1313
"@type": "ComputerLanguage",
1414
"name": "R",

inst/extdata/quarto/repo.qmd

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,21 @@ repoMetrics = {
424424
...row,
425425
}))
426426
}
427-
ctbs = {
427+
ctbs_all = {
428428
return transpose(ctbs_in[repo]).map(row => ({
429429
...row,
430430
}))
431431
}
432-
ctbs_gh = ctbs.map((ctb) => ctb['gh_handle']).filter(item => item != null);
432+
433+
auts = ctbs_all.filter(function(ctb) {
434+
return ctb.is_author
435+
})
436+
ctbs = ctbs_all.filter(function(ctb) {
437+
return !ctb.is_author
438+
})
439+
440+
ctbs_gh = ctbs.map((ctb) => ctb['login']).filter(item => item != null);
441+
auts_gh = auts.map((aut) => aut['login']).filter(item => item != null);
433442
```
434443

435444

@@ -482,30 +491,26 @@ htl.html`${releases[0].total} releases (latest: ${release_latest}), ${releases[0
482491
gitlog_txt_total = htl.html`${gitlog_total_commits} commits since ${gitlog_first_commit}`;
483492
gitlog_txt_recent = htl.html`${gitlog_recent_commits} commits in past year`;
484493
485-
maintainer_count = repoMetrics.filter(function(m) {
486-
return m.name == "maintainer_count"
487-
})[0].value;
488-
maintainer_count_txt = pluraliseObjects(maintainer_count, "primary maintainer");
494+
author_count = auts_gh.length;
495+
author_count_txt = pluraliseObjects(author_count, "primary author");
489496
490-
maintainer_gh = [].concat(ctbs_gh.slice(0, maintainer_count) || []);
491-
maintainer_gh_list = maintainer_gh.length == 0 ? undefined:
492-
(maintainer_gh.length == 1 ? htl.html`
493-
<div onclick=${() => localStorage.setItem('orgmetricsMaintainer', maintainer_gh)}>
494-
<li><a href='/contributor.html'>${maintainer_gh}</a></li>
497+
author_gh_list = auts_gh.length == 0 ? undefined:
498+
(auts_gh.length == 1 ? htl.html`
499+
<div onclick=${() => localStorage.setItem('orgmetricsMaintainer', auts_gh)}>
500+
<li><a href='/contributor.html'>${auts_gh}</a></li>
495501
</div>
496-
` : maintainer_gh.map(m => htl.html`
502+
` : auts_gh.map(m => htl.html`
497503
<div onclick=${() => localStorage.setItem('orgmetricsMaintainer', m)}>
498504
<li><a href='/contributor.html'>${m}</a></li>
499505
</div>
500506
`));
501-
maintainer_gh_list_txt = maintainer_gh.length > 0 ? htl.html`<ul>${maintainer_gh_list}</ul>` : undefined;
507+
author_gh_list_txt = auts_gh.length > 0 ? htl.html`<ul>${author_gh_list}</ul>` : undefined;
502508
503-
ctb_gh = [].concat(ctbs_gh.slice(maintainer_count) || []);
504-
ctb_count = ctb_gh.length;
509+
ctb_count = ctbs_gh.length;
505510
ctb_count_txt = pluraliseObjects(ctb_count, "additional contributor");
506-
ctb_count_list = ctb_gh.map((item, i) => htl.html`
511+
ctb_count_list = ctbs_gh.map((item, i) => htl.html`
507512
<span onclick=${() => localStorage.setItem('orgmetricsMaintainer', item)}>
508-
<a href='/contributor.html'>${item}</a>${i < ctb_gh.length - 1 ? ", " : ""}</span>`);
513+
<a href='/contributor.html'>${item}</a>${i < ctbs_gh.length - 1 ? ", " : ""}</span>`);
509514
ctb_count_html = ctb_count == 0 ? htl.html`<div>No additional contributors</div>` :
510515
htl.html`<div>${ctb_count_txt}: ${ctb_count_list}</div>`;
511516
@@ -604,7 +609,7 @@ htl.html`<ul>
604609
<li>${releases_txt_total}</li>
605610
<li>${gitlog_txt_total}</li>
606611
<li>${gitlog_txt_recent}</li>
607-
<li>${maintainer_count_txt}${maintainer_gh_list_txt}</li>
612+
<li>${author_count_txt}${author_gh_list_txt}</li>
608613
<li>${ctb_count_html}</li>
609614
<li>${test_coverage_txt}</li>
610615
</ul>`

0 commit comments

Comments
 (0)