Skip to content

Default branch link: add support for forked repos - #1132

Closed
fregante wants to merge 5 commits into
masterfrom
default-branch-link-for-forks
Closed

fregante wants to merge 5 commits into
masterfrom
default-branch-link-for-forks

Conversation

@fregante

@fregante fregante commented Mar 5, 2018 •

Copy link
Copy Markdown
Member

Forks display the default branch as original-repo:original-repos-branch.

This would break the old code.

We can't reliably detect the forks' default branch but in most cases it should match the original repo.

I thought we could support both the current repo's and the original repo's default branch.

Live example: https://github.com/jamiebuilds/refined-github/tree/tooltips/source

Forks display the default branch as `original-repo:original-repos-branch`

We can't reliably detect the forks' default branch but in most cases it should match the original repo.
fregante added 2 commits March 5, 2018 16:36
Uhhh... the branch name was being cached without any reference to the repo's itself, so all repos would point to that branch for the current session
@fregante
fregante force-pushed the default-branch-link-for-forks branch from f8fa9db to ca342fd Compare March 5, 2018 09:43
@fregante
fregante force-pushed the default-branch-link-for-forks branch from 7443cb2 to ca342fd Compare March 12, 2018 11:31
@fregante

Copy link
Copy Markdown
Member Author

It turns out that the links are completely wrong, sadly.

On forks, GitHub compares each branch to respective branches on the origin's… unless they don't exist.

Examples:

New branch on fork: https://github.com/stivaugoin/refined-github/tree/add_pull-request_hotkey

This branch is 4 commits ahead, 1 commit behind sindresorhus:master.

Pre-existing branch on fork: https://github.com/stivaugoin/refined-github/tree/github-follow

This branch is even with sindresorhus:github-follow.

Sadly, there's no way to determine when GitHub refers to the default branch and when it just points to the origin's same-branch.

So we have to remove these buttons from forks altogether.

@fregante fregante closed this Mar 14, 2018
@fregante
fregante deleted the default-branch-link-for-forks branch March 14, 2018 07:12
@sindresorhus

sindresorhus commented Mar 15, 2018 •

Copy link
Copy Markdown
Member

Could we request the data we need by fetching it from a different page or even using the API?

@fregante

fregante commented Mar 15, 2018 •

Copy link
Copy Markdown
Member Author

It looks like it:

❯ curl https://api.github.com/repos/jamiebuilds/refined-github
{
  "id": 121555112,
  "name": "refined-github",
  "full_name": "jamiebuilds/refined-github",
  "default_branch": "master",
  "parent": {
    "id": 51769689,
    "name": "refined-github",
    "full_name": "sindresorhus/refined-github",
    "default_branch": "master"
  },
  "source": {
    "id": 51769689,
    "name": "refined-github",
    "full_name": "sindresorhus/refined-github",
    "default_branch": "master"
  }
  # fields omitted
}

@sindresorhus

Copy link
Copy Markdown
Member

Cool. Let's use the API then.

@fregante

Copy link
Copy Markdown
Member Author

Open a new issue? 😄

Not sure I'll implement it

@sindresorhus

Copy link
Copy Markdown
Member

Done: #1173

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants