Skip to content

Add more details to useful-not-found-page - #4646

Merged
fregante merged 42 commits into
refined-github:mainfrom
gamemaker1:main
Aug 14, 2021
Merged

fregante merged 42 commits into
refined-github:mainfrom
gamemaker1:main

Conversation

@gamemaker1

@gamemaker1 gamemaker1 commented Aug 7, 2021 •

Copy link
Copy Markdown
Contributor

What this PR adds

This PR adds a couple of things mentioned in #4617:

  • If the branch does not exist and the user is trying to view a file on that branch, tell the user that the branch was deleted.
    • In addition, check if the file exists on the default branch (existing behaviour)
  • If the file was deleted/moved, show who did it, when and with which commit. Also link to the last version of the file before the commit took place.
  • If the file was renamed, show who did it, when and with which commit. Also link to the renamed file.

All of the above information is added as the API calls resolve.

Related issues

Closes #4617 (if merged).

Example URLs

Screenshots

Renamed file

refined-github-renamed-file

Moved/deleted file

refined-github-moved-or-deleted-file

Non existent branch (and file does not exist)

refined-github-non-existent-branch-and-no-file

Non existent branch (but file exists on default branch)

refined-github-non-existent-branch-and-file-on-default-branch


Please do let me know if there are any improvements that can be made to the changes made in this PR.

Thanks!

Be more explicit about what happened to the file:

- The file you are looking for was deleted/moved by <username> <time ago>
- You can find the last version of the file <here: link to file before deletion/move>

- The branch you are viewing does not exist

Todos:

- Handle file renaming
@gamemaker1 gamemaker1 changed the title Add more details to [useful-not-found-page](https://github.com/sindresorhus/refined-github/blob/main/source/features/useful-not-found-page.tsx) (#4617) Add more details to useful-not-found-page (#4617) Aug 7, 2021

@fregante fregante left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the PR! Once settled we should also find a less verbose way to show all of this content. For example just:

@gamemaker1

Copy link
Copy Markdown
Contributor Author

A less verbose way to show all of this content. For example just:

* the file was (deleted|renamed) by (commit) (relative-time) - [See commit history](url)

I changed the message to be a bit shorter:

Renamed file

refined-github-renamed-file-shorter-message

Details

refined-github-moved-or-deleted-file-shorter-message

Please let me know if it requires any further changes.

Thanks

@fregante

fregante commented Aug 7, 2021

Copy link
Copy Markdown
Member
  • "The file" can be the link to the last known version
  • Changes are "renamed/moved" and "deleted". We can just stick to "moved" and "deleted" as verbs

@gamemaker1

Copy link
Copy Markdown
Contributor Author

I think we have 2 parallel requests to make:

  • does the file exist on default branch, currently
  • does the file exist in history

If both are false

  • does the file exist in default’s history

If that's also false, the file never existed, the URL is just wrong and we don't add anything else.

  • does the file exist on default branch, currently

We show "The file only exists on the default branch" or "The branch has been deleted, see the file on the default branch"

  • does the file exist in history

We show "The file was deleted" or "The file was moved"

  • does the file exist in default’s history

Same as above, but change the links to point to default (we don't need to say anything about the missing branch)

Thanks a lot, this really helped!

Changes made

I have incorporated all of the changes you suggested, along with some of my own refactoring:

  • Moved the rendering of the file path and striking-through into a seperate function (showWhatIsMissingInPath).

  • Added a function (showAdditionalInformation) which asks what happened (by calling the whatHappenedToTheFile function) and renders something based on the response.

  • Added the function whatHappenedToTheFile, which performs three checks, one after the other:

    • First, it checks if the file exists on the default branch (calls getUrlToFileOnDefaultBranch).

    • Else, it checks if the file exists in commit history on the current branch (calls getLastCommitForFile).

    • Else, it check if the file exists in the default branch's history (calls getLinkToCommitHistoryOnDefaultBranch).

  • The whatHappenedToTheFile function returns an object with a type property. The type can be removed, renamed, isOnDefaultBranch or wasOnDefaultBranch. Based on the type, other properties are also returned:

    • renamed:

      • filePath
      • newFilePath
      • commitSha
      • commitDate
      • linkToCommit
      • linkToLastVersion
      • linkToNewVersion
      • linkToCommitHistory
    • removed:

      • filePath
      • commitSha
      • commitDate
      • linkToCommit
      • linkToLastVersion
      • linkToCommitHistory
    • isOnDefaultBranch:

      • linkToLastVersion
    • wasOnDefaultBranch:

      • linkToCommitHistory
  • Once the whatHappenedToTheFile returns an event object, showAdditionalInformation goes ahead and renders info based on the type.

  • I have also kept renamed and deleted as the verbs instead of renamed and moved/deleted

  • Removed the getType function. I couldn't find a URL that would result in object as the type, so I put in the word file everywhere instead. Let me know if there are any edge cases I might have missed, in which case I will revert this.

  • Largely replaced API calls with some URL manipulation and is404 calls.

Caveats/Problems

  • When a file is renamed, the Github API does not return a link to the previous file (before renaming). I put in a bit of a hack to get a URL to the previous file: I take the sha of the last to last commit (before it was renamed) and generate a blob URL. Please let me know if there is a better way of doing this. Perhaps I should add a is404 check there if we keep this hack.
  • I could not find a test case for the wasOnDefaultBranch case. In my test repo, when I deleted the file and then created a new branch, the commit history was also copied over to the new branch - resulting in the deletion event existing in the history for the current branch as well. So the 404 page shows that the file was deleted instead of it is only on the default branch (see the last screenshot).

Screenshots

Renamed file

refined-github-renamed-file

Deleted file

refined-github-moved-or-deleted-file

Non existent branch (and file does not exist)

refined-github-non-existent-branch-and-no-file

Non existent branch (but file exists on default branch)

refined-github-non-existent-branch-and-file-on-default-branch

`wasOnDefaultBranch` case (repo - https://github.com/gamemaker1/test)

refined-github-was-on-default-branch


Also, sorry for combining so many changes into one commit. I should have split them, it would have been easier to review.

@fregante

fregante commented Aug 7, 2021 •

Copy link
Copy Markdown
Member

Also, sorry for combining so many changes into one commit. I should have split them, it would have been easier to review.

I review the whole code at once, don't worry about splitting the commits. What I'm more concerned about is that 300 lines have been added and we'll have to rethink this to at least halve it.

Also no need to list each detailed change, I can already see the code 😃

@fregante fregante changed the title Add more details to useful-not-found-page (#4617) Add more details to useful-not-found-page Aug 8, 2021
@gamemaker1

Copy link
Copy Markdown
Contributor Author

What I'm more concerned about is that 300 lines have been added and we'll have to rethink this to at least halve it.

It's about 250 lines now (after incorporating your suggestions/changes), I'll try making it smaller.

Refer to GitHubURL to parse the URL, I think it works here as well (I might be wrong)

That worked perfectly, I've replaced most of the parseCurrentUrl calls with GithubURL. Thanks!

@yakov116 yakov116 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Few nit picks

@gamemaker1

Copy link
Copy Markdown
Contributor Author

Added all the changes requested above (including the nitpicks as well as ref.target => object change in the GraphQL query). Let me know if there are any more!

Thanks!

@yakov116 yakov116 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

I tested and it works great!

@fregante any comments?

@fregante

Copy link
Copy Markdown
Member

Types can be improved but let’s get this in for now.

@fregante fregante added the Please! ♥︎ Particularly useful features that everyone would love! label Aug 14, 2021
@fregante

Copy link
Copy Markdown
Member

I’m tagging PRs with “extra wishes” with the Please label, just in case we want to circle back to them in the near future 😬

@fregante
fregante merged commit 6047ca5 into refined-github:main Aug 14, 2021
@fregante

Copy link
Copy Markdown
Member

Thanks @gamemaker1!

@gamemaker1

Copy link
Copy Markdown
Contributor Author

Thanks a lot for your help and guidance on this PR @fregante @yakov116!

kidonng pushed a commit to kidonng/refined-github that referenced this pull request Aug 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Please! ♥︎ Particularly useful features that everyone would love!

Development

Successfully merging this pull request may close these issues.

Add more information to useful-not-found-page

3 participants