Skip to content

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

Merged
jennybc merged 9 commits into
mainfrom
lock-unlock
Sep 4, 2025
Merged

jennybc merged 9 commits into
mainfrom
lock-unlock

Conversation

@hadley

@hadley hadley commented Jul 28, 2025

Copy link
Copy Markdown
Member

This ensures that there's no way to accidentally forget that you're in the middle of the release process and make a change to the repo.

Part of #1946

@DavisVaughan it's been a long time since we discussed this, but does this make sense to you?

@jennybc mostly opening to start discussion; not planning to merge just yet.

hadley added 2 commits July 28, 2025 16:05
This ensures that there's no way to accidentally forget that you're in the middle of the release process and make a change to the repo.

Part of #1946

@DavisVaughan DavisVaughan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the positioning makes sense based on what I remember about this

Comment thread R/github_token.R Resolved
Comment thread R/github_token.R Resolved
Comment thread R/github_token.R Resolved
Comment thread R/release.R Resolved
Comment thread R/release.R Resolved
@thomasp85

Copy link
Copy Markdown
Member

Don't have anything to add on top of Davis' comments

@hadley
hadley marked this pull request as ready for review September 2, 2025 22:22
Comment thread NAMESPACE Resolved
Comment thread R/github_token.R Outdated
#' 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)

@jennybc jennybc Sep 4, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right around here we could adapt this code we use in use_release_issue() and use_upkeep_issue() except I guess we just tell people that don't have enough permission to do this:

usethis/R/release.R

Lines 38 to 47 in 0592077

if (!isTRUE(tr$can_push)) {
ui_bullets(c(
"!" = "It is very unusual to open a release issue on a repo you can't push
to ({.val {tr$repo_spec}})."
))
if (ui_nah("Do you really want to do this?")) {
ui_bullets(c("x" = "Cancelling."))
return(invisible())
}
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it's probably fine to let the GitHub error bubble up, and then we can add more user-friendly errors if we discover it's causing substantial confusion.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I went ahead and emitted our own error. It's a big improvement on what happens otherwise:

Letting the gh error bubble up, we get a mysterious 404:

> github_lock_branch()
✔ Setting active project to "/Users/jenny/tmp/nettskjemar".
Run `rlang::last_trace()` to see where the error occurred.
Error in `gh::gh()` at usethis/R/utils-gh.R:6:5:
! GitHub API error (404): Not Found
✖ URL not found:
  <https://api.github.com/repos/cran/nettskjemar/branches/master/protection>
ℹ Read more at
  <https://docs.github.com/rest/branches/branch-protection#update-branch-protection>

If we check for admin permissions and message:

> github_lock_branch()
✔ Setting active project to "/Users/jenny/tmp/nettskjemar".
Run `rlang::last_trace()` to see where the error occurred.
Error in `github_lock_branch()`:
✖ You don't seem to have admin permissions for the source repo
  "cran/nettskjemar", which is required to lock a branch.

Comment thread R/github_token.R Resolved
Looking at other function names we use "github" (vs. "gh") everywhere except `gh_token_help()`. And that is arguably correct, since you could view that function as helping the gh package get a suitable token.
@jennybc

jennybc commented Sep 4, 2025

Copy link
Copy Markdown
Member

The CI failure is because the Air format-suggest workflow is having a bad day. Not relevant.

@jennybc
jennybc merged commit 66d0437 into main Sep 4, 2025
jennybc added a commit that referenced this pull request Sep 4, 2025
I have learned the hard way that we need to more fully reverse github_lock_branch() in order to be able to delete a branch later. Learned with a PR branch. Won't come up often IRL because we will mostly lock / unlock `main`. But still better to leave things as we found them.
@jennybc
jennybc deleted the lock-unlock branch September 5, 2025 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants