roomservice: Migrate from GitHub API to git ls-remote
Change-Id: Ia62594dc0d350c2eaa93e9f02372443ac737abb7
This commit is contained in:
@@ -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:
|
||||
@@ -258,24 +255,28 @@ def fetch_dependencies(repo_path):
|
||||
for deprepo in verify_repos:
|
||||
fetch_dependencies(deprepo)
|
||||
|
||||
def has_branch(branches, revision):
|
||||
return revision in [branch['name'] for branch in branches]
|
||||
|
||||
def get_default_or_fallback_revision(repo_name):
|
||||
default_revision = get_default_revision()
|
||||
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
|
||||
|
||||
if os.getenv('ROOMSERVICE_BRANCHES'):
|
||||
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
|
||||
|
||||
|
Reference in New Issue
Block a user