Detect GitHub issue/PR URL in composer search

Pasting a GitHub issue or pull request URL into the composer's
issue/PR picker now searches by the number from the URL instead
of treating the full URL as a keyword that returns no matches.
This commit is contained in:
Mohamed Boudra
2026-05-07 15:23:45 +07:00
parent 0785ee31f0
commit bad304c2d3
2 changed files with 50 additions and 2 deletions
@@ -1698,6 +1698,44 @@ describe("GitHubService", () => {
]);
});
it("treats a GitHub issue or PR URL as a search for that number", async () => {
const runner = createRunner([issueJson("Issue title"), searchPullRequestJson("PR title")]);
const service = createGitHubService({
runner: runner.runner,
resolveGhPath: async () => "/usr/bin/gh",
now: () => 100,
});
await service.searchIssuesAndPrs({
cwd: "/repo",
query: "https://github.com/getpaseo/paseo/pull/793",
limit: 5,
});
expect(runner.calls.map((call) => call.args)).toEqual([
[
"issue",
"list",
"--search",
"793",
"--json",
"number,title,url,state,body,labels,updatedAt",
"--limit",
"5",
],
[
"pr",
"list",
"--search",
"793",
"--json",
"number,title,url,state,body,labels,baseRefName,headRefName,updatedAt",
"--limit",
"5",
],
]);
});
it("searches only GitHub PRs when the search kinds request excludes issues", async () => {
const runner = createRunner([searchPullRequestJson("PR title")]);
const service = createGitHubService({
+12 -2
View File
@@ -933,11 +933,12 @@ export function createGitHubService(options: CreateGitHubServiceOptions = {}): G
const readOptions: GitHubReadOptions = input.force
? { force: true, reason: input.reason }
: { force: false, reason: input.reason };
const query = normalizeGitHubSearchQuery(input.query);
const [issuesResult, prsResult] = await Promise.allSettled([
shouldFetchIssues
? this.listIssues({
cwd: input.cwd,
query: input.query,
query,
limit: input.limit,
...readOptions,
})
@@ -945,7 +946,7 @@ export function createGitHubService(options: CreateGitHubServiceOptions = {}): G
shouldFetchPullRequests
? this.listPullRequests({
cwd: input.cwd,
query: input.query,
query,
limit: input.limit,
...readOptions,
})
@@ -1171,6 +1172,15 @@ async function runGhCommand(
});
}
const GITHUB_ISSUE_OR_PR_URL_PATTERN =
/^https?:\/\/github\.com\/[^/\s]+\/[^/\s]+\/(?:pull|issues)\/(\d+)(?:[/?#].*)?$/i;
function normalizeGitHubSearchQuery(query: string): string {
const trimmed = query.trim();
const match = trimmed.match(GITHUB_ISSUE_OR_PR_URL_PATTERN);
return match ? match[1] : query;
}
function buildCacheKey(params: { cwd: string; method: string; args: unknown }): string {
return `${params.cwd}:${params.method}:${stableStringify(params.args)}`;
}