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:
@@ -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 () => {
|
it("searches only GitHub PRs when the search kinds request excludes issues", async () => {
|
||||||
const runner = createRunner([searchPullRequestJson("PR title")]);
|
const runner = createRunner([searchPullRequestJson("PR title")]);
|
||||||
const service = createGitHubService({
|
const service = createGitHubService({
|
||||||
|
|||||||
@@ -933,11 +933,12 @@ export function createGitHubService(options: CreateGitHubServiceOptions = {}): G
|
|||||||
const readOptions: GitHubReadOptions = input.force
|
const readOptions: GitHubReadOptions = input.force
|
||||||
? { force: true, reason: input.reason }
|
? { force: true, reason: input.reason }
|
||||||
: { force: false, reason: input.reason };
|
: { force: false, reason: input.reason };
|
||||||
|
const query = normalizeGitHubSearchQuery(input.query);
|
||||||
const [issuesResult, prsResult] = await Promise.allSettled([
|
const [issuesResult, prsResult] = await Promise.allSettled([
|
||||||
shouldFetchIssues
|
shouldFetchIssues
|
||||||
? this.listIssues({
|
? this.listIssues({
|
||||||
cwd: input.cwd,
|
cwd: input.cwd,
|
||||||
query: input.query,
|
query,
|
||||||
limit: input.limit,
|
limit: input.limit,
|
||||||
...readOptions,
|
...readOptions,
|
||||||
})
|
})
|
||||||
@@ -945,7 +946,7 @@ export function createGitHubService(options: CreateGitHubServiceOptions = {}): G
|
|||||||
shouldFetchPullRequests
|
shouldFetchPullRequests
|
||||||
? this.listPullRequests({
|
? this.listPullRequests({
|
||||||
cwd: input.cwd,
|
cwd: input.cwd,
|
||||||
query: input.query,
|
query,
|
||||||
limit: input.limit,
|
limit: input.limit,
|
||||||
...readOptions,
|
...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 {
|
function buildCacheKey(params: { cwd: string; method: string; args: unknown }): string {
|
||||||
return `${params.cwd}:${params.method}:${stableStringify(params.args)}`;
|
return `${params.cwd}:${params.method}:${stableStringify(params.args)}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user