Skip to content

Lock and unlock branch as part of the release process #2145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export(edit_r_profile)
export(edit_rstudio_prefs)
export(edit_rstudio_snippets)
export(edit_template)
export(gh_lock_branch)
export(gh_token_help)
export(gh_unlock_branch)
export(git_branch_default)
export(git_default_branch)
export(git_default_branch_configure)
Expand Down
53 changes: 50 additions & 3 deletions R/github_token.R
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,12 @@ scold_for_scopes <- function(scopes) {

suggestions <- c(
"*" = if (!has_repo) "{.val repo}: needed to fully access user's repos",
"*" = if (!has_workflow)
"{.val workflow}: needed to manage GitHub Actions workflow files",
"*" = if (!has_user_email)
"*" = if (!has_workflow) {
"{.val workflow}: needed to manage GitHub Actions workflow files"
},
"*" = if (!has_user_email) {
"{.val user:email}: needed to read user's email addresses"
}
)
message <- c(
"!" = "Token lacks recommended scopes:",
Expand All @@ -294,3 +296,48 @@ scold_for_scopes <- function(scopes) {
)
ui_bullets(message)
}

#' Lock and unlock a branch on GitHub
#'
#' These functions lock and unlock a branch on GitHub so that it's not possible
#' for anyone to make any changes. This is used as part of the release process
#' to ensure that you don't accidentally merge any pull requests or push any
#' commits while you are waiting for CRAN to get back to you.
Comment on lines +302 to +305
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything about permissions required to perform this action?

#'
#' @export
#' @param branch The branch to lock/unlock. If not supplied, uses the
#' default branch with is usually "main" or "master".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#' default branch with is usually "main" or "master".
#' default branch which is usually "main" or "master".

gh_lock_branch <- function(branch = NULL) {
cfg <- github_remote_config(github_get = TRUE)
repo <- target_repo(cfg)
branch <- branch %||% git_default_branch_(cfg)

invisible(gh::gh(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you lock an already locked branch?

"PUT /repos/{owner}/{repo}/branches/{branch}/protection",
owner = repo$repo_owner,
repo = repo$repo_name,
branch = branch,
# required parameters
required_status_checks = NA,
enforce_admins = TRUE,
required_pull_request_reviews = NA,
restrictions = NA,
# paramter that actually does what we want
lock_branch = TRUE
))
}

#' @export
#' @rdname gh_lock_branch
gh_unlock_branch <- function(branch = NULL) {
cfg <- github_remote_config(github_get = TRUE)
repo <- target_repo(cfg)
branch <- branch %||% git_default_branch_(cfg)

invisible(gh::gh(
"DELETE /repos/{owner}/{repo}/branches/{branch}/protection",
owner = repo$repo_owner,
repo = repo$repo_name,
branch = branch
))
}
7 changes: 5 additions & 2 deletions R/release.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ release_checklist <- function(version, on_cran, target_repo = NULL) {
milestone_num <- gh_milestone_number(target_repo, version)

c(
if (!on_cran)
if (!on_cran) {
c(
"First release:",
"",
Expand All @@ -100,7 +100,8 @@ release_checklist <- function(version, on_cran, target_repo = NULL) {
),
todo("Review <https://github.com/DavisVaughan/extrachecks>"),
""
),
)
},
"Prepare for release:",
"",
todo("`git pull`"),
Expand Down Expand Up @@ -137,13 +138,15 @@ release_checklist <- function(version, on_cran, target_repo = NULL) {
"",
"Submit to CRAN:",
"",
todo("`usethis::gh_lock_branch()"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
todo("`usethis::gh_lock_branch()"),
todo("`usethis::gh_lock_branch()`"),

todo("`usethis::use_version('{type}')`"),
todo("`devtools::submit_cran()`"),
todo("Approve email"),
"",
"Wait for CRAN...",
"",
todo("Accepted :tada:"),
todo("`usethis::gh_unlock_branch()"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
todo("`usethis::gh_unlock_branch()"),
todo("`usethis::gh_unlock_branch()`"),

todo("Finish & publish blog post", type != "patch"),
todo("Add link to blog post in pkgdown news menu", type != "patch"),
todo("`usethis::use_github_release()`"),
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ reference:
- starts_with("use_github")
- git_sitrep
- create_github_token
- gh_lock_branch
- gh_token_help
- git_vaccinate
- use_git_config
Expand Down
21 changes: 21 additions & 0 deletions man/gh_lock_branch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/testthat/_snaps/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@

Submit to CRAN:

* [ ] `usethis::gh_lock_branch()
* [ ] `usethis::use_version('minor')`
* [ ] `devtools::submit_cran()`
* [ ] Approve email

Wait for CRAN...

* [ ] Accepted :tada:
* [ ] `usethis::gh_unlock_branch()
* [ ] Finish & publish blog post
* [ ] Add link to blog post in pkgdown news menu
* [ ] `usethis::use_github_release()`
Expand Down Expand Up @@ -61,13 +63,15 @@

Submit to CRAN:

* [ ] `usethis::gh_lock_branch()
* [ ] `usethis::use_version('patch')`
* [ ] `devtools::submit_cran()`
* [ ] Approve email

Wait for CRAN...

* [ ] Accepted :tada:
* [ ] `usethis::gh_unlock_branch()
* [ ] `usethis::use_github_release()`
* [ ] `usethis::use_dev_version(push = TRUE)`
* [ ] `usethis::use_news_md()`
Expand All @@ -94,13 +98,15 @@

Submit to CRAN:

* [ ] `usethis::gh_lock_branch()
* [ ] `usethis::use_version('major')`
* [ ] `devtools::submit_cran()`
* [ ] Approve email

Wait for CRAN...

* [ ] Accepted :tada:
* [ ] `usethis::gh_unlock_branch()
* [ ] Finish & publish blog post
* [ ] Add link to blog post in pkgdown news menu
* [ ] `usethis::use_github_release()`
Expand Down Expand Up @@ -150,13 +156,15 @@

Submit to CRAN:

* [ ] `usethis::gh_lock_branch()
* [ ] `usethis::use_version('major')`
* [ ] `devtools::submit_cran()`
* [ ] Approve email

Wait for CRAN...

* [ ] Accepted :tada:
* [ ] `usethis::gh_unlock_branch()
* [ ] Finish & publish blog post
* [ ] Add link to blog post in pkgdown news menu
* [ ] `usethis::use_github_release()`
Expand Down Expand Up @@ -185,13 +193,15 @@

Submit to CRAN:

* [ ] `usethis::gh_lock_branch()
* [ ] `usethis::use_version('major')`
* [ ] `devtools::submit_cran()`
* [ ] Approve email

Wait for CRAN...

* [ ] Accepted :tada:
* [ ] `usethis::gh_unlock_branch()
* [ ] Finish & publish blog post
* [ ] Add link to blog post in pkgdown news menu
* [ ] `usethis::use_github_release()`
Expand Down
Loading