Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e29bf5b
Add `fork-source-link-same-view` feature
yakov116 Jun 12, 2020
2bc94db
Remove default
yakov116 Jun 14, 2020
cf9caf3
add `checkIfFileExists`
yakov116 Jun 14, 2020
4003fa2
Feedback
yakov116 Jun 14, 2020
7b6af69
Apply suggestions from code review
yakov116 Jun 15, 2020
0fb6022
Update source/github-helpers/index.ts
yakov116 Jun 15, 2020
9dc1151
Fix build (For now) and add readme (no screenshot yet)
yakov116 Jun 15, 2020
c42ee6e
Feedback
yakov116 Jun 15, 2020
cdfdb9a
Add screenshot
yakov116 Jun 15, 2020
3d56ada
Remove border from image
yakov116 Jun 15, 2020
fc0de93
Update image
yakov116 Jun 16, 2020
70a2ed9
Merge remote-tracking branch 'origin/master' into pr/3230
fregante Jun 16, 2020
bd73a44
Merge remote-tracking branch 'origin/master' into pr/3230
fregante Jun 16, 2020
b212e92
Functional programming
fregante Jun 16, 2020
43c1e9f
Enable` fork-source-link-same-view` on 2 specific pages
fregante Jun 16, 2020
3324db0
Replace shared function with specific, local logic
fregante Jun 16, 2020
d06d40f
Avoid check that never happens
fregante Jun 16, 2020
91f631a
Point to the default branch instead of `HEAD`
fregante Jun 16, 2020
2cba76b
Update source/features/forked-to.tsx
yakov116 Jun 16, 2020
5d52acc
Dont like it, but it works
yakov116 Jun 16, 2020
963e26d
doesFileExists to its own file
yakov116 Jun 16, 2020
f1664f0
Revert forked-to.tsx
fregante Jun 18, 2020
275f2ac
Merge line
fregante Jun 18, 2020
6cc6eac
Partial fix
fregante Jun 18, 2020
6044764
Restore index.ts
fregante Jun 18, 2020
b7461a5
Use forked repository again
fregante Jun 18, 2020
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
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Thanks for contributing! 🦋🙌
- [](# "repo-age") [Adds the age of the repository to the statistics bar.](https://user-images.githubusercontent.com/3848317/69494069-7d2b1180-0eb7-11ea-9aa1-d4194e566340.png)
- [](# "show-open-prs-of-forks") [In your forked repos, shows number of your open PRs to the original repo.](https://user-images.githubusercontent.com/1922624/76398271-e0648500-637c-11ea-8210-53dda1be9d51.png)
- [](# "go-to-action-from-file") [Adds a link to access the past runs of a GitHub Action workflow when seeing the workflow configuration file.](https://user-images.githubusercontent.com/1402241/80146153-ab6d6400-85b1-11ea-9f38-e87950692a62.png)
- [](# "fork-source-link-same-view") [Points the “Forked from user/repository” link to current folder or file in the upstream repository.](https://user-images.githubusercontent.com/1402241/84795784-3722d000-aff8-11ea-9b34-97c01acf4fd4.png)

<!-- Refer to style guide above. Keep this message between sections. -->

Expand Down
37 changes: 37 additions & 0 deletions source/features/fork-source-link-same-view.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '.';
import GitHubURL from '../github-helpers/github-url';
import doesFileExist from '../github-helpers/does-file-exist';
import getDefaultBranch from '../github-helpers/get-default-branch';
import {getRepositoryInfo, getForkedRepo} from '../github-helpers';

async function init(): Promise<void> {
const forkedRepository = getRepositoryInfo(getForkedRepo());
const sameViewUrl = new GitHubURL(location.href).assign({
user: forkedRepository.owner,
repository: forkedRepository.name,
branch: await getDefaultBranch(forkedRepository)
});

if (await doesFileExist(sameViewUrl)) {
select<HTMLAnchorElement>('.fork-flag .text a')!.pathname = sameViewUrl.pathname;
}
}

void features.add({
id: __filebasename,
description: 'Points the “Forked from user/repository” link to current folder or file in the upstream repository.',
screenshot: 'https://user-images.githubusercontent.com/1402241/84795784-3722d000-aff8-11ea-9b34-97c01acf4fd4.png'
}, {
include: [
pageDetect.isSingleFile,
pageDetect.isRepoTree
],
exclude: [
() => !pageDetect.isForkedRepo(),
() => pageDetect.isRepoRoot()
],
init
});
14 changes: 14 additions & 0 deletions source/github-helpers/does-file-exist.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as api from './api';
import GitHubURL from './github-url';

export default async function doesFileExist(url: GitHubURL): Promise<boolean> {
const {repository} = await api.v4(`
repository(owner: "${url.user}", name: "${url.repository}") {
file: object(expression: "${url.branch}:${url.filePath}") {
id
}
}
`);

return Boolean(repository.file);
}
1 change: 1 addition & 0 deletions source/refined-github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ import './features/prevent-pr-commit-link-loss';
import './features/first-published-tag-for-merged-pr';
import './features/show-associated-branch-prs-on-fork';
import './features/faster-reviews';
import './features/fork-source-link-same-view';

// Add global for easier debugging
(window as any).select = select;