-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
link-to-file-in-file-history
feature (#2000)
Co-authored-by: Federico Brigante <github@bfred.it>
- Loading branch information
1 parent
3150af6
commit ad17f06
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
source/features/filter-pr-by-build-status.tsx @HardikModha | ||
source/features/tags-dropdown.tsx @HardikModha | ||
source/features/link-to-file-in-file-history.tsx @HardikModha | ||
source/features/default-to-rich-diff.tsx @idasbiste |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
Adds direct link to file/directory when viewing the history. | ||
See it in action at https://github.com/sindresorhus/refined-github/commits/master/readme.md | ||
*/ | ||
|
||
import React from 'dom-chef'; | ||
import select from 'select-dom'; | ||
import features from '../libs/features'; | ||
import {file} from '../libs/icons'; | ||
import {getRepoPath} from '../libs/utils'; | ||
import {groupSiblings} from '../libs/group-buttons'; | ||
|
||
function init(): void | false { | ||
// /user/repo/commits/master/readme.md -> 'readme.md' | ||
// /user/repo/commits/master/ -> '' | ||
const path = getRepoPath()!.replace(/^commits\/[^/]+\//, ''); | ||
if (!path) { | ||
return false; | ||
} | ||
|
||
for (const rootLink of select.all<HTMLAnchorElement>('[aria-label="Browse the repository at this point in the history"]')) { | ||
// `rootLink.pathname` points to /tree/ but GitHub automatically redirects to /blob/ when the path is of a file | ||
rootLink.before( | ||
<a | ||
href={rootLink.pathname + '/' + path} | ||
className="btn btn-outline tooltipped tooltipped-sw" | ||
aria-label="See object at this point in the history" | ||
> | ||
{file()} | ||
</a> | ||
); | ||
|
||
// TODO: drop `as` after https://github.com/Microsoft/TSJS-lib-generator/pull/697 | ||
(rootLink.closest('.commit-links-cell') as HTMLElement).style.width = 'auto'; | ||
|
||
groupSiblings(rootLink); | ||
} | ||
} | ||
|
||
features.add({ | ||
id: 'link-to-file-in-file-history', | ||
include: [ | ||
features.isCommitList | ||
], | ||
load: features.onAjaxedPages, | ||
init | ||
}); |