Skip to content

Commit

Permalink
Require verified commits
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Jul 19, 2024
1 parent aa3bdd8 commit adf39ae
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 13 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: multiverse.internals
Title: Internal Infrastructure for R-multiverse
Description: R-multiverse requires this internal internal infrastructure
package to automate contribution reviews and populate universes.
Version: 0.2.6
Version: 0.2.7
License: MIT + file LICENSE
URL: https://github.com/r-multiverse/multiverse.internals
BugReports: https://github.com/r-multiverse/multiverse.internals/issues
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# multiverse.internals 0.2.6
# multiverse.internals 0.2.7

* Exclude superfluous fields from `update_production()` `packages.json`.
* Require verified commits in contributions.

# multiverse.internals 0.2.6

Expand Down
68 changes: 57 additions & 11 deletions R/review_pull_request.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,57 @@ review_pull_request <- function(
assert_character_scalar(repo)
assert_positive_scalar(number)
message("Reviewing pull request ", number)
merge <- review_pull_request_integrity(owner, repo, number) &&
review_pull_request_content(owner, repo, number)
if (isTRUE(merge)) {
pull_request_merge(
owner = owner,
repo = repo,
number = number
)
}
invisible()
}

review_pull_request_integrity <- function(owner, repo, number) {
pull <- gh::gh(
"/repos/:owner/:repo/pulls/:number",
owner = owner,
repo = repo,
number = number
)
commit <- gh::gh(
"GET /repos/:owner/:repo/git/commits/:sha",
owner = owner,
repo = repo,
sha = pull$head$sha
)
if (!isTRUE(commit$verification$verified)) {
pull_request_defer(
owner = owner,
repo = repo,
number = number,
message = paste0(
"The latest commit (",
pull$head$sha,
") of pull request ",
number,
" is unverified. For security reasons, ",
"R-multiverse only merges pull requests with ",
"verified commits. You can create a verified commit ",
"by contributing through the point-and-click web interface ",
"as described at https://r-multiverse.org/contributors.html. ",
"For more information on commit signature verification, please see ",
"https://docs.github.com/en/authentication/",
"managing-commit-signature-verification"
)
)
return(FALSE)
}
TRUE
}

review_pull_request_content <- function(owner, repo, number) {
response <- gh::gh(
"/repos/:owner/:repo/pulls/:number/files",
owner = owner,
Expand All @@ -46,7 +97,7 @@ review_pull_request <- function(
"more text files directly inside 'packages/' with package URLs."
)
)
return(invisible())
return(FALSE)
}
if (!identical(file$status, "added")) {
pull_request_defer(
Expand All @@ -60,7 +111,7 @@ review_pull_request <- function(
"folder."
)
)
return(invisible())
return(FALSE)
}
name <- basename(file$filename)
if (file$additions != 1L) {
Expand All @@ -79,7 +130,7 @@ review_pull_request <- function(
"unless it contains custom JSON (which is uncommon)."
)
)
return(invisible())
return(FALSE)
}
if (!is_character_scalar(file$patch)) {
pull_request_defer(
Expand All @@ -94,7 +145,7 @@ review_pull_request <- function(
"."
)
)
return(invisible())
return(FALSE)
}
url <- gsub(pattern = "^.*\\+", replacement = "", x = file$patch)
url <- gsub(pattern = "\\s.*$", replacement = "", x = url)
Expand All @@ -111,15 +162,10 @@ review_pull_request <- function(
result
)
)
return(invisible())
return(FALSE)
}
}
pull_request_merge(
owner = owner,
repo = repo,
number = number
)
invisible()
TRUE
}

pull_request_close <- function(owner, repo, number, message) {
Expand Down

0 comments on commit adf39ae

Please sign in to comment.