Skip to content

Commit

Permalink
Release ready clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
F-WRunTime committed Jan 28, 2024
1 parent a5fba68 commit 7f8b273
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
38 changes: 20 additions & 18 deletions src/automerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
_LOG_FORMAT: Final = '%(levelname)s %(asctime)s %(name)s - %(message)s'
logging.basicConfig(level=logging.INFO)


def pr_to_display_string(pr):
return f'- {pr.number}: {pr.title}\n\t\t{pr.html_url}'


def run_git_command(command_args: str) -> subprocess.CompletedProcess:
command = ['git'] + command_args.split(' ')
_LOGGER.debug(f'Running: {" ".join(command)}')
Expand All @@ -36,27 +38,28 @@ def run_git_command(command_args: str) -> subprocess.CompletedProcess:
raise
return res


github = Github(login_or_token=os.environ['GITHUB_TOKEN'])
repo = args.org + "/" + args.repo

# 1. Get PRs that are:
# - Open.
# - Open.
open_prs = []
for pr in github.get_repo(repo).get_pulls():
if pr.state == 'open':
open_prs.append(pr)
pr_string = '\n'.join(map(pr_to_display_string, open_prs))
_LOGGER.info(f' PRs:\n{pr_string}\n')
if not open_prs:
_LOGGER.info(f' Quitting.')
_LOGGER.info(' Quitting.')

# 2. Get PRs that are:
# - Open,
# - Labeled as `automerge`, and
# - Approved.
automerge_prs = []
for pr in open_prs:
labels = [l.name for l in pr.get_labels()]
labels = [label.name for label in pr.get_labels()]
reviews = sorted([(r.state, r.submitted_at) for r in pr.get_reviews()], key=lambda x: x[1], reverse=True)
reviews = [state for state, _ in reviews]
if 'automerge' in labels:
Expand All @@ -76,11 +79,11 @@ def run_git_command(command_args: str) -> subprocess.CompletedProcess:
sys.exit(0)

# 3. Get PRs that are:
# - Open,
# - Labelled as `automerge`,
# - Approved,
# - Up-to-date, and
# - Passing tests.
# - Open,
# - Labelled as `automerge`,
# - Approved,
# - Up-to-date, and
# - Passing tests.
automerge_up_to_date_prs = []
for pr in automerge_prs:
is_up_to_date = run_git_command(f'merge-base --is-ancestor {pr.base.sha} {pr.head.sha}').returncode == 0
Expand All @@ -90,10 +93,10 @@ def run_git_command(command_args: str) -> subprocess.CompletedProcess:
_LOGGER.info(f' Automerge approved up-to-date PRs:\n{pr_string}\n')

# 4. Get PRs that are:
# - Open,
# - Labelled as `automerge`,
# - Approved, and
# - Up-to-date.
# - Open,
# - Labelled as `automerge`,
# - Approved, and
# - Up-to-date.
# If so, merge
if automerge_up_to_date_prs:
pr = automerge_up_to_date_prs[0]
Expand All @@ -110,7 +113,6 @@ def run_git_command(command_args: str) -> subprocess.CompletedProcess:
# - Approved,
# - Up-to-date, and
# - Pending tests.
#
automerge_up_to_date_pending_prs = []
for pr in automerge_prs:
is_up_to_date = run_git_command(f'merge-base --is-ancestor {pr.base.sha} {pr.head.sha}').returncode == 0
Expand All @@ -124,11 +126,11 @@ def run_git_command(command_args: str) -> subprocess.CompletedProcess:


# 6. Get PRs that are:
# - Open,
# - Labelled as `automerge`,
# - Approved,
# - Out-of-date, and
# - Passing tests.
# - Open,
# - Labelled as `automerge`,
# - Approved,
# - Out-of-date, and
# - Passing tests.
# If so, update the branch.
automerge_out_of_date_passing_prs = []
for pr in automerge_prs:
Expand Down
6 changes: 1 addition & 5 deletions test/automerge.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[
"devops-actions",
"k",
"pyk",
"foundry-demo",
"evm-semantics"
"devops-actions"
]

0 comments on commit 7f8b273

Please sign in to comment.