Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Meta: Ability to remotely disable broken features - #3530

Merged
fregante merged 16 commits into
refined-github:masterfrom
shinenelson:remote-hotfix-flagging
Sep 13, 2020
Merged

fregante merged 16 commits into
refined-github:masterfrom
shinenelson:remote-hotfix-flagging

Conversation

@shinenelson

@shinenelson shinenelson commented Sep 5, 2020

Copy link
Copy Markdown
Contributor

Closes #3529.

hotfix.json has been added to the repository tree to
indicate the existence of the file in the repository. I have
set the value to { false } for now, but if that might
introduce confusion to contributors, we could delete the file
altogether.

Note : since this is a background feature, I couldn't figure
out a way to test these changes.

@shinenelson
shinenelson force-pushed the remote-hotfix-flagging branch from 0acc631 to a7cc2c8 Compare September 5, 2020 01:07
Comment thread source/features/index.tsx Outdated
Comment thread source/features/index.tsx Outdated
Comment thread source/features/index.tsx Outdated
Comment thread source/features/index.tsx Outdated
Comment thread source/features/index.tsx Outdated
Comment thread source/features/index.tsx Outdated
Comment thread source/features/index.tsx Outdated
@fregante fregante added the meta Related to Refined GitHub itself label Sep 5, 2020
Comment thread source/background.ts Outdated
Comment thread source/features/index.tsx Outdated
Comment thread source/features/index.tsx Outdated
@fregante

fregante commented Sep 5, 2020

Copy link
Copy Markdown
Member

Note : since this is a background feature, I couldn't figure
out a way to test these changes.

To test this:

  1. Know that there's a "clear cache" button in the extension’s option page
  2. Try changing the version in manifest.json to 20.9.3
  3. Reload the extension (this should already clear the cache, thanks to the changes you made in background.ts)
  4. Open https://github.com/sindresorhus/refined-github

The feature cleanup-repo-filelist-actions should be disabled on that page because of this content: https://github.com/sindresorhus/refined-github/blob/hotfix/hotfix.json

  1. Change the version to 20.9.4
  2. Reload the extension
  3. Open https://github.com/sindresorhus/refined-github

The feature cleanup-repo-filelist-actions should now work.

Please ensure it works

@fregante fregante changed the title Add remote hotfix flagging Ability to remotely disable broken features Sep 5, 2020
@fregante
fregante marked this pull request as draft September 5, 2020 22:13
@yakov116

This comment has been minimized.

Comment thread source/features/index.tsx Outdated
@fregante fregante added the Please! ♥︎ Particularly useful features that everyone would love! label Sep 9, 2020
@shinenelson
shinenelson marked this pull request as ready for review September 13, 2020 00:57
@shinenelson

Copy link
Copy Markdown
Contributor Author

after multiple roadblocks and workarounds, I've finally managed to test the feature.

my first issue was with Firefox not able to fetch the hotfix.json file from remote because of a sourceMap error with webpack/webpack#1194 on Firefox which took me down a rabbit hole. I finally gave up and went to Chromium to test the remote fetch.

I realized this early ( during my Firefox testing itself when I over-rode the remote fetch with a hard-coded object ), but my second issue was with the content of hotfix.json itself. The feature name is supposed to be prepended with feature: for it to actually override the value in options.

{"feature:cleanup-repo-filelist-actions": false, "unaffected": "20.9.4"}

Disclaimer : I was only able to confirm that the JSON that is pulled from the remote file is appended to options. Separately, I also tested, provided that the hot-fix value is the right format, then the feature is disabled ( I tested this by hard-coding the value, so I disabled multiple features and all of them were disabled upon reloading the page ).

Also, I noticed that if logging is enabled on the extension, then the disabled feature is logged to the console as Skipping cleanup-repo-filelist-actions <empty string>. It would great if we could somehow trigger the reason in place of <empty string>. I spent some time thinking and looked through the code where we could put this logic, but I couldn't find a place where it would really work. Would it be possible to over-ride the features.add function call or something?

PS : The lint check failing against my last commit 37646fd looks like a false positive. There is no double import in source/background.ts. I ran npm run test and npm run lint multiple times locally ( without errors ) before pushing my last commit to my remote.

Comment thread source/features/index.tsx Outdated
@fregante

Copy link
Copy Markdown
Member

The lint check failing against my last commit 37646fd looks like a false positive

PR checks are tested against the "merge commit". This means that even if not visible, the actual file being tested was https://github.com/sindresorhus/refined-github/blob/817871850908ffa687b0b087d03199f5eed3c40e/source/background.ts#L1-L3

You can see that there are two imports, because one was recently added by 2dc5f26

Thankfully we have this feature to update the PR with those changes and fix them: https://github.com/sindresorhus/refined-github/blob/master/source/features/update-pr-from-base-branch.tsx

@fregante

fregante commented Sep 13, 2020

Copy link
Copy Markdown
Member

I tested this and it works in Chrome, but not in Firefox: neither with window.fetch nor window.content.fetch, apparently due to lack of permission in the former and due to CSP in the latter.

We can't add https://raw.githubusercontent.com to the permission list because the browsers will block the extension and ask the users to re-enable it. The solution is to get the content of the file via API.

You can use api.v3 on this endpoint: https://developer.github.com/v3/repos/contents/#get-repository-content

my second issue was with the content of hotfix.json itself. The feature name is supposed to be prepended with feature: for it to actually override the value in options.

I just updated the contents of hotfix.json now: https://github.com/sindresorhus/refined-github/blob/hotfix/hotfix.json

Comment thread source/features/index.tsx
@shinenelson

shinenelson commented Sep 13, 2020

Copy link
Copy Markdown
Contributor Author

I tested this and it works in Chrome, but not in Firefox: neither with window.fetch nor window.content.fetch, apparently due to lack of permission in the former and due to CSP in the latter.

were you testing with web-ext? that didn't work for me ( as mentioned in my previous comment ), but I was hoping that it would work if it came via an update through the proper channels.

We can't add https://raw.githubusercontent.com to the permission list because the browsers will block the extension and ask the users to re-enable it. The solution is to get the content of the file via API.

Good catch. I'll use the repos/contents API for the fetch.

I just updated the contents of hotfix.json now

thanks. it'll make testing easier for me.

@fregante

fregante commented Sep 13, 2020

Copy link
Copy Markdown
Member

Don’t call the API directly, we have the file api.ts for that. Use

const response = await api.v3('/repos/sindresorhus/refined-github/contents/hotfix.json?ref=hotfix');
const hotfixes = JSON.parse(atob(response.content))

@yakov116

yakov116 commented Sep 13, 2020

Copy link
Copy Markdown
Member

@shinenelson

shinenelson commented Sep 13, 2020

Copy link
Copy Markdown
Contributor Author

I am always skeptical about atob whenever I have used it. So, to be on the safer side, I use Buffer.from everywhere.

I think it makes sense here since this is a web extension and it is only about DOM manipulation and Web APIs. Honestly, I did not see the edited comment and made the changes before I saw the edited comment. If you feel strongly about atob, I can make that change as well but c8ba275 works with Buffer.from though. I've tested it both with Chromium and Firefox.

@shinenelson

shinenelson commented Sep 13, 2020

Copy link
Copy Markdown
Contributor Author

@yakov116 : I noticed this too when I was exploring source/github-helpers/api.ts and pondered over this. I might be wrong here, but I believe L67-L69 creates the domain part of the URL i.e., api.github.com or github.enterprise.com and L109 adds the actual path to the URL.

with GitHub.com :

api3 = https://api.github.com/
query = repos/sindresorhus/refined-github/contents/hotfix.json?ref=hotfix
url = https://api.github.com/repos/sindresorhus/refined-github/contents/hotfix.json?ref=hotfix

with GitHub Enterprise :

location.origin = https://github.enterpise.com
api3 = https://github.enteripse.com/api/v3/
query = repos/sindresorhus/refined-github/contents/hotfix.json?ref=hotfix
url = https://github.enterprise.com/api/v3/repos/sindresorhus/refined-github/contents/hotfix.json?ref=hotfix

is this what you are talking about? or did I miss the point altogether?

@yakov116

Copy link
Copy Markdown
Member

is this what you are talking about?

Yes

@fregante fregante self-assigned this Sep 13, 2020
@fregante fregante removed their assignment Sep 13, 2020
@fregante

Copy link
Copy Markdown
Member

@fregante would that cause issues when run on enterprise?

Good catch. I wanted to use api.v3 specifically to support GHE, but didn't think that it would actually break it

@fregante fregante changed the title Ability to remotely disable broken features Meta: Ability to remotely disable broken features Sep 13, 2020
@fregante
fregante merged commit 3b50862 into refined-github:master Sep 13, 2020
@yakov116

Copy link
Copy Markdown
Member

@fregante I think having an enterprise token will make an issue. Since it includes the token if it exists.

I tried to put in an invalid token and I got

refined-github.js:19790 Uncaught (in promise) Error: The token seems to be incorrect or expired. Update it in the options.
    at getError (refined-github.js:19892)
    at async Module../source/github-helpers/api.ts.mem__WEBPACK_IMPORTED_MODULE_0___default.cacheKey (refined-github.js:19842)
    at async ./source/features/index.tsx.webext_storage_cache__WEBPACK_IMPORTED_MODULE_1__.default.function.maxAge.seconds (refined-github.js:12131)
    at async getSet (refined-github.js:6490)

@fregante

fregante commented Sep 14, 2020

Copy link
Copy Markdown
Member

I tried using api.ts to possibly use the token when making the call, but every “automatic” part comes back to bite us in this case.

Let’s revert to fetch.

@yakov116

yakov116 commented Sep 14, 2020

Copy link
Copy Markdown
Member

Put in the lint pr?

@shinenelson

Copy link
Copy Markdown
Contributor Author

please let me know if I can to help here. does this only involve changing the response variable to use fetch as in 5324689?

@yakov116

Copy link
Copy Markdown
Member

please let me know if I can to help here. does this only involve changing the response variable to use fetch as in 5324689?

	const request = await fetch('https://api.github.com/repos/sindresorhus/refined-github/contents/hotfix.json?ref=hotfix');
	const response = JSON.parse(await request.text());
	const hotfixes: AnyObject | false = JSON.parse(atob(response.content));

You can send a pr. This should be the code.

shinenelson added a commit to shinenelson/refined-github that referenced this pull request Sep 16, 2020
@shinenelson shinenelson mentioned this pull request Sep 16, 2020
shinenelson added a commit to shinenelson/refined-github that referenced this pull request Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

meta Related to Refined GitHub itself Please! ♥︎ Particularly useful features that everyone would love!

Development

Successfully merging this pull request may close these issues.

Ability to remotely disable broken features

3 participants