Find a single-select field and a specific option by name.
(
project_id: str, field_name: str, option_name: str
)
| 152 | |
| 153 | |
| 154 | def get_field_and_option( |
| 155 | project_id: str, field_name: str, option_name: str |
| 156 | ) -> FieldOption: |
| 157 | """Find a single-select field and a specific option by name.""" |
| 158 | query = """ |
| 159 | query($projectId: ID!) { |
| 160 | node(id: $projectId) { |
| 161 | ... on ProjectV2 { |
| 162 | fields(first: 50) { |
| 163 | nodes { |
| 164 | ... on ProjectV2SingleSelectField { |
| 165 | id |
| 166 | name |
| 167 | options { |
| 168 | id |
| 169 | name |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | """ |
| 178 | data = graphql(query, {"projectId": project_id}) |
| 179 | fields: list[dict[str, Any]] = data["data"]["node"]["fields"]["nodes"] |
| 180 | |
| 181 | for field in fields: |
| 182 | if field.get("name") == field_name: |
| 183 | for option in field.get("options", []): |
| 184 | if option["name"] == option_name: |
| 185 | return FieldOption(field_id=field["id"], option_id=option["id"]) |
| 186 | available: list[str] = [] |
| 187 | for opt in field.get("options", []): |
| 188 | available.append(opt["name"]) |
| 189 | raise SystemExit( |
| 190 | f"Option '{option_name}' not found in field '{field_name}'. " |
| 191 | f"Available: {available}" |
| 192 | ) |
| 193 | |
| 194 | available_fields: list[str] = [] |
| 195 | for f in fields: |
| 196 | name = f.get("name") |
| 197 | if name: |
| 198 | available_fields.append(name) |
| 199 | raise SystemExit(f"Field '{field_name}' not found. Available: {available_fields}") |
| 200 | |
| 201 | |
| 202 | def get_date_field(project_id: str, field_name: str) -> str: |
no test coverage detected