1# This Source Code Form is subject to the terms of the Mozilla Public 2# License, v. 2.0. If a copy of the MPL was not distributed with this 3# file, # You can obtain one at http://mozilla.org/MPL/2.0/. 4 5from __future__ import absolute_import, print_function, unicode_literals 6 7import urllib 8import requests 9 10from mozbuild.vendor.host_base import BaseHost 11 12 13class GitLabHost(BaseHost): 14 def upstream_commit(self, revision): 15 """Query the gitlab api for a git commit id and timestamp.""" 16 repo_url = urllib.parse.urlparse(self.manifest["origin"]["url"]) 17 gitlab_api = repo_url.scheme + "://" + repo_url.netloc + "/api/v4/projects/" 18 gitlab_api += repo_url.path[1:].replace("/", "%2F") 19 gitlab_api += "/repository/commits" 20 req = requests.get("/".join([gitlab_api, revision])) 21 req.raise_for_status() 22 info = req.json() 23 return (info["id"], info["committed_date"]) 24 25 def upstream_snapshot(self, revision): 26 return "/".join( 27 [self.manifest["origin"]["url"], "-", "archive", revision + ".tar.gz"] 28 ) 29