summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Kubacki <michael.kubacki@microsoft.com>2024-07-31 18:28:27 -0400
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-08-05 19:30:26 +0000
commit98f17cdcf41df331ac3cdd4be0686219fa812b7f (patch)
treeda8d0810db77e6aa9b486870b1b2431a5cf11f3e
parent057c26710a1f1daf68c00a72180963191d49953d (diff)
downloadedk2-98f17cdcf41df331ac3cdd4be0686219fa812b7f.tar.gz
edk2-98f17cdcf41df331ac3cdd4be0686219fa812b7f.tar.bz2
edk2-98f17cdcf41df331ac3cdd4be0686219fa812b7f.zip
.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>
-rw-r--r--.github/scripts/GitHub.py22
-rw-r--r--.github/scripts/requirements.txt1
-rw-r--r--.github/workflows/request-reviews.yml18
3 files changed, 10 insertions, 31 deletions
diff --git a/.github/scripts/GitHub.py b/.github/scripts/GitHub.py
index 95865dea41..ad3ee3ef06 100644
--- a/.github/scripts/GitHub.py
+++ b/.github/scripts/GitHub.py
@@ -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:
diff --git a/.github/scripts/requirements.txt b/.github/scripts/requirements.txt
index 4b4988cc2f..a1c2a3c672 100644
--- a/.github/scripts/requirements.txt
+++ b/.github/scripts/requirements.txt
@@ -9,4 +9,5 @@
##
edk2-pytool-library==0.*
+GitPython==3.*
requests==2.*
diff --git a/.github/workflows/request-reviews.yml b/.github/workflows/request-reviews.yml
index f80bb591d5..e176a979e9 100644
--- a/.github/workflows/request-reviews.yml
+++ b/.github/workflows/request-reviews.yml
@@ -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: