Skip to content

Commit

Permalink
Show whether feature is hotfixed in rgh-feature-descriptions (#6396)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Mar 2, 2023
1 parent f70deaa commit 6c9f180
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
29 changes: 29 additions & 0 deletions source/features/rgh-feature-descriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import './rgh-feature-descriptions.css';
import React from 'dom-chef';
import * as pageDetect from 'github-url-detection';
import {CopyIcon} from '@primer/octicons-react';
import cache from 'webext-storage-cache';

import features from '../feature-manager';
import {featuresMeta} from '../../readme.md';
import {getNewFeatureName} from '../options-storage';
import {isRefinedGitHubRepo} from '../github-helpers';
import observe from '../helpers/selector-observer';
import {HotfixStorage} from '../helpers/hotfix';
import {createRghIssueLink} from '../helpers/rgh-issue-link';

async function add(infoBanner: HTMLElement): Promise<void> {
const [, currentFeature] = /source\/features\/([^.]+)/.exec(location.pathname) ?? [];
Expand Down Expand Up @@ -63,6 +66,23 @@ async function add(infoBanner: HTMLElement): Promise<void> {
</div>
</div>,
);

// Skip dev check present in `getLocalHotfixes`, we want to see this even when developing
const hotfixes = await cache.get<HotfixStorage>('hotfixes:') ?? [];

const hotfixed = hotfixes.find(([feature]) => feature === currentFeatureName);
if (!hotfixed) {
return;
}

const [_name, issue, unaffectedVersion] = hotfixed;

infoBanner.before(
<div className="mb-3 d-inline-block width-full flash flash-warn mb-2">
<strong>Note:</strong> This feature is disabled due to {createRghIssueLink(issue)}
{unaffectedVersion && ` until version ${unaffectedVersion}`}
</div>,
);
}

function init(signal: AbortSignal): void {
Expand All @@ -78,3 +98,12 @@ void features.add(import.meta.url, {
],
init,
});

/*
Test URLs:
- https://github.com/refined-github/refined-github/blob/main/source/features/sync-pr-commit-title.tsx
- https://github.com/refined-github/refined-github/blob/main/source/features/clean-conversation-sidebar.css
*/
4 changes: 2 additions & 2 deletions source/helpers/hotfix.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function fetchHotfix(path: string): Promise<string> {
return '';
}

export type HotfixStorage = Array<[FeatureID, string]>;
export type HotfixStorage = Array<[FeatureID, string, string]>;

export const updateHotfixes = cache.function('hotfixes', async (version: string): Promise<HotfixStorage> => {
const content = await fetchHotfix('broken-features.csv');
Expand All @@ -44,7 +44,7 @@ export const updateHotfixes = cache.function('hotfixes', async (version: string)
const storage: HotfixStorage = [];
for (const [featureID, relatedIssue, unaffectedVersion] of parseCsv(content)) {
if (featureID && relatedIssue && (!unaffectedVersion || compareVersions(unaffectedVersion, version) > 0)) {
storage.push([featureID as FeatureID, relatedIssue]);
storage.push([featureID as FeatureID, relatedIssue, unaffectedVersion]);
}
}

Expand Down

0 comments on commit 6c9f180

Please sign in to comment.