diff --git a/prisma/migrations/20260925120000_reset_blacklisted_pr_tab_urls/migration.sql b/prisma/migrations/20260925120000_reset_blacklisted_pr_tab_urls/migration.sql new file mode 100644 index 0000000..076685f --- /dev/null +++ b/prisma/migrations/20260925120000_reset_blacklisted_pr_tab_urls/migration.sql @@ -0,0 +1,6 @@ +UPDATE "Project" +SET "prDescriptionFetchedAt" = NULL, + "prShortDescription" = NULL +WHERE "prDescriptionFetchedAt" IS NOT NULL + AND "prShortDescription" IS NULL + AND "prUrl" ~ '^https?://(www\.)?github\.com/[^/]+/[^/]+/pull/[0-9]+/[^/?#]'; diff --git a/src/github/index.test.ts b/src/github/index.test.ts index 59a8189..2c59611 100644 --- a/src/github/index.test.ts +++ b/src/github/index.test.ts @@ -57,11 +57,26 @@ function assertEqual(actual: T, expected: T, message: string): void { { owner: 'codeday', repo: 'labs-gql', number: 42 }, 'parses owner/repo/number from a pull request URL', ); + assertEqual( + parseGithubPullRequestUrl('https://github.com/codeday/labs-gql/pull/42/files'), + { owner: 'codeday', repo: 'labs-gql', number: 42 }, + 'parses a PR URL with a trailing tab segment (e.g. /files)', + ); + assertEqual( + parseGithubPullRequestUrl('https://github.com/codeday/labs-gql/pull/42/files/diff/abc123'), + { owner: 'codeday', repo: 'labs-gql', number: 42 }, + 'parses a PR URL with multiple trailing path segments (deep link)', + ); assertEqual( parseGithubPullRequestUrl('https://github.com/codeday/labs-gql/issues/42'), null, 'rejects an issue URL', ); + assertEqual( + parseGithubPullRequestUrl('https://github.com/codeday/labs-gql/issues/42/files'), + null, + 'rejects an issue URL with a trailing segment', + ); assertEqual( parseGithubPullRequestUrl('https://github.com/codeday/labs-gql'), null, diff --git a/src/github/index.ts b/src/github/index.ts index bf64e0e..2e21915 100644 --- a/src/github/index.ts +++ b/src/github/index.ts @@ -1,7 +1,7 @@ import fetch from 'node-fetch'; import config from '../config'; -const GITHUB_URL_RE = /^https?:\/\/(?:www\.)?github\.com\/([^/\s]+)\/([^/\s#?]+?)(?:\.git)?(?:\/(issues|pull)\/(\d+))?\/?(?:[?#].*)?$/i; +const GITHUB_URL_RE = /^https?:\/\/(?:www\.)?github\.com\/([^/\s]+)\/([^/\s#?]+?)(?:\.git)?(?:\/(issues|pull)\/(\d+)(?:\/[^/?#]+)*?)?\/?(?:[?#].*)?$/i; export interface GithubRepoRef { owner: string;