Skip to content

Commit

Permalink
Meta: Reorganize utility functions (refined-github#3110)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored May 19, 2020
1 parent 508c93a commit f9d8b7a
Show file tree
Hide file tree
Showing 185 changed files with 391 additions and 476 deletions.
5 changes: 3 additions & 2 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The simplest usage of `feature.add` is the following. This will be run instantly

```js
import * as pageDetect from 'github-url-detection';
import features from '../libs/features';
import features from '.';

function init () {
console.log('');
Expand All @@ -47,7 +47,8 @@ import React from 'dom-chef';
import select from 'select-dom';
import delegate from 'delegate-it';
import * as pageDetect from 'github-url-detection';
import features from '../libs/features';

import features from '.';

function append(event: delegate.Event<MouseEvent, HTMLButtonElement>): void {
event.delegateTarget.after('', <div className="rgh-jsx-element">Button clicked!</div>);
Expand Down
2 changes: 1 addition & 1 deletion source/features/action-used-by-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import select from 'select-dom';
import SearchIcon from 'octicon/search.svg';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import features from '.';

function init(): void {
const actionRepo = select('aside .octicon-repo')!
Expand Down
6 changes: 3 additions & 3 deletions source/features/add-tag-to-commits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import select from 'select-dom';
import TagIcon from 'octicon/tag.svg';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import * as api from '../libs/api';
import {getOwnerAndRepo, getRepoURL, getRepoGQL} from '../libs/utils';
import features from '.';
import * as api from '../github-helpers/api';
import {getOwnerAndRepo, getRepoURL, getRepoGQL} from '../github-helpers';

interface CommitTags {
[name: string]: string[];
Expand Down
2 changes: 1 addition & 1 deletion source/features/align-issue-labels.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './align-issue-labels.css';
import features from '../libs/features';
import features from '.';

function init(): void {
document.body.classList.add('rgh-align-issue-labels');
Expand Down
2 changes: 1 addition & 1 deletion source/features/batch-mark-files-as-viewed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import select from 'select-dom';
import delegate from 'delegate-it';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import features from '.';

let previousFile: HTMLElement | undefined;

Expand Down
2 changes: 1 addition & 1 deletion source/features/batch-open-issues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import delegate from 'delegate-it';
import elementReady from 'element-ready';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import features from '.';

const confirmationRequiredCount = 10;

Expand Down
8 changes: 4 additions & 4 deletions source/features/bugs-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import elementReady from 'element-ready';
import * as pageDetect from 'github-url-detection';
import BugIcon from '@primer/octicons/build/svg/bug.svg';

import * as api from '../libs/api';
import features from '../libs/features';
import SearchQuery from '../libs/search-query';
import {getRepoURL} from '../libs/utils';
import features from '.';
import * as api from '../github-helpers/api';
import SearchQuery from '../github-helpers/search-query';
import {getRepoURL} from '../github-helpers';

const numberFormatter = new Intl.NumberFormat();
const countBugs = cache.function(async (): Promise<number> => {
Expand Down
4 changes: 2 additions & 2 deletions source/features/bypass-checks.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import fetchDom from '../libs/fetch-dom';
import features from '.';
import fetchDom from '../helpers/fetch-dom';

async function init(): Promise<void> {
// This selector excludes URLs that are already external
Expand Down
8 changes: 4 additions & 4 deletions source/features/ci-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import './ci-link.css';
import oneTime from 'onetime';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import fetchDom from '../libs/fetch-dom';
import {getRepoURL} from '../libs/utils';
import {appendBefore} from '../libs/dom-utils';
import features from '.';
import fetchDom from '../helpers/fetch-dom';
import {getRepoURL} from '../github-helpers';
import {appendBefore} from '../helpers/dom-utils';

// Look for the CI icon in the latest 2 days of commits #2990
const getIcon = oneTime(fetchDom.bind(null,
Expand Down
6 changes: 3 additions & 3 deletions source/features/clean-issue-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import cache from 'webext-storage-cache';
import elementReady from 'element-ready';
import * as pageDetect from 'github-url-detection';

import * as api from '../libs/api';
import features from '../libs/features';
import {getOwnerAndRepo, getRepoURL, getRepoGQL} from '../libs/utils';
import features from '.';
import * as api from '../github-helpers/api';
import {getOwnerAndRepo, getRepoURL, getRepoGQL} from '../github-helpers';

const hasAnyProjects = cache.function(async (): Promise<boolean> => {
const {repository, organization} = await api.v4(`
Expand Down
2 changes: 1 addition & 1 deletion source/features/clean-rich-text-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './clean-rich-text-editor.css';
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import features from '.';

function hideButtons(): void {
document.body.classList.add('rgh-clean-rich-text-editor');
Expand Down
6 changes: 3 additions & 3 deletions source/features/clean-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import select from 'select-dom';
import oneTime from 'onetime';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import onReplacedElement from '../libs/on-replaced-element';
import onElementRemoval from '../libs/on-element-removal';
import features from '.';
import onReplacedElement from '../helpers/on-replaced-element';
import onElementRemoval from '../helpers/on-element-removal';

const canEditSidebar = oneTime((): boolean => select.exists('.sidebar-labels .octicon-gear'));

Expand Down
4 changes: 2 additions & 2 deletions source/features/clear-pr-merge-commit-message.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import onPrMergePanelOpen from '../libs/on-pr-merge-panel-open';
import features from '.';
import onPrMergePanelOpen from '../github-events/on-pr-merge-panel-open';

function init(): void {
const messageField = select<HTMLTextAreaElement>('#merge_message_field')!;
Expand Down
10 changes: 5 additions & 5 deletions source/features/clone-branch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import gitBranch from 'octicon/git-branch.svg';
import * as textFieldEdit from 'text-field-edit';
import * as pageDetect from 'github-url-detection';

import * as api from '../libs/api';
import features from '../libs/features';
import LoadingIcon from '../libs/icon-loading';
import {getRepoURL, getRepoGQL} from '../libs/utils';
import observeElement from '../libs/simplified-element-observer';
import features from '.';
import * as api from '../github-helpers/api';
import LoadingIcon from '../github-helpers/icon-loading';
import {getRepoURL, getRepoGQL} from '../github-helpers';
import observeElement from '../helpers/simplified-element-observer';

const getBranchBaseSha = async (branchName: string): Promise<string> => {
const {repository} = await api.v4(`
Expand Down
5 changes: 2 additions & 3 deletions source/features/close-out-of-view-modals.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import delegate from 'delegate-it';

import features from '../libs/features';
import {logError} from '../libs/utils';
import features from '.';

const observer = new IntersectionObserver(([{intersectionRatio, target}]) => {
if (intersectionRatio === 0) {
Expand All @@ -17,7 +16,7 @@ function init(): void {
setTimeout(() => {
const modalBox = summary.parentElement!.querySelector('details-menu')!;
if (modalBox.getBoundingClientRect().width === 0) {
logError(__filebasename, 'Modal element was not correctly detected for', summary);
features.error(__filebasename, 'Modal element was not correctly detected for', summary);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion source/features/collapsible-content-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import FoldDownIcon from 'octicon/fold-down.svg';
import * as textFieldEdit from 'text-field-edit';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import features from '.';

// Wraps string in at least 2 \n on each side,
// as long as the field doesn't already have them.
Expand Down
2 changes: 1 addition & 1 deletion source/features/comment-fields-keyboard-shortcuts.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import select from 'select-dom';
import delegate from 'delegate-it';

import features from '../libs/features';
import features from '.';

// eslint-disable-next-line import/prefer-default-export
export function listenToCommentFields(callback: delegate.EventHandler<KeyboardEvent, HTMLTextAreaElement>): void {
Expand Down
6 changes: 3 additions & 3 deletions source/features/comments-time-machine-links.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import select from 'select-dom';
import ClockIcon from 'octicon/clock.svg';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import {getRepoURL} from '../libs/utils';
import {appendBefore} from '../libs/dom-utils';
import features from '.';
import {getRepoURL} from '../github-helpers';
import {appendBefore} from '../helpers/dom-utils';

function addInlineLinks(comment: HTMLElement, timestamp: string): void {
const links = select.all<HTMLAnchorElement>(`
Expand Down
4 changes: 2 additions & 2 deletions source/features/conflict-marker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import select from 'select-dom';
import AlertIcon from 'octicon/alert.svg';
import * as pageDetect from 'github-url-detection';

import * as api from '../libs/api';
import features from '../libs/features';
import features from '.';
import * as api from '../github-helpers/api';

interface PRConfig {
number: string;
Expand Down
2 changes: 1 addition & 1 deletion source/features/copy-file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import delegate from 'delegate-it';
import * as pageDetect from 'github-url-detection';
import copyToClipboard from 'copy-text-to-clipboard';

import features from '../libs/features';
import features from '.';

function handleClick({delegateTarget: button}: delegate.Event<MouseEvent, HTMLButtonElement>): void {
const file = button.closest('.Box, .js-gist-file-update-container')!;
Expand Down
2 changes: 1 addition & 1 deletion source/features/copy-on-y.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import select from 'select-dom';
import * as pageDetect from 'github-url-detection';
import copyToClipboard from 'copy-text-to-clipboard';

import features from '../libs/features';
import features from '.';

const handler = ({key, target}: KeyboardEvent): void => {
if (key === 'y' && (target as Element).nodeName !== 'INPUT') {
Expand Down
2 changes: 1 addition & 1 deletion source/features/create-release-shortcut.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import features from '.';

function init(): void {
const createReleaseButton = select('a[href$="/releases/new"]:not([data-hotkey])');
Expand Down
4 changes: 2 additions & 2 deletions source/features/cross-deleted-pr-branches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import React from 'dom-chef';
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import {wrap} from '../libs/dom-utils';
import features from '../libs/features';
import {wrap} from '../helpers/dom-utils';
import features from '.';

function init(): void {
const lastBranchAction = select.last('.TimelineItem-body .user-select-contain > span:not(.base-ref)');
Expand Down
2 changes: 1 addition & 1 deletion source/features/cycle-lists-with-keyboard-shortcuts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import select from 'select-dom';
import delegate from 'delegate-it';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import features from '.';

function init(): void {
let selectableItems: HTMLElement[] = [];
Expand Down
8 changes: 4 additions & 4 deletions source/features/deep-reblame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import delegate from 'delegate-it';
import VersionIcon from 'octicon/versions.svg';
import * as pageDetect from 'github-url-detection';

import * as api from '../libs/api';
import features from '../libs/features';
import LoadingIcon from '../libs/icon-loading';
import {getRepoGQL, looseParseInt, parseRoute} from '../libs/utils';
import features from '.';
import * as api from '../github-helpers/api';
import LoadingIcon from '../github-helpers/icon-loading';
import {getRepoGQL, looseParseInt, parseRoute} from '../github-helpers';

const getPullRequestBlameCommit = mem(async (commit: string, prNumber: number, currentFilename: string): Promise<string> => {
const {repository} = await api.v4(`
Expand Down
8 changes: 4 additions & 4 deletions source/features/default-branch-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import elementReady from 'element-ready';
import * as pageDetect from 'github-url-detection';
import ChevronLeftIcon from 'octicon/chevron-left.svg';

import features from '../libs/features';
import {groupButtons} from '../libs/group-buttons';
import getDefaultBranch from '../libs/get-default-branch';
import {getRepoURL, getCurrentBranch, replaceBranch, parseRoute} from '../libs/utils';
import features from '.';
import {groupButtons} from '../github-helpers/group-buttons';
import getDefaultBranch from '../github-helpers/get-default-branch';
import {getRepoURL, getCurrentBranch, replaceBranch, parseRoute} from '../github-helpers';

async function init(): Promise<false | void> {
const defaultBranch = await getDefaultBranch();
Expand Down
2 changes: 1 addition & 1 deletion source/features/deprioritize-marketplace-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import domLoaded from 'dom-loaded';
import elementReady from 'element-ready';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import features from '.';

async function init(): Promise<void> {
const marketPlaceLink = (await elementReady('.Header-link[href="/marketplace"]'));
Expand Down
2 changes: 1 addition & 1 deletion source/features/dim-bots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './dim-bots.css';
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import features from '.';

function init(): void {
const bots = select.all([
Expand Down
4 changes: 2 additions & 2 deletions source/features/discussion-links-on-repo-lists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import IssueIcon from 'octicon/issue-opened.svg';
import * as pageDetect from 'github-url-detection';
import PullRequestIcon from 'octicon/git-pull-request.svg';

import features from '../libs/features';
import observeElement from '../libs/simplified-element-observer';
import features from '.';
import observeElement from '../helpers/simplified-element-observer';

function init(): void {
const repositories = select.all<HTMLAnchorElement>([
Expand Down
2 changes: 1 addition & 1 deletion source/features/download-folder-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'dom-chef';
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import features from '.';

function init(): void {
select('.file-navigation .BtnGroup.float-right')?.prepend(
Expand Down
2 changes: 1 addition & 1 deletion source/features/edit-comments-faster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import select from 'select-dom';
import PencilIcon from 'octicon/pencil.svg';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import features from '.';

function init(): void {
const menuItems = select.all('details .js-comment-edit-button:not(.rgh-edit-comment)');
Expand Down
10 changes: 5 additions & 5 deletions source/features/edit-files-faster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import select from 'select-dom';
import PencilIcon from 'octicon/pencil.svg';
import * as pageDetect from 'github-url-detection';

import {wrap} from '../libs/dom-utils';
import features from '../libs/features';
import {parseRoute} from '../libs/utils';
import getDefaultBranch from '../libs/get-default-branch';
import onFileListUpdate from '../libs/on-file-list-update';
import {wrap} from '../helpers/dom-utils';
import features from '.';
import {parseRoute} from '../github-helpers';
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();
Expand Down
6 changes: 3 additions & 3 deletions source/features/edit-readme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import select from 'select-dom';
import PencilIcon from 'octicon/pencil.svg';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import {parseRoute} from '../libs/utils';
import getDefaultBranch from '../libs/get-default-branch';
import features from '.';
import {parseRoute} from '../github-helpers';
import getDefaultBranch from '../github-helpers/get-default-branch';

async function init(): Promise<void | false> {
const readmeHeader = select('#readme .Box-header h2');
Expand Down
4 changes: 2 additions & 2 deletions source/features/embed-gist-inline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import domify from 'doma';
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '../libs/features';
import {isFirefox} from '../libs/utils';
import features from '.';
import {isFirefox} from '../github-helpers';

const isGist = (link: HTMLAnchorElement): boolean =>
!link.pathname.includes('.') && // Exclude links to embed files
Expand Down
Loading

0 comments on commit f9d8b7a

Please sign in to comment.