Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore restore-file feature #6171

Merged
merged 3 commits into from
Dec 15, 2022
Merged

Conversation

gamemaker1
Copy link
Contributor

Related Issues

Closes #6155.

Test URLs

https://github.com/gamemaker1/test/pull/1/files

@fregante fregante added the bug label Nov 18, 2022
@fregante fregante changed the title fix: restore restore-file feature Restore restore-file feature Nov 18, 2022
@fregante
Copy link
Member

Did you verify whether this works on PR from forks? This was the issue last time we tried

@fregante
Copy link
Member

This doesn't work when the file contains non-ascii characters unfortunately:

Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.

Screen.Recording.1.mov

See https://stackoverflow.com/a/54302528

I think you should be able to test it on this PR, once fixed, exactly like in my demo. If the file is restored correctly, then we can merge it!

@fregante
Copy link
Member

fregante commented Nov 21, 2022

It's unclear whether this would work correctly with GitHub: https://developer.mozilla.org/en-US/docs/Web/API/btoa#unicode_strings

GitHub’s docs don't go into detail on how to deal with this either: https://docs.github.com/en/rest/repos/contents#create-or-update-file-contents

I wonder if something as simple as this is enough for GitHub: https://stackoverflow.com/a/53221307

@fregante
Copy link
Member

I'm confused as to why we're getting a raw text string and pushing a base64. There must be a way to avoid having to do any conversion. In my first iteration, I was using the API v3 for this, but I had to turn to pushForm for the same issue we had on your last PR:

@gamemaker1
Copy link
Contributor Author

Did you verify whether this works on PR from forks? This was the issue last time we tried

Yes, it works - dabbu-knowledge-platform/test#1

@gamemaker1
Copy link
Contributor Author

I don't see the Restore File button for images :/

image

@gamemaker1
Copy link
Contributor Author

Turns out its because the "Edit file" button is disabled (L120), which makes sense to me.

@gamemaker1
Copy link
Contributor Author

I can't play the video you shared:

image

But it does seem to work with non-ascii characters: dabbu-knowledge-platform/test@776b841

@fregante
Copy link
Member

fregante commented Nov 22, 2022

The non-ASCII files need to be in the previous version, not the "new" one. We fetch and submit the previous version in order to restore it. Try on this PR, I tried restoring the last file in the PR Files list.

As for the video, you can download it and open it with VLC if the browser won't play it

@fregante
Copy link
Member

@gamemaker1 can you finalize this PR? I'd love to ship it this week

@gamemaker1
Copy link
Contributor Author

Done :)

@fregante
Copy link
Member

Neat! I think it works, tested in Chrome and Firefox: refined-github/sandbox#54

Will merge and release a new version soon

const {repository} = await api.v4(`
repository() { # Cache buster ${Math.random()}
pullRequest(number: ${getConversationNumber()!}) {
headRefOid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you avoid this separate call? This specific line just needs to be moved inside getBaseReference and onetime can be removed (also because it can change once you "Update branch in the PR)

source/features/restore-file.tsx Outdated Show resolved Hide resolved
source/features/restore-file.tsx Outdated Show resolved Hide resolved
Comment on lines 97 to 102
// Only allow one click
if (filesRestored.has(menuItem)) {
return;
}

filesRestored.add(menuItem);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can drop this too. It's part of the old logic that kept the menu open to display the status. Thanks to showToast, double-clicks are impossible now

@fregante fregante merged commit 668b90c into refined-github:main Dec 15, 2022
@gamemaker1
Copy link
Contributor Author

Oh I'm sorry I couldn't make the changes quickly, I just saw the review comments :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

restore-file no longer works
2 participants