Skip to content

Commit

Permalink
Get rid of PyGithub dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Felixoid committed Dec 2, 2022
1 parent ed4db12 commit 7356d48
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions tests/ci/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
from contextlib import contextmanager
from typing import Any, Iterator, List, Literal, Optional
import argparse
import json
import logging
import subprocess

from git_helper import commit, release_branch
from github_helper import GitHub
from version_helper import (
FILE_WITH_VERSION_PATH,
GENERATED_CONTRIBUTORS,
Expand All @@ -32,7 +32,6 @@

RELEASE_READY_STATUS = "Ready for release"


git = Git()


Expand Down Expand Up @@ -113,31 +112,30 @@ def get_stable_release_type(self) -> str:
return VersionType.STABLE

def check_commit_release_ready(self):
# First, get the auth token from gh cli
auth_status = self.run(
"gh auth status -t", stderr=subprocess.STDOUT
).splitlines()
token = ""
for line in auth_status:
if "✓ Token:" in line:
token = line.split()[-1]
if not token:
logging.error("Can not extract token from `gh auth`")
raise subprocess.SubprocessError("Can not extract token from `gh auth`")
gh = GitHub(token, per_page=100)
repo = gh.get_repo(str(self.repo))

# Statuses are ordered by descending updated_at, so the first necessary
# status in the list is the most recent
statuses = repo.get_commit(self.release_commit).get_statuses()
for status in statuses:
if status.context == RELEASE_READY_STATUS:
if status.state == "success":
per_page = 100
page = 1
while True:
statuses = json.loads(
self.run(
f"gh api 'repos/{self.repo}/commits/{self.release_commit}"
f"/statuses?per_page={per_page}&page={page}'"
)
)

if not statuses:
break

for status in statuses:
if status["context"] == RELEASE_READY_STATUS:
if not status["state"] == "success":
raise Exception(
f"the status {RELEASE_READY_STATUS} is {status['state']}"
", not success"
)

return

raise Exception(
f"the status {RELEASE_READY_STATUS} is {status.state}, not success"
)
page += 1

raise Exception(
f"the status {RELEASE_READY_STATUS} "
Expand Down

0 comments on commit 7356d48

Please sign in to comment.