.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 # SPDX-License-Identifier: BSD-2-Clause-Patent
# #
import git
import logging import logging
import re import re
import requests import requests
from collections import OrderedDict from collections import OrderedDict
from edk2toollib.utility_functions import RunCmd, RunPythonScript from edk2toollib.utility_functions import RunPythonScript
from io import StringIO from io import StringIO
from typing import List from typing import List
@ -59,24 +60,15 @@ def get_reviewers_for_range(
Returns: Returns:
List[str]: A list of GitHub usernames. List[str]: A list of GitHub usernames.
""" """
if range_start == range_end: if range_start == range_end:
commits = [range_start] commits = [range_start]
else: else:
commit_stream_buffer = StringIO() commits = [
cmd_ret = RunCmd( c.hexsha
"git", for c in git.Repo(workspace_path).iter_commits(
f"log --format=format:%H {range_start}..{range_end}", f"{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()}"
) )
return [] ]
commits = commit_stream_buffer.getvalue().splitlines()
raw_reviewers = [] raw_reviewers = []
for commit_sha in commits: for commit_sha in commits:

View File

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

View File

@ -65,12 +65,10 @@ jobs:
TARGET_BRANCH: ${{ github.event.pull_request.base.ref }} TARGET_BRANCH: ${{ github.event.pull_request.base.ref }}
WORKSPACE_PATH: ${{ github.workspace }} WORKSPACE_PATH: ${{ github.workspace }}
run: | run: |
import logging import git
import os import os
import sys import sys
sys.path.append(os.path.join(os.environ['WORKSPACE_PATH'], ".github")) 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 from scripts import GitHub
WORKSPACE_PATH = os.environ['WORKSPACE_PATH'] 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}") print(f"::notice title=PR Commit SHA::Looking at files in consolidated PR commit: {pr_commit_sha}")
out_stream_buffer = StringIO() git.Repo(WORKSPACE_PATH).remotes.origin.fetch(pr_commit_sha, depth=1)
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)
reviewers = GitHub.get_reviewers_for_range(WORKSPACE_PATH, GET_MAINTAINER_LOCAL_PATH, pr_commit_sha, pr_commit_sha) reviewers = GitHub.get_reviewers_for_range(WORKSPACE_PATH, GET_MAINTAINER_LOCAL_PATH, pr_commit_sha, pr_commit_sha)
if not reviewers: if not reviewers: