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

Commit 2bcace2f authored by /e/ robot's avatar /e/ robot
Browse files

Merge remote-tracking branch 'origin/lineage-21.0' into v1-u

parents b78e13b4 08535177
Loading
Loading
Loading
Loading
+14 −23
Original line number Diff line number Diff line
@@ -16,12 +16,11 @@

from __future__ import print_function

import base64
import glob
import json
import netrc
import os
import re
import subprocess
import sys
import urllib.error
import urllib.parse
@@ -50,21 +49,6 @@ if not depsonly:

repositories = []

try:
    authtuple = netrc.netrc().authenticators("api.github.com")

    if authtuple:
        auth_string = ('%s:%s' % (authtuple[0], authtuple[2])).encode()
        githubauth = base64.encodestring(auth_string).decode().replace('\n', '')
    else:
        githubauth = None
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 +253,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", "-h", "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 +271,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 ""