@@ -224,101 +224,6 @@ use_github_links <- function(overwrite = FALSE) {
224224 invisible ()
225225}
226226
227- # ' Lock and unlock a branch on GitHub
228- # '
229- # ' @description
230- # ' These functions lock and unlock a branch on GitHub so that it's not possible
231- # ' for anyone to make any changes. They are used in the release checklist
232- # ' generated by [use_release_issue()]. The objective is to ensure that, once
233- # ' you've submitted your package to CRAN, you don't accidentally merge any pull
234- # ' requests or push any commits, while you are waiting for CRAN to get back to
235- # ' you. This, in turn, helps guarantee that your future Git release tag points
236- # ' to the correct commit.
237- # '
238- # ' You must be an admin or an owner of the repo in order to lock/unlock
239- # ' a branch.
240- # '
241- # ' @export
242- # ' @param branch The branch to lock/unlock. If not supplied, uses the
243- # ' default branch which is usually "main" or "master", as determined by
244- # ' [git_default_branch()].
245- github_lock_branch <- function (branch = NULL ) {
246- cfg <- github_remote_config(github_get = TRUE )
247- tr <- target_repo(cfg , role = " source" , ask = FALSE )
248- branch <- branch %|| % git_default_branch_(cfg )
249-
250- if (! isTRUE(tr $ can_admin )) {
251- ui_abort(
252- "
253- You don't seem to have {.field admin} permissions for the source repo
254- {.val {tr$repo_spec}}, which is required to lock a branch."
255- )
256- }
257-
258- gh <- gh_tr(tr )
259- out <- gh(
260- " PUT /repos/{owner}/{repo}/branches/{branch}/protection" ,
261- branch = branch ,
262- # required parameters
263- required_status_checks = NA ,
264- enforce_admins = TRUE ,
265- required_pull_request_reviews = NA ,
266- restrictions = NA ,
267- # paramater that actually does what we want
268- lock_branch = TRUE
269- )
270- result <- pluck_lgl(out , " lock_branch" )
271-
272- if (isTRUE(result )) {
273- ui_bullets(c(
274- " v" = " Branch {.val {branch}} is locked."
275- ))
276- }
277-
278- invisible (out )
279- }
280-
281- # ' @export
282- # ' @rdname github_lock_branch
283- github_unlock_branch <- function (branch = NULL ) {
284- cfg <- github_remote_config(github_get = TRUE )
285- tr <- target_repo(cfg , role = " source" , ask = FALSE )
286- branch <- branch %|| % git_default_branch_(cfg )
287-
288- if (! isTRUE(tr $ can_admin )) {
289- ui_abort(
290- "
291- You don't seem to have {.field admin} permissions for the source repo
292- {.val {tr$repo_spec}}, which is required to unlock a branch."
293- )
294- }
295-
296- gh <- gh_tr(tr )
297- # using the endpoint to update branch protection instead of the one for
298- # deletion, in order to get a response that helps us emit a good message
299- # and invisibly return something useful
300- out <- gh(
301- " PUT /repos/{owner}/{repo}/branches/{branch}/protection" ,
302- branch = branch ,
303- # required parameters
304- required_status_checks = NA ,
305- enforce_admins = FALSE ,
306- required_pull_request_reviews = NA ,
307- restrictions = NA ,
308- # paramater that actually does what we want
309- lock_branch = FALSE
310- )
311- result <- pluck_lgl(out , " lock_branch" )
312-
313- if (isFALSE(result )) {
314- ui_bullets(c(
315- " v" = " Branch {.val {branch}} is unlocked."
316- ))
317- }
318-
319- invisible (out )
320- }
321-
322227has_github_links <- function (target_repo = NULL ) {
323228 url <- if (is.null(target_repo )) NULL else target_repo $ url
324229 github_url <- github_url_from_git_remotes(url )
0 commit comments