[IMP] conftest: fstring-ify repo forking

Also use the fork's response for the fork's own URL instead of
composing it by hand.
This commit is contained in:
Xavier Morel 2025-02-06 12:33:45 +01:00
parent e065206f79
commit 3b0e59a3cd

View File

@ -912,21 +912,22 @@ class Repo:
s = self._get_session(token)
r = s.post(f'https://api.github.com/repos/{self.name}/forks')
assert 200 <= r.status_code < 300, r.text
assert r.ok, r.text
repo_name = r.json()['full_name']
repo_url = 'https://api.github.com/repos/' + repo_name
response = r.json()
repo_name = response['full_name']
repo_url = response['url']
# poll for end of fork
limit = time.time() + 60
while s.head(repo_url, timeout=5).status_code != 200:
if time.time() > limit:
raise TimeoutError("No response for repo %s over 60s" % repo_name)
raise TimeoutError(f"No response for repo {repo_name} over 60s")
time.sleep(1)
# wait for the branches (which should have been copied over) to be visible
while not s.get(f'{repo_url}/branches').json():
if time.time() > limit:
raise TimeoutError("No response for repo %s over 60s" % repo_name)
raise TimeoutError(f"No response for repo {repo_name} over 60s")
time.sleep(1)
return Repo(s, repo_name, self._repos)