import re
import urllib2

from .base import BaseProcessor

URL_DATA_PATTERN = re.compile(r'github(.com)?\/([\w\-\_]+)\/([\w\-\_]+)')
CONTENTS_URL = 'https://api.github.com/repos/{0.username}/{0.repo}/contents'


class GitHubProcessor(BaseProcessor):
    name = 'github'

    def __init__(self, url):
        self.url = url
        _, self.username, self.repo = self.extract_url_data()

    def extract_url_data(self):
        match = URL_DATA_PATTERN.match(self.url)
        return match.groups()

    @classmethod
    def is_match(cls, url):
        return URL_DATA_PATTERN.match(url)

    def get_license(self):
        file_list = self.get_file_list()

        license = None
        if 'setup.py' in file_list:
            license = self.get_license_from_setup_py(file_list['setup.py'])
            license_found_in = file_list['setup.py']

        if 'LICENSE' in file_list and not license:
            license = self.get_license_from_license_file(file_list['LICENSE'])
            license_found_in = file_list['LICENSE']

        return license, license_found_in

    def get_file_list(self):
        contents_url = CONTENTS_URL.format(self)

        contents = self.get_file_data(contents_url, parse_json=True)
        return {f['name']: f['download_url'] for f in contents}

    def get_license_from_setup_py(self, download_url):
        file_data = self.get_file_data(download_url)

        pattern = r"License :: OSI Approved :: (\w*)"
        match = re.search(pattern, file_data)
        return match and match.groups()[0]

@@ -91,16 +91,18 @@
 'github(
+?:
 .com)?%5C/
@@ -125,16 +125,26 @@
 w%5C-%5C_%5D+)
+(?:%5C.git)?
 ')%0ACONTE
@@ -339,11 +339,8 @@
     
- _,
  sel
@@ -428,23 +428,22 @@
         
-match =
+return
  URL_DAT
@@ -452,19 +452,20 @@
 PATTERN.
-mat
+sear
 ch(self.
@@ -468,37 +468,16 @@
 elf.url)
-%0A        return match
 .groups(

Support git protocol in GH processor