mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-04 11:22:10 +00:00
simplify Linear webhook team/project field handling
This commit is contained in:
parent
234ddbc16f
commit
64541a0cde
1 changed files with 24 additions and 38 deletions
|
|
@ -93,46 +93,38 @@ LINEAR_TEAM_TO_REPO: dict[str, dict[str, Any] | dict[str, str]] = {
|
||||||
|
|
||||||
|
|
||||||
def get_repo_config_from_team_mapping(
|
def get_repo_config_from_team_mapping(
|
||||||
team_name: str, team_id: str, project_name: str = ""
|
team_identifier: str, project_name: str = ""
|
||||||
) -> dict[str, str]:
|
) -> dict[str, str] | None:
|
||||||
"""
|
"""
|
||||||
Look up repository configuration from LINEAR_TEAM_TO_REPO mapping.
|
Look up repository configuration from LINEAR_TEAM_TO_REPO mapping.
|
||||||
|
|
||||||
Supports both legacy flat mapping (team -> repo) and new nested mapping (team -> project -> repo).
|
Supports both legacy flat mapping (team -> repo) and new nested mapping (team -> project -> repo).
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
team_name: Name of the team (e.g., "LangChain OSS")
|
team_identifier: Team name or ID to look up (e.g., "LangChain OSS")
|
||||||
team_id: ID of the team
|
|
||||||
project_name: Name of the project (e.g., "deepagents")
|
project_name: Name of the project (e.g., "deepagents")
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Repository config dict with 'owner' and 'name' keys, or None if not found
|
Repository config dict with 'owner' and 'name' keys, or None if not found
|
||||||
"""
|
"""
|
||||||
# Try team_id first
|
if not team_identifier or team_identifier not in LINEAR_TEAM_TO_REPO:
|
||||||
if team_id and team_id in LINEAR_TEAM_TO_REPO:
|
return None
|
||||||
config = LINEAR_TEAM_TO_REPO[team_id]
|
|
||||||
# Legacy flat format: team_id maps directly to repo config
|
|
||||||
if "owner" in config and "name" in config:
|
|
||||||
return config
|
|
||||||
# New nested format: team_id maps to structure with projects
|
|
||||||
if "projects" in config and project_name:
|
|
||||||
return config["projects"].get(project_name)
|
|
||||||
if "default" in config:
|
|
||||||
return config["default"]
|
|
||||||
|
|
||||||
# Try team_name
|
config = LINEAR_TEAM_TO_REPO[team_identifier]
|
||||||
if team_name and team_name in LINEAR_TEAM_TO_REPO:
|
|
||||||
config = LINEAR_TEAM_TO_REPO[team_name]
|
|
||||||
# Legacy flat format: team_name maps directly to repo config
|
|
||||||
if "owner" in config and "name" in config:
|
|
||||||
return config
|
|
||||||
# New nested format: team_name maps to structure with projects
|
|
||||||
if "projects" in config and project_name:
|
|
||||||
return config["projects"].get(project_name)
|
|
||||||
if "default" in config:
|
|
||||||
return config["default"]
|
|
||||||
|
|
||||||
return {"owner": "langchain-ai", "name": "langchainplus"}
|
# Legacy flat format: team maps directly to repo config
|
||||||
|
if "owner" in config and "name" in config:
|
||||||
|
return config
|
||||||
|
|
||||||
|
# New nested format: team maps to structure with projects
|
||||||
|
if "projects" in config and project_name:
|
||||||
|
return config["projects"].get(project_name)
|
||||||
|
|
||||||
|
# Team has default repo (no project needed)
|
||||||
|
if "default" in config:
|
||||||
|
return config["default"]
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
async def get_ls_user_id_from_email(email: str) -> dict[str, str | None]:
|
async def get_ls_user_id_from_email(email: str) -> dict[str, str | None]:
|
||||||
|
|
@ -774,26 +766,20 @@ async def linear_webhook( # noqa: PLR0911, PLR0912, PLR0915
|
||||||
return {"status": "ignored", "reason": "No issue data in comment"}
|
return {"status": "ignored", "reason": "No issue data in comment"}
|
||||||
|
|
||||||
team = issue.get("team", {})
|
team = issue.get("team", {})
|
||||||
team_id = team.get("id", "") if team else ""
|
|
||||||
team_name = team.get("name", "") if team else ""
|
team_name = team.get("name", "") if team else ""
|
||||||
project = issue.get("project", {}) if issue else {}
|
project = issue.get("project")
|
||||||
project_name = ""
|
project_name = project.get("name", "") if project else ""
|
||||||
if isinstance(project, dict):
|
|
||||||
project_name = project.get("name", "") or ""
|
|
||||||
elif isinstance(project, str):
|
|
||||||
project_name = project
|
|
||||||
|
|
||||||
# Look up repository configuration from team/project mapping
|
# Look up repository configuration from team/project mapping
|
||||||
team_key = team_name.strip() if team_name else ""
|
team_identifier = team_name.strip() if team_name else ""
|
||||||
project_key = project_name.strip() if project_name else ""
|
project_key = project_name.strip() if project_name else ""
|
||||||
|
|
||||||
repo_config = get_repo_config_from_team_mapping(team_key, team_id, project_key)
|
repo_config = get_repo_config_from_team_mapping(team_identifier, project_key)
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Team/project lookup result",
|
"Team/project lookup result",
|
||||||
extra={
|
extra={
|
||||||
"team_name": team_key,
|
"team_name": team_identifier,
|
||||||
"team_id": team_id,
|
|
||||||
"project_name": project_key,
|
"project_name": project_key,
|
||||||
"repo_config": repo_config,
|
"repo_config": repo_config,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue