Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [FC-0074] add support for optional trigger information #143

Merged
merged 12 commits into from
Jan 15, 2025
Merged
9 changes: 4 additions & 5 deletions code_annotations/contrib/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
"""
Expose contrib configuration file paths as Python variables, for use in 3rd-party utilities.
"""
import importlib.resources
import os

import importlib_resources

FEATURE_TOGGLE_ANNOTATIONS_CONFIG_PATH = importlib_resources.files(
FEATURE_TOGGLE_ANNOTATIONS_CONFIG_PATH = importlib.resources.files(
"code_annotations") / os.path.join("contrib", "config", "feature_toggle_annotations.yaml")

SETTING_ANNOTATIONS_CONFIG_PATH = importlib_resources.files(
SETTING_ANNOTATIONS_CONFIG_PATH = importlib.resources.files(
"code_annotations") / os.path.join("contrib", "config", "setting_annotations.yaml")

OPENEDX_EVENTS_ANNOTATIONS_CONFIG_PATH = importlib_resources.files(
OPENEDX_EVENTS_ANNOTATIONS_CONFIG_PATH = importlib.resources.files(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reference: #135 (comment)

"code_annotations") / os.path.join("contrib", "config", "openedx_events_annotations.yaml")
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ annotations:
- ".. event_description:":
- ".. event_data:":
- ".. event_key_field:":
- ".. event_trigger_repository:":
- ".. event_warning:":
extensions:
python:
Expand Down
36 changes: 34 additions & 2 deletions code_annotations/contrib/sphinx/extensions/openedx_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def iter_nodes(self):
event_key_field = event.get(".. event_key_field:", "")
event_key_literal = nodes.literal(text=event_key_field)
event_description = event[".. event_description:"]
event_trigger_repository = event.get(".. event_trigger_repository:")

event_section = nodes.section("", ids=[f"openedxevent-{event_type}"])
event_section += nodes.title(text=event_type, ids=[f"title-{event_type}"])
Expand All @@ -114,10 +115,41 @@ def iter_nodes(self):
)
event_section += nodes.paragraph("", "Event data: ", event_data_literal)
event_section += nodes.paragraph(
text=f"Defined at: {event['filename']} (line"
f" {event['line_number']})"
"",
"Defined at: ",
nodes.reference(
text="{} (line {})".format(
event["filename"], event["line_number"]
),
refuri="{}/blob/{}/{}#L{}".format(
self.env.config.openedxevents_repo_url,
self.env.config.openedxevents_repo_version,
event["filename"],
event["line_number"],
),
),
ids=[f"definition-{event_name}"],
)

if event_trigger_repository:
event_trigger_repository = event_trigger_repository.split(" ")
event_section += nodes.paragraph(text="Triggers", ids=[f"triggers-{event_name}"])
triggers_bullet_list = nodes.bullet_list()
for repository in event_trigger_repository:
triggers_bullet_list += nodes.list_item(
"",
nodes.paragraph(
"",
"Event triggered by ",
nodes.reference(
text=repository,
refuri=f"https://github.com/search?q=repo:{repository}+{event_name}.send_event&type=code",
),
),
)

event_section += triggers_bullet_list

if event.get(".. event_warning:") not in (None, "None", "n/a", "N/A"):
event_section += nodes.warning(
"", nodes.paragraph("", event[".. event_warning:"]), ids=[f"warning-{event_name}"]
Expand Down
Loading