From 15e04aa541d8b9c8c52302a6faebbd5f3d096242 Mon Sep 17 00:00:00 2001 From: Jarod Wilson Date: Wed, 5 Mar 2025 10:46:50 -0800 Subject: [PATCH 2/2] skeleton: build a comment to leave instead of only logging In dev mode, it'll never actually leave a comment, but maybe people want to play around with it against staging and see how the comment stuff works. And we need to pass empty lists for label add/remove, rather than None, or the hook will crash. Signed-off-by: Jarod Wilson --- tests/test_skeleton.py | 24 ++++++++++++++---------- webhook/skeleton.py | 20 +++++++++----------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/tests/test_skeleton.py b/tests/test_skeleton.py index a3e2fdd3..7e3328b1 100644 --- a/tests/test_skeleton.py +++ b/tests/test_skeleton.py @@ -122,25 +122,25 @@ class TestProcessMR(KwfTestCase): @mock.patch('webhook.skeleton.SkeletonMR.update_statuses') @mock.patch('webhook.skeleton.SkeletonMR.new') def test_process_mr(self, mock_MR, mock_update): - """Does not update JIRA Issues or MR labels but leaves a comment.""" + """Does not update MR labels but leaves a comment.""" mock_args = mock.Mock() mock_session = SessionRunner.new('skeleton', mock_args, skeleton.HANDLERS) - username = 'user1' - namespace = 'group/project' + username = 'cki-kwf-bot' + namespace = 'redhat/rhel/src/kernel/rhel-7' mr_id = 123 mr_url = defs.GitlabURL(f'https://gitlab.com/{namespace}/-/merge_requests/{mr_id}') mock_session.get_graphql = mock.Mock() mock_session.get_graphql.return_value.username = username mock_session.is_production_or_staging = True - mock_mr = mock.Mock(commits=True, - description=mock.Mock(bugzilla=False), - first_dep_sha='', - draft=False, - labels=[]) - + mock_mr = mock.Mock(commits=True, labels=[]) mock_mr.update_statuses = mock_update mock_mr.gl_mr.milestone = {'description': "RHEL-55.3"} + mock_mr.gl_mr.title = "Title of record" + mock_mr.rh_project = "Foo" + mock_mr.rh_branch = "Bar" + mock_mr.commit_count = 1 + mock_mr.files = ['foo/bar/blah.c'] mock_MR.return_value = mock_mr mock_gl = fakes.FakeGitLab() mock_project = mock_gl.add_project(45678, namespace) @@ -148,8 +148,12 @@ class TestProcessMR(KwfTestCase): mock_session.get_gl_instance = mock.Mock(return_value=mock_gl) mock_session.rh_projects = mock.Mock() + expected = "Product: RHEL-55.3\nRed Hat Project: Foo\nRed Hat Branch: Bar\n" + expected += "MR Title: Title of record\nMR Commit Count: 1\n" + expected += "MR Files touched: ['foo/bar/blah.c']\nMR Commit data: True\n" + skeleton.process_mr(mock_session, mr_url) - mock_update.assert_called_once_with(None, None, "") + mock_update.assert_called_once_with([], [], expected) @mock.patch.dict('os.environ', {'RH_METADATA_EXTRA_PATHS': 'tests/assets/rh_projects_private.yaml', diff --git a/webhook/skeleton.py b/webhook/skeleton.py index 23bc4fc5..9ae51daf 100644 --- a/webhook/skeleton.py +++ b/webhook/skeleton.py @@ -35,19 +35,17 @@ def process_mr(session, mr_url): """Process the given MR.""" # Fetch and parse MR data. this_mr = SkeletonMR.new(session, mr_url) + LOGGER.debug("Full MR details: %s", vars(this_mr.gl_mr)) - LOGGER.info("Product: %s", this_mr.gl_mr.milestone['description']) - LOGGER.info("Red Hat Project: %s", this_mr.rh_project) - LOGGER.info("Red Hat Branch: %s", this_mr.rh_branch) - LOGGER.info("MR Description:\n%s", this_mr.gl_mr.description) - LOGGER.info("MR Commit Count: %s", this_mr.commit_count) - LOGGER.info("MR Files touched: %s", this_mr.files) - LOGGER.info("Commit access: %s", this_mr.commits) + comment = f"Product: {this_mr.gl_mr.milestone['description']}\n" + comment += f"Red Hat Project: {this_mr.rh_project}\n" + comment += f"Red Hat Branch: {this_mr.rh_branch}\n" + comment += f"MR Title: {this_mr.gl_mr.title}\n" + comment += f"MR Commit Count: {this_mr.commit_count}\n" + comment += f"MR Files touched: {this_mr.files}\n" + comment += f"MR Commit data: {this_mr.commits}\n" -# Below is for seeing all attributes in great detail -# LOGGER.info("Session info: %s", vars(this_mr.gl_mr)) - - this_mr.update_statuses(None, None, "") + this_mr.update_statuses([], [], comment) def process_event( -- 2.48.1