summaryrefslogtreecommitdiffstats
path: root/python/mozbuild/mozbuild/vendor/host_codeberg.py
blob: 158dd0472d4d4bdbf89f7db57f7f12267e6e5ba1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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/.

import requests

from mozbuild.vendor.host_base import BaseHost


class CodebergHost(BaseHost):
    def upstream_commit(self, revision):
        """Query the codeberg api for a git commit id and timestamp."""
        codeberg_api = (
            self.repo_url.scheme + "://" + self.repo_url.netloc + "/api/v1/repos/"
        )
        codeberg_api += self.repo_url.path[1:]
        codeberg_api += "/git/commits"
        req = requests.get("/".join([codeberg_api, revision]))
        req.raise_for_status()
        info = req.json()
        return (info["sha"], info["created"])

    def upstream_snapshot(self, revision):
        codeberg_api = (
            self.repo_url.scheme + "://" + self.repo_url.netloc + "/api/v1/repos/"
        )
        codeberg_api += self.repo_url.path[1:]
        return "/".join([codeberg_api, "archive", revision + ".tar.gz"])