Skip to content

Conversation

@yakov116
Copy link
Member

@yakov116 yakov116 commented Jun 14, 2020

  1. LINKED ISSUES:
    Closes default-branch-button on forks: add secondary button to see folder on source repo #2985

  2. TEST URLS:
    Any forked repo

  3. SCREENSHOT:
    image

Notes: I "hosted" the function in this feature since I felt that forked-to was getting crowded.

@fregante
Copy link
Member

Also does this feature need a screenshot?

Yes, as small as possible around the repo name and fork link, but include the browser’s status bar to show its different. I did something similar for the “fix view link” feature.

Side Note. This does lead to 404 sometimes

Yeah it happens when the fork has a new file. It’s expected but at the same time it means we’re breaking that link.

What if we send a HEAD request to the link to ensure it works before changing the pathname?

@yakov116
Copy link
Member Author

yakov116 commented Jun 14, 2020

I did something similar for the “fix view link” feature.

I am not sure which feature your talking about.

What if we send a HEAD request to the link to ensure it works before changing the pathname?

Ok I had this idea.
Only if its a single file then check if it exists. I am assuming that usually the fork and the source will have the the same directory's. I can change that if you want.
If it does not exists update the link back to the original link.

At first I awaited the check but that was causing issues with the fork dropdown (When there is more than one fork we make it a drop down).

So I decided not to await it and update the link when api finishes. Its a very simple request and did not take even a second. The worst thing that can happen if someone clicks it before and the file does not exists they will get a 404.

Maybe we should only do this on your own forks?

WDYT?

@yakov116
Copy link
Member Author

Looks like I missed the boat (Ouch) I thought you wanted to check the fork links too if they point to a 404. Correcting.

@fregante
Copy link
Member

I thought you wanted to check the fork links too if they point to a 404.

I didn't think of that, but in that case we're not breaking an native link, it's our own feature.

@yakov116
Copy link
Member Author

I thought you wanted to check the fork links too if they point to a 404.

I didn't think of that, but in that case we're not breaking an native link, it's our own feature.

💯

@yakov116
Copy link
Member Author

yakov116 commented Jun 14, 2020

I timed it to test which one is faster, Api wins.

refined-github.js:8953 fetch: 356.760009765625ms
refined-github.js:8959 api: 132.14990234375ms
refined-github.js:8953 fetch: 694.949951171875ms
refined-github.js:8959 api: 143.827880859375ms
refined-github.js:8953 fetch: 599.36279296875ms
refined-github.js:8959 api: 142.7587890625ms
refined-github.js:8953 fetch: 485.253662109375ms
refined-github.js:8959 api: 3.7099609375ms
refined-github.js:8953 fetch: 451.873779296875ms
refined-github.js:8959 api: 140.218994140625ms


export function getForkedRepo(): string | undefined {
return select<HTMLAnchorElement>('.fork-flag a')?.pathname.slice(1);
return select<HTMLAnchorElement>('.fork-flag a')?.pathname.slice(1).split('/', 2).join('/');
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
return select<HTMLAnchorElement>('.fork-flag a')?.pathname.slice(1).split('/', 2).join('/');
return select<HTMLAnchorElement>('.fork-flag .text a')?.textContent!.trim();

I think this would work here too, no?

Copy link
Member

Choose a reason for hiding this comment

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

I guess. Double-check by blaming the line

Copy link
Member Author

@yakov116 yakov116 Jun 15, 2020

Choose a reason for hiding this comment

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

Looks at the blame and finds a magic comment

Also you could use the same meta tags I used in the isForkedRepo since they're available earlier on the page:

<meta name="octolytics-dimension-repository_parent_nwo" content="sindresorhus/refined-github" />
Suggested change
return select<HTMLAnchorElement>('.fork-flag a')?.pathname.slice(1).split('/', 2).join('/');
return select<HTMLMetaElement>('[name="octolytics-dimension-repository_parent_nwo"]')?.content;

Originally posted by @fregante in #2880

Copy link
Member

Choose a reason for hiding this comment

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

Heh, good job. That's what happens when I review after a merge PR, it gets lost

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this should be put back?

@yakov116
Copy link
Member Author

Also does this feature need a screenshot?

Yes, as small as possible around the repo name and fork link, but include the browser’s status bar to show its different. I did something similar for the “fix view link” feature.

I think all I am missing is a screenshot

Can you point me to it? I am not sure which feature your talking about

@fregante
Copy link
Member

fix-view-file-link-in-pr

https://github.com/sindresorhus/refined-github/blob/4dabb8ce0539222101d39c5329857dafb88327b6/source/features/enable-file-links-in-compare-view.tsx#L61

@yakov116
Copy link
Member Author

@fregante what program do you use? I have a very hard time doing those kind of pictures.

@fregante
Copy link
Member

I'm not talking about the composition, I'm talking about including the status bar (with the URL) in the screenshot when you hover the button, like:

@yakov116 yakov116 marked this pull request as ready for review June 15, 2020 22:07
@fregante
Copy link
Member

The screenshot misses the context entirely. I have no idea what that is. At least include the repo name and don’t zoom too much

@yakov116
Copy link
Member Author

image

Is this good?

@yakov116
Copy link
Member Author

Cleared up a bit. Untested. Do you see any issues?

I can test it in about an hour

@yakov116
Copy link
Member Author

Do you see any issues?

Yes forked-to link is always changed not just on isRepoRoot and isSingleFile.

For example on this PR it send me to https://github.com/yakov116/refined-github/pull/HEAD

Co-authored-by: Fregante <opensource@bfred.it>
Copy link
Member

@fregante fregante left a comment

Choose a reason for hiding this comment

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

Felt like those changes weren't needed at all. createLink was fine in that feature

@fregante
Copy link
Member

fregante commented Jun 18, 2020

Doesn't work again 😅 it points to itself, not the fork source

https://github.com/fregante/refined-github/blob/master/.editorconfig

@yakov116
Copy link
Member Author

Felt like those changes weren't needed at all. createLink was fine in that feature
👍

I love how clean it is now.

@fregante I learn from your coding each day. Thanks!

@yakov116
Copy link
Member Author

@fregante fregante merged commit 6f4ac06 into refined-github:master Jun 18, 2020
@fregante
Copy link
Member

Testing this feature and forked-to should result into this 👍

s

@yakov116 yakov116 deleted the fork-source-link-same-view branch June 18, 2020 12:19
@fregante
Copy link
Member

fregante commented Aug 10, 2020

I think this should also support isEditingFile:

Test link: https://github.com/yakov116/refined-github/edit/upstream/package.json

@yakov116
Copy link
Member Author

yakov116 commented Aug 10, 2020

@fregante I'm on it

Send it just to blob?

@fregante
Copy link
Member

Why would you send it to blob instead of leaving it as edit?

@yakov116
Copy link
Member Author

Less code :). I am working on it will have a pr in a few

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.

default-branch-button on forks: add secondary button to see folder on source repo

2 participants