Skip to content

Commit

Permalink
Better way to handle fetching PR test results during testing
Browse files Browse the repository at this point in the history
  • Loading branch information
iarspider committed Jun 24, 2024
1 parent 3c76023 commit 2b1e3dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
13 changes: 6 additions & 7 deletions process_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
from _py2with3compatibility import run_cmd
from json import dumps, dump, load, loads
import yaml
import sys # to test if we are doing tests or are in production mode

try:
from yaml import CLoader as Loader, CDumper as Dumper
Expand Down Expand Up @@ -853,13 +852,16 @@ def on_labels_changed(added_labels, removed_labels):
pass


def fetch_pr_result(url):
e, o = run_cmd("curl -k -s -L --max-time 60 %s" % url)
return e, o


def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=False):
global L2_DATA
if (not force) and ignore_issue(repo_config, repo, issue):
return

test_mode = "pytest" in sys.modules

gh_user_char = "@"
if not notify_user(issue):
gh_user_char = ""
Expand Down Expand Up @@ -1956,10 +1958,7 @@ def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=F
+ "/pr-result"
)
print("PR Result:", url)
if test_mode:
e, o = "", "ook"
else:
e, o = run_cmd("curl -k -s -L --max-time 60 %s" % url)
e, o = fetch_pr_result(result_url)
if e:
print(o)
raise Exception("System-error: unable to get PR result")
Expand Down
14 changes: 14 additions & 0 deletions tests/test_process_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ def on_labels_changed(*args, **kwargs):
actions.append({"type": "remove-label", "data": sorted(list(removed_labels))})


def dummy_fetch_pr_result(*args, **kwargs):
assert len(args) == 1, "Signature of process_pr.fetch_pr_result changed"
assert len(kwargs) == 0, "Signature of process_pr.fetch_pr_result changed"

return "", "ook"


class TestProcessPr(Framework.TestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -340,6 +347,13 @@ def setUpHooks(self):
"hook_function": on_labels_changed,
"call_original": False,
},
{
"module_path": "process_pr",
"class_name": None,
"function_name": "fetch_pr_result",
"hook_function": dummy_fetch_pr_result,
"call_original": False,
},
# TODO: remove once we update PyGithub
{
"module_path": "github.IssueComment",
Expand Down

0 comments on commit 2b1e3dc

Please sign in to comment.