Skip to content

Commit

Permalink
roomservice: Migrate from GitHub API to git ls-remote
Browse files Browse the repository at this point in the history
Change-Id: Ia62594dc0d350c2eaa93e9f02372443ac737abb7
  • Loading branch information
luk1337 committed Jan 7, 2025
1 parent c1d108c commit 13ba07f
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions build/tools/roomservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import netrc
import os
import re
import subprocess
import sys
import urllib.error
import urllib.parse
Expand Down Expand Up @@ -61,10 +62,6 @@
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:
Expand Down Expand Up @@ -269,24 +266,31 @@ 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() ]
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

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 ""
Expand Down

0 comments on commit 13ba07f

Please sign in to comment.