From 95bc4720adfa392f7b3faf73c9249672ffc6337d Mon Sep 17 00:00:00 2001 From: ljf Date: Sat, 26 May 2018 23:37:14 +0200 Subject: [PATCH 1/4] [enh] Support gitlab --- add_or_update.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/add_or_update.py b/add_or_update.py index 10ef559e..57abeda0 100755 --- a/add_or_update.py +++ b/add_or_update.py @@ -41,12 +41,21 @@ if __name__ == '__main__': url = url[:-len(".git")] if not url.startswith("https://github.com"): - sys.stderr.write("WARNING: url '%s' doesn't starts with https://github.com, skip it\n" % url) + sys.stderr.write("WARNING: url '%s' doesn't starts with https://github.com, we will try with gitlab api\n" % url) owner, repo = filter(None, url.split("/"))[-2:] project_name = filter(None, url.split("/"))[-1].replace("_ynh", "") - github_data = json.load(urlopen("https://api.github.com/repos/%(owner)s/%(repo)s/commits" % {"owner": owner, "repo": repo})) + if url.startswith("https://github.com"): + git_data = json.load(urlopen("https://api.github.com/repos/%(owner)s/%(repo)s/commits" % {"owner": owner, "repo": repo})) + revision = git_data[0]["sha"] + else: + from urlparse import urlparse + parsed_uri = urlparse( url ) + base_url = '{uri.scheme}://{uri.netloc}/'.format(uri=parsed_uri) + # Try with gitlab api + git_data = json.load(urlopen("%(base_url)sapi/v4/projects/%(owner)s%%2F%(repo)s/repository/commits/HEAD" % {"base_url": base_url, "owner": owner, "repo": repo})) + revision = git_data["id"] if project_name not in content: content[project_name] = {} @@ -54,7 +63,7 @@ if __name__ == '__main__': print("INFO: project already in '%s', I'm updating it" % sys.argv[1]) content[project_name]["url"] = url - content[project_name]["revision"] = github_data[0]["sha"] + content[project_name]["revision"] = revision content[project_name]["branch"] = "master" if sys.argv[1] == "official.json": From ae21cb2c64e64f1c2c2c9930071443de81c76857 Mon Sep 17 00:00:00 2001 From: ljf Date: Sat, 26 May 2018 23:40:46 +0200 Subject: [PATCH 2/4] [enh] Adapt documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f07e7ad..5a816917 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ your app from one of the 2 json files. Usage: ```bash -./add_or_update.py [community.json OR official.json] [github url OR app name [github url OR app name [github url OR app name ...]]] +./add_or_update.py [community.json OR official.json] [github/gitlab url OR app name [github/gitlab url OR app name [github/gitlab url OR app name ...]]] ``` #### More information on [yunohost.org/packaging_apps](https://yunohost.org/packaging_apps) From 6b321066f015e8181f4938aa1328a461be096333 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sun, 27 May 2018 08:52:26 +0200 Subject: [PATCH 3/4] [mod] import at the debigging of the file, it's not yunohost codebase --- add_or_update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/add_or_update.py b/add_or_update.py index 57abeda0..ff1be0b5 100755 --- a/add_or_update.py +++ b/add_or_update.py @@ -5,6 +5,7 @@ import sys import json from urllib2 import urlopen +from urlparse import urlparse states = { 1: "notworking", @@ -50,7 +51,6 @@ if __name__ == '__main__': git_data = json.load(urlopen("https://api.github.com/repos/%(owner)s/%(repo)s/commits" % {"owner": owner, "repo": repo})) revision = git_data[0]["sha"] else: - from urlparse import urlparse parsed_uri = urlparse( url ) base_url = '{uri.scheme}://{uri.netloc}/'.format(uri=parsed_uri) # Try with gitlab api From 59209731e918d52f8acf91d8325cd2a72db3a4b1 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Sun, 27 May 2018 08:52:33 +0200 Subject: [PATCH 4/4] [mod] pep8 --- add_or_update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/add_or_update.py b/add_or_update.py index ff1be0b5..33c72915 100755 --- a/add_or_update.py +++ b/add_or_update.py @@ -51,7 +51,7 @@ if __name__ == '__main__': git_data = json.load(urlopen("https://api.github.com/repos/%(owner)s/%(repo)s/commits" % {"owner": owner, "repo": repo})) revision = git_data[0]["sha"] else: - parsed_uri = urlparse( url ) + parsed_uri = urlparse(url) base_url = '{uri.scheme}://{uri.netloc}/'.format(uri=parsed_uri) # Try with gitlab api git_data = json.load(urlopen("%(base_url)sapi/v4/projects/%(owner)s%%2F%(repo)s/repository/commits/HEAD" % {"base_url": base_url, "owner": owner, "repo": repo}))