Repository: pymedusa/Medusa

Issue:
Github Personal Acces Token
### Before submitting your issue:

Enable debug logging in Medusa settings, reproduce the error (be sure to disable after the bug is fixed)
**Python Version**: `2.7.13 (default, Nov 24 2017, 17:33:09) [GCC 6.3.0 20170516]`
**Operating System**: `Linux-3.4.113-bananian-armv7l-with-debian-9.3`
**Locale**: `UTF-8`
**Branch**: [master](../tree/master)
**Database**: `44.9`
**Commit**: pymedusa/Medusa@d6eb72d4e1019e5d1286ae6ac1d7e4b318229ebe
**What you did:** I selected Github personal acces token as authentication method for submitting new issues, entered my token, and tried to submit an issue from within Medusa
**What happened:** It kept giving me the error message that I should enter my username/password
**What you expected:** I expected the issue to be submitted of course but I also expected to still have to enter my username, as is usual AFAIK when logging into Github through a 3rd party service 

Unless I'm gravely mistaken (or made an error while entering my login info, but I triple checked it) I think the way of logging in with a git token is wrong, it's missing the username field, and can thus not work.


Discussion:

Resolving patch:
diff --git a/medusa/issue_submitter.py b/medusa/issue_submitter.py
--- a/medusa/issue_submitter.py
+++ b/medusa/issue_submitter.py
@@ -12,7 +12,7 @@
 from datetime import datetime, timedelta
 
 from github import InputFileContent
-from github.GithubException import GithubException, RateLimitExceededException
+from github.GithubException import GithubException, RateLimitExceededException, UnknownObjectException
 
 from medusa import app, db
 from medusa.classes import ErrorViewer
@@ -41,14 +41,16 @@
 class IssueSubmitter(object):
     """GitHub issue submitter."""
 
-    MISSING_CREDENTIALS = 'Please set your GitHub Username and Password in the config.  Unable to submit issue ticket to GitHub.'
-    DEBUG_NOT_ENABLED = 'Please enable Debug mode in the config.  Unable to submit issue ticket to GitHub.'
+    MISSING_CREDENTIALS = 'Please set your GitHub Username and Password in the config. Unable to submit issue ticket to GitHub.'
+    MISSING_CREDENTIALS_TOKEN = 'Please set your GitHub personal access token in the config. Unable to submit issue ticket to GitHub.'
+    DEBUG_NOT_ENABLED = 'Please enable Debug mode in the config. Unable to submit issue ticket to GitHub.'
     NO_ISSUES = 'No issue to be submitted to GitHub.'
     UNSUPPORTED_VERSION = 'Please update Medusa, unable to submit issue ticket to GitHub with an outdated version.'
     ALREADY_RUNNING = 'An issue is already being submitted, please wait for it to complete.'
     BAD_CREDENTIALS = 'Please check your Github credentials in Medusa settings. Bad Credentials error'
     RATE_LIMIT = 'Please wait before submit new issues. Github Rate Limit Exceeded error'
     GITHUB_EXCEPTION = 'Error trying to contact Github. Please try again'
+    GITHUB_UNKNOWNOBJECTEXCEPTION = 'GitHub returned an error "Not Found". If using a token, make sure the proper scopes are selected.'
     EXISTING_ISSUE_LOCKED = 'Issue #{number} is locked, check GitHub to find info about the error.'
     COMMENTED_EXISTING_ISSUE = 'Commented on existing issue #{number} successfully!'
     ISSUE_CREATED = 'Your issue ticket #{number} was submitted successfully!'
@@ -131,7 +133,10 @@ def result(message, level=logging.WARNING):
         if not app.DEBUG:
             return result(self.DEBUG_NOT_ENABLED)
 
-        if not (app.GIT_USERNAME and app.GIT_PASSWORD) or app.GIT_TOKEN:
+        if app.GIT_AUTH_TYPE == 1 and not app.GIT_TOKEN:
+            return result(self.MISSING_CREDENTIALS_TOKEN)
+
+        if app.GIT_AUTH_TYPE == 0 and not (app.GIT_USERNAME and app.GIT_PASSWORD):
             return result(self.MISSING_CREDENTIALS)
 
         if not ErrorViewer.errors:
@@ -159,7 +164,10 @@ def result(message, level=logging.WARNING):
             return self.submit_issues(github, github_repo, loglines, similar_issues)
         except RateLimitExceededException:
             return result(self.RATE_LIMIT)
-        except (GithubException, IOError):
+        except (GithubException, IOError) as error:
+            # If the api return http status 404, authentication or permission issue(token right to create gists)
+            if isinstance(error, UnknownObjectException):
+                return result(self.GITHUB_UNKNOWNOBJECTEXCEPTION)
             return result(self.GITHUB_EXCEPTION)
         finally:
             self.running = False


Test patch: