donnemartin / gitsome

A supercharged Git/GitHub command line interface (CLI). An official integration for GitHub and GitHub Enterprise: https://github.com/works-with/category/desktop-tools
Other
7.56k stars 438 forks source link

Gracefully ignore missing avatar image #147

Closed kBite closed 5 years ago

kBite commented 6 years ago

When Python Image Library is missing, avatar can't be / won't be shown and execution proceeds without further errors / warnings. After installation of Pillow not being able to show avatar breaks gitsome.

$ gh me
To view the avatar in your terminal, install the Python Image Library.
kbite
Followers: 0 | Following: 0

  1.   kbite/sensu (Ruby)
        Stars: 0      Forks: 0      Updated: 1 month(s) ago 
  View the page for 1 through 1 with the following command:
    gh view [#] optional: [-b/--browser] [--help]

$ pip3 install pillow
Collecting pillow
  Downloading https://files.pythonhosted.org/packages/3d/9e/b8a10bec874d2f6f2668b0d71ddf0d0a69ed9307d2ef111607adf81fdc1c/Pillow-5.2.0-cp35-cp35m-manylinux1_x86_64.whl (2.0MB)
    100% |████████████████████████████████| 2.0MB 16.3MB/s 
Installing collected packages: pillow
Successfully installed pillow-5.2.0

$ gh me
File not found: /home/kbite/.gitsomeconfigavatar.png

When gitsome can not display the avatar image, it should gracefully ignore it. In place of the avatar image gitsome should display a message indicating missing avatar and the cause. Result might look like this:

$ gh me
[ INFO ] Avatar could not be displayed (File not found: /home/kbite/.gitsomeconfigavatar.png)
kbite
Followers: 0 | Following: 0

  1.   kbite/sensu (Ruby)
        Stars: 0      Forks: 0      Updated: 1 month(s) ago 
  View the page for 1 through 1 with the following command:
    gh view [#] optional: [-b/--browser] [--help]

Indeed, this is more a workaround to the issue causing File not found: /home/kbite/.gitsomeconfigavatar.png, nevertheless I think gitsome will profit from more robust error handling.


Context to File not found: /home/kbite/.gitsomeconfigavatar.png

EDIT: Explanation of File not found: /home/kbite/.gitsomeconfigavatar.png

We are running GHE in private mode. OAUTH scopes include anything but API calls, and the avatars themselves are outside of the API. Testing it against our GHE dev environment with disabled private mode worked.

I'm trying to use gitsome with our GitHub Enterprise instance, but requesting avatar images from Enterprise isn't the same as the public instance. You can see the differences when explicitly requesting via curl:

$ curl -IL -u kbite https://github.com/kbite.png                                  
Enter host password for user 'kbite':                                            
HTTP/1.1 302 Found                                                              
Server: GitHub.com                                                              
Date: Tue, 07 Aug 2018 14:29:15 GMT                                             
Content-Type: image/png; charset=utf-8                                          
Status: 302 Found                                                               
Cache-Control: no-cache                                                         
Vary: X-PJAX                                                                    
Location: https://avatars1.githubusercontent.com/u/10487288?v=4 

$ curl -IL -u kbite https://github.our-company.net/kbite.png                      
Enter host password for user 'kbite':                                            
HTTP/1.1 302 Found                                                              
Server: GitHub.com                                                              
Date: Tue, 07 Aug 2018 14:29:44 GMT                                             
Content-Type: text/html; charset=utf-8                                          
Status: 302 Found                                                               
Cache-Control: no-cache                                                         
Vary: X-PJAX                                                                    
Location: https://github.our-company.net/login?return_to=https%3A%2F%2Fgithub.our-company.net%2Fkbite.png

Instead of an image (see: Content-Type) Enterprise actually returns the login page's HTML ...

$ file ~/.gitsomeconfigavatar.png
/home/kbite/.gitsomeconfigavatar.png: HTML document, UTF-8 Unicode text, with very long lines

... even though authentication is working correctly:

$ curl -L -u kbite https://github.our-company.net/api/v3/users/kbite      
...                         
{                                                                                  
  "login": "kbite",                                                                
  "id": 12345,                                                                     
  "avatar_url": "https://github.our-company.net/avatars/u/12345?",                 
  "gravatar_id": "",                                                               
...                                                                                
}