From 3355ff245e823bdec12e70f84983219acaa4b4eb Mon Sep 17 00:00:00 2001 From: Navin Karkera Date: Fri, 3 Jan 2025 16:14:07 +0530 Subject: [PATCH] fixup! feat: fill date opened field in ospr project board --- openedx_webhooks/tasks/pr_tracking.py | 8 +++---- tests/test_pull_request_opened.py | 34 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/openedx_webhooks/tasks/pr_tracking.py b/openedx_webhooks/tasks/pr_tracking.py index 91713b13..bc8f579b 100644 --- a/openedx_webhooks/tasks/pr_tracking.py +++ b/openedx_webhooks/tasks/pr_tracking.py @@ -698,8 +698,8 @@ def add_pull_request_to_project(self, *, pr_node_id: str, project: GhProject) -> """ try: return add_pull_request_to_project(self.prid, pr_node_id, project) - except Exception as exc: # pylint: disable=broad-exception-caught - logger.exception(f"Couldn't add PR to project: {exc}") + except Exception: # pylint: disable=broad-exception-caught + logger.exception("Couldn't add PR to project") return None def update_project_pr_custom_field(self, *, field_name: str, field_value, item_id: str, project: GhProject) -> None: @@ -708,8 +708,8 @@ def update_project_pr_custom_field(self, *, field_name: str, field_value, item_i """ try: update_project_pr_custom_field(field_name, field_value, item_id, project) - except Exception as exc: # pylint: disable=broad-exception-caught - logger.exception(f"Couldn't update: {field_name} for a PR in project: {exc}") + except Exception: # pylint: disable=broad-exception-caught + logger.exception(f"Couldn't update: {field_name} for a PR in project") def set_cla_status(self, *, status: Dict[str, str]) -> None: set_cla_status_on_pr(self.prid.full_name, self.prid.number, status) diff --git a/tests/test_pull_request_opened.py b/tests/test_pull_request_opened.py index 6af59eeb..2a13dc79 100644 --- a/tests/test_pull_request_opened.py +++ b/tests/test_pull_request_opened.py @@ -1,5 +1,6 @@ """Tests of tasks/github.py:pull_request_changed for opening pull requests.""" +import logging import textwrap from datetime import datetime from unittest import mock @@ -503,3 +504,36 @@ def test_pr_project_fields_data(fake_github, mocker, owner): assert pr.repo.github.project_items['repo-owner-id'] == {f"{owner_name.title()} (@{owner_name})"} else: assert pr.repo.github.project_items['repo-owner-id'] == {f"openedx/{owner_name}"} + + +def test_pr_project_fields_invalid_field_name(fake_github, mocker, caplog): + # Create user "navin" to fake `get_github_user_info` api. + fake_github.make_user(login='navin', name='Navin') + mocker.patch( + "openedx_webhooks.info.get_catalog_info", + lambda _: { + 'spec': {'owner': "user:navin", 'lifecycle': 'production'} + } + ) + # mock project metadata + mocker.patch( + "openedx_webhooks.gh_projects.get_project_metadata", + lambda _: { + "id": "some-project-id", + "fields": [ + {"name": "Name", "id": "name-id", "dataType": "text"}, + ] + } + ) + created_at = datetime(2024, 12, 1) + pr = fake_github.make_pull_request(owner="openedx", repo="edx-platform", created_at=created_at) + pull_request_changed(pr.as_json()) + assert pr.repo.github.project_items['date-opened-id'] == set() + assert pr.repo.github.project_items['repo-owner-id'] == set() + error_logs = [log for log in caplog.records if log.levelno == logging.ERROR] + expected_msgs = ( + f"Could not find field with name: Date opened in project: {settings.GITHUB_OSPR_PROJECT}", + f"Could not find field with name: Repo Owner / Owning Team in project: {settings.GITHUB_OSPR_PROJECT}" + ) + assert error_logs[0].msg == expected_msgs[0] + assert error_logs[1].msg == expected_msgs[1]