Commits

Pete Gadomski committed 6d32d1d

Add issuetracker_username and _password

These values are used for basic HTTP authentication when fetching
issues from the remote server.

  • Participants
  • Parent commits 4c5e23c

Comments (0)

Files changed (1)

File issuetracker/sphinxcontrib/issuetracker.py

 
 Issue = namedtuple('Issue', 'id title url closed')
 
-_TrackerConfig = namedtuple('_TrackerConfig', 'project url')
+_TrackerConfig = namedtuple('_TrackerConfig', 'project url username password')
 
 class TrackerConfig(_TrackerConfig):
     """
     :event:`issuetracker-lookup-issue`.
     """
 
-    def __new__(cls, project, url=None):
+    def __new__(cls, project, url=None, username=None, password=None):
         if url:
             url = url.rstrip('/')
-        return _TrackerConfig.__new__(cls, project, url)
+        return _TrackerConfig.__new__(cls, project, url, username, password)
 
     @classmethod
     def from_sphinx_config(cls, config):
         """
         project = config.issuetracker_project or config.project
         url = config.issuetracker_url
-        return cls(project, url)
+        username = config.issuetracker_username
+        password = config.issuetracker_password
+        return cls(project, url, username, password)
 
 
 FORMAT_CALLBACKS = {
 }
 
 
-def fetch_issue(app, url, output_format=None):
+def fetch_issue(app, tracker_config, url, output_format=None):
     """
     Fetch issue data from a web service or website.
 
     if output_format not in FORMAT_CALLBACKS:
         raise ValueError(output_format)
 
-    response = requests.get(url)
+    request_kwargs = {}
+    if tracker_config.username:
+        request_kwargs['auth'] = (tracker_config.username, tracker_config.password)
+
+    response = requests.get(url, **request_kwargs)
     if response.status_code == 200:
         return FORMAT_CALLBACKS[output_format](response.content)
     else:
 def lookup_github_issue(app, tracker_config, issue_id):
     check_project_with_username(tracker_config)
 
-    issue = fetch_issue(app, GITHUB_API_URL.format(tracker_config, issue_id),
+    issue = fetch_issue(app, tracker_config, GITHUB_API_URL.format(tracker_config, issue_id),
                         output_format='json')
     if issue:
         closed = issue['state'] == 'closed'
 def lookup_bitbucket_issue(app, tracker_config, issue_id):
     check_project_with_username(tracker_config)
 
-    issue = fetch_issue(app, BITBUCKET_API_URL.format(tracker_config, issue_id),
+    issue = fetch_issue(app, tracker_config, BITBUCKET_API_URL.format(tracker_config, issue_id),
                         output_format='json')
     if issue:
         closed = issue['status'] not in ('new', 'open')
                        '{0.project}/issues/full/{1}')
 
 def lookup_google_code_issue(app, tracker_config, issue_id):
-    issue = fetch_issue(app, GOOGLE_CODE_API_URL.format(
+    issue = fetch_issue(app, tracker_config, GOOGLE_CODE_API_URL.format(
         tracker_config, issue_id), output_format='xml')
     if issue:
         ISSUE_NS = '{http://schemas.google.com/projecthosting/issues/2009}'
 def lookup_jira_issue(app, tracker_config, issue_id):
     if not tracker_config.url:
         raise ValueError('URL required')
-    issue = fetch_issue(app, JIRA_API_URL.format(tracker_config, issue_id),
+    issue = fetch_issue(app, tracker_config, JIRA_API_URL.format(tracker_config, issue_id),
                         output_format='xml')
     if issue:
         project = issue.find('*/item/project').text
     app.add_config_value('issuetracker', None, 'env')
     app.add_config_value('issuetracker_project', None, 'env')
     app.add_config_value('issuetracker_url', None, 'env')
+    app.add_config_value('issuetracker_username', None, 'env')
+    app.add_config_value('issuetracker_password', None, 'env')
     # configuration specific to plaintext issue references
     app.add_config_value('issuetracker_plaintext_issues', True, 'env')
     app.add_config_value('issuetracker_issue_pattern',