summaryrefslogtreecommitdiffstats
path: root/python/mozbuild/mozbuild/vendor/host_gitlab.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/mozbuild/mozbuild/vendor/host_gitlab.py')
-rw-r--r--python/mozbuild/mozbuild/vendor/host_gitlab.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/python/mozbuild/mozbuild/vendor/host_gitlab.py b/python/mozbuild/mozbuild/vendor/host_gitlab.py
new file mode 100644
index 0000000000..001159c20b
--- /dev/null
+++ b/python/mozbuild/mozbuild/vendor/host_gitlab.py
@@ -0,0 +1,31 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, # You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+import urllib
+import requests
+
+
+class GitLabHost:
+ def __init__(self, manifest):
+ self.manifest = manifest
+
+ def upstream_commit(self, revision):
+ """Query the gitlab api for a git commit id and timestamp."""
+ repo_url = urllib.parse.urlparse(self.manifest["origin"]["url"])
+ gitlab_api = repo_url.scheme + "://" + repo_url.netloc + "/api/v4/projects/"
+ gitlab_api += repo_url.path[1:].replace("/", "%2F")
+ gitlab_api += "/repository/commits"
+
+ url = "/".join([gitlab_api, revision])
+ req = requests.get(url)
+ req.raise_for_status()
+ info = req.json()
+ return (info["id"], info["committed_date"])
+
+ def upstream_snapshot(self, revision):
+ return "/".join(
+ [self.manifest["origin"]["url"], "-", "archive", revision + ".tar.gz"]
+ )