Repository navigation
delete-branch - New feature - #9974
Conversation
Good questions. GitHub shows the button and then asks for confirmation, with extensive information. We can't show the same popup style so I'm leaning towards not showing the button at all. I don’t think anyone would really want to close a PR this way. So no button.
So GitHub does it in the first case, but not when there's nothing linked to it. However GitHub also has a quick way to restore the deletion a few clicks away, whereas our redirect is more confusing. So yeah let's just use confirm() here. |
fregante
left a comment
There was a problem hiding this comment.
Thanks!
By the way you only need screenshots from one browser. We rarely have browser-specific bugs
quick-branch-deletion - Add button to easily delete branchedelete-branch - Add button to easily delete branche
Test of each pages / modals / layoutOn main branch (should be disabled, we cannot remove main with quick delete)
On new branch inside a fork but not linked to any PR
On new branch outside a fork
When clicking on delete button
When comiting the delete
On branch, but whithout push permission
@fregante Did I miss something ? |
| const pullRequests = await api.v3( | ||
| `/repos/${targetRepository}/pulls?head=${owner}:${branchName}&state=open`, | ||
| ); | ||
|
|
||
| return pullRequests.length === 0; |
There was a problem hiding this comment.
Non-fork repos already show the current PR on the same line, we don't need an API request.
As for fork repos... not sure it's worth the effort... however it seems relatively simple
There was a problem hiding this comment.
Ok !
With the new code, if I am on a non-fork repository, and I am on a branch that has PR.
I have this :
Selector are : &&optional if I have the icon with 1 or something (check on the url) then, I am on a branch that have PR, so we are not able to delete the branch.
If i don't have the icon then, we can delete the branch
All of that in non-fork without querying api.
If I am on a fork + on a branch that is a PR we cannot delete the branch
And, if I am on a fork, with a branch that is not a pr, then, I can delete the branch
| function add(contributeContainer: HTMLElement): void { | ||
| if (elementExists([ | ||
| // No button if there are open PRs | ||
| 'a[class*="PullRequestLink-module"]', | ||
| // No button if the branch is linked to upstream repo (generally the main branch) | ||
| '.octicon-sync', | ||
| ], contributeContainer)) { | ||
| return; |
There was a problem hiding this comment.
No API calls required, all the info we need is on the page
| <button | ||
| type="button" | ||
| className="btn btn-danger rgh-delete-branch" | ||
| ref={withTooltipRef('Delete branch')} |
There was a problem hiding this comment.
The button label was too long and had the wrong text size. GitHub's own trash button is unlabelled
| export function getForkedRepo(): string | undefined { | ||
| return $optional('meta[name="octolytics-dimension-repository_parent_nwo"]')?.content; | ||
| export function getForkedRepo(): `${string}/${string}` | undefined { | ||
| return $optional('meta[name="octolytics-dimension-repository_parent_nwo"]')?.content as |
There was a problem hiding this comment.
This already existed. It turns out we don't need it after all, the information already appears on forks. See open PR link/icon on https://github.com/refined-github/sandbox/tree/sdfsdfds
There was a problem hiding this comment.
Pull request overview
Adds a new Refined GitHub feature that surfaces a “Delete branch” button on branch /tree/* pages, enabling maintainers to delete the currently viewed branch without navigating back to the branches list.
Changes:
- Registered a new
delete-branchfeature in the extension entrypoint. - Implemented the UI + API call to delete the current branch and then redirect.
- Updated README and generated feature metadata snapshots to include the new feature.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| source/refined-github.ts | Registers the new delete-branch feature for loading. |
| source/github-helpers/index.ts | Tightens the return type of getForkedRepo() to a owner/repo template string. |
| source/features/delete-branch.tsx | New feature: injects a delete button and performs the delete request. |
| readme.md | Documents the new feature in the feature list. |
| build/snapshots/imported-features.json | Adds delete-branch to the imported features snapshot. |
| build/snapshots/features-meta.json | Adds metadata entry for delete-branch. |
Suppressed comments (1)
source/features/delete-branch.tsx:71
- The feature is gated behind
pageDetect.isRepoRoot, but the branch info bar only exists on/tree/*pages, so this feature won't run where it's needed. Limit it to repo tree pages and exclude tags/commit permalinks (otherwise the button can appear on tag/SHA views and the delete call will fail).
asLongAs: [
pageDetect.isRepoRoot,
],
requiresToken: true,
init,
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| import features from '../feature-manager.js'; | ||
| import observe from '../helpers/selector-observer.js'; | ||
| import {buildRepoUrl} from '../github-helpers/index.js'; |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
delete-branch - Add button to easily delete branchedelete-branch - New feature












Closes: #8617
I checked if someone already implemented this one, I saw this PR. I used it a little for the rendering of my button. Hope this is good.
Multiple questions are still here :
Number
2is not really required, because we can revert the change on the next page ...Warning
The testing url looks to not be working CF my screen. Then, I choose to use this one instead. BUT, this will work only for maintainer. Other user's who's gonna test the PR, you will have to create a new branch on your own fork or project.
Screen of the page
Test URLs
Screenshot / GIF
GIF are from Chrome, other screenshots are from Firefox / Safari
Workflow from Chrome
Screenshot from Firefox
Screenshot from Safari
Screenshot for README (with green arrow)