Configuration parsed from environment variables.
| 34 | |
| 35 | @dataclass |
| 36 | class Config: |
| 37 | """Configuration parsed from environment variables.""" |
| 38 | |
| 39 | project_owner: str |
| 40 | project_owner_type: str # "organization" or "user" |
| 41 | project_number: int |
| 42 | status_field: str |
| 43 | status_todo: str |
| 44 | status_done: str |
| 45 | status_draft: str # empty string means unused |
| 46 | date_field: str # empty string means unused |
| 47 | event_name: str |
| 48 | event_action: str |
| 49 | item_node_id: str |
| 50 | is_draft: bool |
| 51 | |
| 52 | @classmethod |
| 53 | def from_env(cls: type[Config]) -> Config: |
| 54 | """Parse configuration from environment variables.""" |
| 55 | project_number_raw = os.environ.get("PROJECT_NUMBER", "") |
| 56 | if not project_number_raw: |
| 57 | raise SystemExit("PROJECT_NUMBER is required") |
| 58 | |
| 59 | item_node_id = os.environ.get("ITEM_NODE_ID", "") |
| 60 | if not item_node_id: |
| 61 | raise SystemExit("ITEM_NODE_ID is required (no issue or PR node ID)") |
| 62 | |
| 63 | return cls( |
| 64 | project_owner=os.environ.get("PROJECT_OWNER", ""), |
| 65 | project_owner_type=os.environ.get("PROJECT_OWNER_TYPE", "organization"), |
| 66 | project_number=int(project_number_raw), |
| 67 | status_field=os.environ.get("STATUS_FIELD", "Status"), |
| 68 | status_todo=os.environ.get("STATUS_TODO", "Todo"), |
| 69 | status_done=os.environ.get("STATUS_DONE", "Done"), |
| 70 | status_draft=os.environ.get("STATUS_DRAFT", ""), |
| 71 | date_field=os.environ.get("DATE_FIELD", ""), |
| 72 | event_name=os.environ.get("EVENT_NAME", ""), |
| 73 | event_action=os.environ.get("EVENT_ACTION", ""), |
| 74 | item_node_id=item_node_id, |
| 75 | is_draft=os.environ.get("IS_DRAFT", "false").lower() == "true", |
| 76 | ) |
| 77 | |
| 78 | |
| 79 | def graphql(query: str, variables: dict[str, Any]) -> dict[str, Any]: |