diff options
author | 2020-05-28 19:00:10 +0200 | |
---|---|---|
committer | 2020-05-28 19:00:10 +0200 | |
commit | 7589633720493550e359468ffdb4294858b74646 (patch) | |
tree | 9574de3d8a560ff0726fdb1070d561bc7e5d867a /source/features/edit-files-faster.tsx | |
parent | 2235c23dedef9f5ef91cc07c53175e28e5f64b6d (diff) | |
download | refined-github-7589633720493550e359468ffdb4294858b74646.tar.gz refined-github-7589633720493550e359468ffdb4294858b74646.tar.zst refined-github-7589633720493550e359468ffdb4294858b74646.zip |
Meta: improve GitHub URL parser (#3138)
Diffstat (limited to 'source/features/edit-files-faster.tsx')
-rw-r--r-- | source/features/edit-files-faster.tsx | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/source/features/edit-files-faster.tsx b/source/features/edit-files-faster.tsx index 75c1358d..5c306ac3 100644 --- a/source/features/edit-files-faster.tsx +++ b/source/features/edit-files-faster.tsx @@ -6,22 +6,24 @@ import * as pageDetect from 'github-url-detection'; import {wrap} from '../helpers/dom-utils'; import features from '.'; -import parseRoute from '../github-helpers/parse-route'; +import GitHubURL from '../github-helpers/github-url'; import getDefaultBranch from '../github-helpers/get-default-branch'; import onFileListUpdate from '../github-events/on-file-list-update'; async function init(): Promise<void> { - const defaultBranch = await getDefaultBranch(); const isPermalink = /Tag|Tree/.test(select('.branch-select-menu i')!.textContent!); for (const fileIcon of select.all('.files :not(a) > .octicon-file')) { - const {pathname} = fileIcon.closest('tr')!.querySelector<HTMLAnchorElement>('.js-navigation-open')!; - const path = parseRoute(pathname); - path.route = 'edit'; // Replaces /blob/ + const fileLink = fileIcon.closest('tr')!.querySelector<HTMLAnchorElement>('.js-navigation-open')!; + const url = new GitHubURL(fileLink.href).assign({ + route: 'edit' + }); + if (isPermalink) { - path.branch = defaultBranch; // Replaces /${tag|commit}/ + // eslint-disable-next-line no-await-in-loop + url.branch = await getDefaultBranch(); // Permalinks can't be edited } - wrap(fileIcon, <a href={path.toString()} className="rgh-edit-files-faster"/>); + wrap(fileIcon, <a href={String(url)} className="rgh-edit-files-faster"/>); fileIcon.after(<PencilIcon/>); } } |