Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 13ba07f9 authored by LuK1337's avatar LuK1337
Browse files

roomservice: Migrate from GitHub API to git ls-remote

Change-Id: Ia62594dc0d350c2eaa93e9f02372443ac737abb7
parent c1d108c3
Loading
Loading
Loading
Loading
+14 −10
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import json
import netrc
import os
import re
import subprocess
import sys
import urllib.error
import urllib.parse
@@ -61,10 +62,6 @@ try:
except:
    githubauth = None

def add_auth(githubreq):
    if githubauth:
        githubreq.add_header("Authorization","Basic %s" % githubauth)

if not depsonly:
    githubreq = urllib.request.Request("https://raw.githubusercontent.com/LineageOS/mirror/main/default.xml")
    try:
@@ -269,10 +266,17 @@ def get_default_or_fallback_revision(repo_name):
    print("Default revision: %s" % default_revision)
    print("Checking branch info")

    githubreq = urllib.request.Request("https://api.github.com/repos/LineageOS/" + repo_name + "/branches")
    add_auth(githubreq)
    result = json.loads(urllib.request.urlopen(githubreq, timeout=5).read().decode())
    if has_branch(result, default_revision):
    try:
        stdout = subprocess.run(
            ["git", "ls-remote", "-b", "https://:@github.com/LineageOS/" + repo_name],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        ).stdout.decode()
        branches = [x.split("refs/heads/")[-1] for x in stdout.splitlines()]
    except:
        return ""

    if default_revision in branches:
        return default_revision

    fallbacks = [ get_default_revision_no_minor() ]
@@ -280,13 +284,13 @@ def get_default_or_fallback_revision(repo_name):
        fallbacks += list(filter(bool, os.getenv('ROOMSERVICE_BRANCHES').split(' ')))

    for fallback in fallbacks:
        if has_branch(result, fallback):
        if fallback in branches:
            print("Using fallback branch: %s" % fallback)
            return fallback

    print("Default revision %s not found in %s. Bailing." % (default_revision, repo_name))
    print("Branches found:")
    for branch in [branch['name'] for branch in result]:
    for branch in branches:
        print(branch)
    print("Use the ROOMSERVICE_BRANCHES environment variable to specify a list of fallback branches.")
    return ""