Skip to content

Commit

Permalink
fixup! feat: fill date opened field in ospr project board
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Jan 3, 2025
1 parent 9e67707 commit 3355ff2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
8 changes: 4 additions & 4 deletions openedx_webhooks/tasks/pr_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 703 in openedx_webhooks/tasks/pr_tracking.py

View check run for this annotation

Codecov / codecov/patch

openedx_webhooks/tasks/pr_tracking.py#L701-L703

Added lines #L701 - L703 were not covered by tests

def update_project_pr_custom_field(self, *, field_name: str, field_value, item_id: str, project: GhProject) -> None:
Expand All @@ -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")

Check warning on line 712 in openedx_webhooks/tasks/pr_tracking.py

View check run for this annotation

Codecov / codecov/patch

openedx_webhooks/tasks/pr_tracking.py#L711-L712

Added lines #L711 - L712 were not covered by tests

def set_cla_status(self, *, status: Dict[str, str]) -> None:
set_cla_status_on_pr(self.prid.full_name, self.prid.number, status)
34 changes: 34 additions & 0 deletions tests/test_pull_request_opened.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]

0 comments on commit 3355ff2

Please sign in to comment.