mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 12:43:16 +00:00
feat: default org to langchain-ai when repo name specified without org (#1099)
* feat: default org to langchain-ai when repo: is used without org prefix * chore: use SLACK_REPO_OWNER for repo shorthand default org and document in CUSTOMIZATION.md --------- Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
This commit is contained in:
parent
150ff6f0c8
commit
6fc82d9edd
3 changed files with 44 additions and 3 deletions
|
|
@ -289,7 +289,7 @@ SLACK_REPO_OWNER="my-org"
|
|||
SLACK_REPO_NAME="my-repo"
|
||||
```
|
||||
|
||||
Users can override per-message with `repo:owner/name` syntax in their Slack message.
|
||||
Users can override per-message with `repo:owner/name` syntax in their Slack message. A shorthand `repo:name` (without the org) is also supported — the org defaults to the value of `SLACK_REPO_OWNER`.
|
||||
|
||||
### Adding a new trigger
|
||||
|
||||
|
|
|
|||
|
|
@ -355,9 +355,14 @@ async def get_slack_repo_config(message: str, channel_id: str, thread_ts: str) -
|
|||
name: str | None = None
|
||||
|
||||
if "repo:" in message or "repo " in message:
|
||||
match = re.search(r"repo[: ]([a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+)", message)
|
||||
match = re.search(r"repo[: ]([a-zA-Z0-9_.\-/]+)", message)
|
||||
if match:
|
||||
owner, name = match.group(1).split("/", 1)
|
||||
value = match.group(1).rstrip("/")
|
||||
if "/" in value:
|
||||
owner, name = value.split("/", 1)
|
||||
else:
|
||||
owner = default_owner
|
||||
name = value
|
||||
|
||||
if not owner or not name:
|
||||
github_match = re.search(r"github\.com/([a-zA-Z0-9_.-]+/[a-zA-Z0-9_.-]+)", message)
|
||||
|
|
|
|||
|
|
@ -321,3 +321,39 @@ def test_get_slack_repo_config_github_url_beats_thread_metadata(
|
|||
)
|
||||
|
||||
assert repo == {"owner": "langchain-ai", "name": "langgraph-api"}
|
||||
|
||||
|
||||
def test_get_slack_repo_config_repo_name_only_defaults_org(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""repo:name without org should default owner to langchain-ai."""
|
||||
threads_client = _FakeThreadsClient(raise_not_found=True)
|
||||
|
||||
async def fake_post_slack_thread_reply(channel_id: str, thread_ts: str, text: str) -> bool:
|
||||
return True
|
||||
|
||||
monkeypatch.setattr(webapp, "get_client", lambda url: _FakeClient(threads_client))
|
||||
monkeypatch.setattr(webapp, "post_slack_thread_reply", fake_post_slack_thread_reply)
|
||||
|
||||
repo = asyncio.run(
|
||||
webapp.get_slack_repo_config("fix bug in repo:langchainplus", "C123", "1.234")
|
||||
)
|
||||
|
||||
assert repo == {"owner": "langchain-ai", "name": "langchainplus"}
|
||||
|
||||
|
||||
def test_get_slack_repo_config_repo_name_only_space_syntax(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""repo name (space syntax, no org) should default owner to langchain-ai."""
|
||||
threads_client = _FakeThreadsClient(raise_not_found=True)
|
||||
|
||||
async def fake_post_slack_thread_reply(channel_id: str, thread_ts: str, text: str) -> bool:
|
||||
return True
|
||||
|
||||
monkeypatch.setattr(webapp, "get_client", lambda url: _FakeClient(threads_client))
|
||||
monkeypatch.setattr(webapp, "post_slack_thread_reply", fake_post_slack_thread_reply)
|
||||
|
||||
repo = asyncio.run(webapp.get_slack_repo_config("fix bug in repo open-swe", "C123", "1.234"))
|
||||
|
||||
assert repo == {"owner": "langchain-ai", "name": "open-swe"}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue