.github/request-reviews.yml: Switch to GitPython

Uses `GitPython` instead of invoking the git executable directly.

This has the benefit of improving code readability and less support
code for binary interaction.

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
This commit is contained in:
Michael Kubacki 2024-07-31 18:28:27 -04:00 committed by mergify[bot]
parent 057c26710a
commit 98f17cdcf4
3 changed files with 10 additions and 31 deletions

View File

@ -5,12 +5,13 @@
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
import git
import logging
import re
import requests
from collections import OrderedDict
from edk2toollib.utility_functions import RunCmd, RunPythonScript
from edk2toollib.utility_functions import RunPythonScript
from io import StringIO
from typing import List
@ -59,24 +60,15 @@ def get_reviewers_for_range(
Returns:
List[str]: A list of GitHub usernames.
"""
if range_start == range_end:
commits = [range_start]
else:
commit_stream_buffer = StringIO()
cmd_ret = RunCmd(
"git",
f"log --format=format:%H {range_start}..{range_end}",
workingdir=workspace_path,
outstream=commit_stream_buffer,
logging_level=logging.INFO,
)
if cmd_ret != 0:
print(
f"::error title=Commit Lookup Error!::Error getting branch commits: [{cmd_ret}]: {commit_stream_buffer.getvalue()}"
commits = [
c.hexsha
for c in git.Repo(workspace_path).iter_commits(
f"{range_start}..{range_end}"
)
return []
commits = commit_stream_buffer.getvalue().splitlines()
]
raw_reviewers = []
for commit_sha in commits:

View File

@ -9,4 +9,5 @@
##
edk2-pytool-library==0.*
GitPython==3.*
requests==2.*

View File

@ -65,12 +65,10 @@ jobs:
TARGET_BRANCH: ${{ github.event.pull_request.base.ref }}
WORKSPACE_PATH: ${{ github.workspace }}
run: |
import logging
import git
import os
import sys
sys.path.append(os.path.join(os.environ['WORKSPACE_PATH'], ".github"))
from edk2toollib.utility_functions import RunCmd
from io import StringIO
from scripts import GitHub
WORKSPACE_PATH = os.environ['WORKSPACE_PATH']
@ -82,19 +80,7 @@ jobs:
print(f"::notice title=PR Commit SHA::Looking at files in consolidated PR commit: {pr_commit_sha}")
out_stream_buffer = StringIO()
cmd_ret = RunCmd(
"git",
f"fetch origin {pr_commit_sha}",
workingdir=WORKSPACE_PATH,
outstream=out_stream_buffer,
logging_level=logging.INFO,
)
if cmd_ret != 0:
print(
f"::error title=Commit Fetch Error!::Error fetching PR commit: [{cmd_ret}]: {out_stream_buffer.getvalue()}"
)
sys.exit(1)
git.Repo(WORKSPACE_PATH).remotes.origin.fetch(pr_commit_sha, depth=1)
reviewers = GitHub.get_reviewers_for_range(WORKSPACE_PATH, GET_MAINTAINER_LOCAL_PATH, pr_commit_sha, pr_commit_sha)
if not reviewers: