Skip to content

Commit

Permalink
Merge pull request #831 from Roshan-R/github-url-validation
Browse files Browse the repository at this point in the history
added support for more variants of github extension url
  • Loading branch information
friday committed Oct 30, 2021
2 parents f0905b9 + 71065eb commit 55c7d0b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/api/server/test_GithubExtension.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_validate_url(self, gh_ext):
GithubExtension('http://github.com/Ulauncher/ulauncher-timer').validate_url()

with pytest.raises(GithubExtensionError):
GithubExtension('https://github.com/Ulauncher/ulauncher-timer/').validate_url()
GithubExtension('git@github.com/Ulauncher/ulauncher-timer/').validate_url()

def test_get_download_url(self, gh_ext):
assert gh_ext.get_download_url() == 'https://github.com/Ulauncher/ulauncher-timer/tarball/master'
Expand Down
8 changes: 4 additions & 4 deletions ulauncher/api/server/GithubExtension.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class GithubExtensionError(UlauncherAPIError):

class GithubExtension:

url_match_pattern = r'^https:\/\/github.com\/([\w-]+\/[\w-]+)$'
url_match_pattern = r'^(https:\/\/github.com\/|git@github.com:)(([\w-]+\/[\w-]+))\/?(.git|tree\/master\/?)?$'
url_file_template = 'https://raw.githubusercontent.com/{project_path}/{branch}/{file_path}'
url_commit_template = 'https://api.github.com/repos/{project_path}/commits/{commit}'

Expand Down Expand Up @@ -138,10 +138,10 @@ def read_manifest(self, commit) -> Manifest:

def get_download_url(self, commit: str = DEFAULT_GITHUB_BRANCH) -> str:
"""
>>> https://github.com/Ulauncher/ulauncher-timer
>>> Ulauncher/ulauncher-timer
<<< https://github.com/Ulauncher/ulauncher-timer/tarball/master
"""
return '%s/tarball/%s' % (self.url, commit)
return 'https://github.com/%s/tarball/%s' % (self._get_project_path(), commit)

def get_ext_id(self) -> str:
"""
Expand All @@ -159,4 +159,4 @@ def _get_project_path(self) -> str:
if not match:
raise GithubExtensionError('Invalid GithubUrl: %s' % self.url, ErrorName.InvalidGithubUrl)

return match.group(1)
return match.group(2)

0 comments on commit 55c7d0b

Please sign in to comment.