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 2bd9c8c commit 4f297b4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
2 changes: 1 addition & 1 deletion openedx_webhooks/gh_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def add_pull_request_to_project(prid: PrId, pr_node_id: str, project: GhProject)


ORG_PROJECT_METADATA = """\
query ($orgname: String!, $number: Int!) {
query OrgProjectMetadata ($orgname: String!, $number: Int!) {
organization(login: $orgname) {
projectV2(number: $number) {
id
Expand Down
34 changes: 33 additions & 1 deletion tests/fake_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,4 +491,36 @@ def _graphql_OrgProjectId(self, owner: str, number: int) -> Dict:
def _graphql_AddProjectItem(self, projectId: str, prNodeId: str) -> Dict:
self.project_items[projectId].add(prNodeId)
self.project_items[prNodeId].add(projectId)
return {"data": "saul goodman"}
return {
'data': {
'addProjectV2ItemById': {
'item': {'id': 'saul goodman'}
}
}
}

def _graphql_UpdateProjectItem(self, projectId: str, itemId: str, fieldId: str, value) -> dict:
self.project_items[projectId].add(itemId)
self.project_items[fieldId].add(value)
return {'data': {}}

def _graphql_OrgProjectMetadata(self, orgname: str, number: int) -> dict:
proj_id = f"PROJECT:{orgname}.{number}"
self.project_nodes[proj_id] = (orgname, number)
self.projects[(orgname, number)] = proj_id
return {
"data": {
"organization": {
"projectV2": {
"id": proj_id,
"fields": {
"nodes": [
{"name": "Name", "id": "name-id", "dataType": "text"},
{"name": "Date opened", "id": "date-opened-id", "dataType": "date"},
{"name": "Repo Owner / Owning Team", "id": "repo-owner-id", "dataType": "text"},
]
}
}
}
}
}
36 changes: 31 additions & 5 deletions tests/test_pull_request_opened.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests of tasks/github.py:pull_request_changed for opening pull requests."""

import textwrap
from datetime import datetime
from unittest import mock

import pytest
Expand All @@ -20,6 +21,7 @@
)
from openedx_webhooks.gh_projects import pull_request_projects
from openedx_webhooks.tasks.github import pull_request_changed

from .helpers import check_issue_link_in_markdown

# These tests should run when we want to test flaky GitHub behavior.
Expand Down Expand Up @@ -80,8 +82,9 @@ def test_pr_in_nocontrib_repo_opened(fake_github, user):
("user:feanil", "@feanil"),
("feanil", "@feanil"),
])
@mock.patch("openedx_webhooks.bot_comments.get_catalog_info")
def test_pr_with_owner_repo_opened(get_catalog_info, fake_github, owner, tag):
@mock.patch("openedx_webhooks.info.get_catalog_info")
def test_pr_with_owner_repo_opened(get_catalog_info, fake_github, owner, tag, mocker):
mocker.patch("openedx_webhooks.tasks.pr_tracking.get_github_user_info", lambda x: {"name": x})
get_catalog_info.return_value = {
'spec': {'owner': owner, 'lifecycle': 'production'}
}
Expand All @@ -93,8 +96,9 @@ def test_pr_with_owner_repo_opened(get_catalog_info, fake_github, owner, tag):
body = pr_comments[0].body
assert f"This repository is currently maintained by `{tag}`" in body


@pytest.mark.parametrize("lifecycle", ["production", "deprecated", None])
@mock.patch("openedx_webhooks.bot_comments.get_catalog_info")
@mock.patch("openedx_webhooks.info.get_catalog_info")
def test_pr_without_owner_repo_opened(get_catalog_info, fake_github, lifecycle):
get_catalog_info.return_value = {
'spec': {'lifecycle': lifecycle}
Expand All @@ -106,9 +110,9 @@ def test_pr_without_owner_repo_opened(get_catalog_info, fake_github, lifecycle):
assert len(pr_comments) == 1
body = pr_comments[0].body
if lifecycle == "production":
assert f"This repository has no maintainer (yet)." in body
assert "This repository has no maintainer (yet)." in body
else:
assert f"This repository is currently unmaintained." in body
assert "This repository is currently unmaintained." in body


def test_pr_opened_by_bot(fake_github):
Expand Down Expand Up @@ -418,6 +422,7 @@ def test_jira_labelling_later(fake_github, fake_jira, fake_jira_another):
jira_issue = fake_jira_another.issues[jira_id.key]
assert jira_issue.summary == "Yet another PR"


def test_bad_jira_labelling_no_server(fake_github):
# What if the jira: label doesn't match one of our configured servers?
pr = fake_github.make_pull_request("openedx", user="nedbat", title="Ned's PR")
Expand All @@ -433,6 +438,7 @@ def test_bad_jira_labelling_no_server(fake_github):
pull_request_changed(pr.as_json())
assert len(pr.list_comments()) == 1


def test_bad_jira_labelling_no_repo_map(fake_github, fake_jira2, mocker):
# What if the jira: label is good, but the repo has no mapping to a project?
pr = fake_github.make_pull_request("openedx", repo="nomap", user="nedbat", title="Ned's PR")
Expand Down Expand Up @@ -476,3 +482,23 @@ def test_bad_jira_labelling_no_repo_map(fake_github, fake_jira2, mocker):
body = pr_comments[0].body
jira_id = result.changed_jira_issues.pop()
check_issue_link_in_markdown(body, jira_id)


@pytest.mark.parametrize("owner", ["user:navin", "group:auth-group"])
def test_pr_project_fields_data(fake_github, mocker, owner):
mocker.patch("openedx_webhooks.tasks.pr_tracking.get_github_user_info", lambda x: {"name": x.title()})
mocker.patch(
"openedx_webhooks.info.get_catalog_info",
lambda _: {
'spec': {'owner': owner, 'lifecycle': 'production'}
}
)
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'] == {created_at.isoformat() + 'Z'}
owner_type, owner_name = owner.split(":")
if owner_type == "user":
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}"}

0 comments on commit 4f297b4

Please sign in to comment.