Skip to content

fix(github): accept PR-tab URLs (e.g. /files, /commits) in PR URL parser - #68

Open
detail-app[bot] wants to merge 2 commits into
mainfrom
detail/bug-fix/fix-github-accept-pr-tab-urls-e-g-files-commits-in-e49f83
Open

detail-app[bot] wants to merge 2 commits into
mainfrom
detail/bug-fix/fix-github-accept-pr-tab-urls-e-g-files-commits-in-e49f83

Conversation

@detail-app

@detail-app detail-app Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Detail bug report: View on Detail

Bug

parseGithubPullRequestUrl in src/github/index.ts rejected valid GitHub PR URLs that carry a trailing path segment after the PR number — any PR-tab URL such as …/pull/42/files, /commits, /diffs, /conflicts, /patches, or a deep link like …/pull/42/files/diff/<sha>. The GITHUB_URL_RE regex only allowed an optional trailing / plus a ?# suffix after /pull/<n>, so any additional segment failed to match $ and the parser returned null.

Its sole consumer, generatePrDescriptions, selects projects whose prUrl contains /pull/ (so tab URLs are selected), then on null sets prDescriptionFetchedAt without prShortDescription and continues — permanently blacklisting the row. Affected PRs never appear in the contributions query, which filters prShortDescription: { not: null }. Students paste their own PR links via addProjectPr with no normalization, so a URL copied from GitHub's Files-changed or Commits tab is stored verbatim and silently dropped.

Fix

  • Widened GITHUB_URL_RE to allow zero or more trailing path segments after the PR (or issue) number via (?:\/[^/?#]+)*? inside the existing (issues|pull)/(\d+) group. Capture-group indices are unchanged, so parseGithubPullRequestUrl and parseGithubRepoUrl are unchanged beyond accepting the trailing segments. I used *? (multi-segment) rather than a single-segment form so deep PR links (e.g. /pull/42/files/diff/<sha>, /pull/42/commits/<sha>) also parse.
  • Added a one-time Prisma migration (20260925120000_reset_blacklisted_pr_tab_urls) that resets prDescriptionFetchedAt and prShortDescription to NULL only for rows the over-narrow regex wrongly blacklisted — fetched-but-no-description, with a prUrl matching a PR-tab pattern. This re-queues them for the next cron run; already-summarized PRs, never-attempted rows, genuinely malformed URLs, and non-github URLs are untouched.

Testing

  • Routine checks pass: tsc --skipLibCheck --noEmit, the offline parser unit tests, a Docker build (CI parity), and npm run prisma (no schema.prisma churn).
  • Added 3 curated regression rows to src/github/index.test.ts: a trailing-tab URL (/pull/42/files), a multi-segment deep link (/pull/42/files/diff/abc123), and an issue URL with a trailing segment (/issues/42/files → null, guarding against over-acceptance since the new clause attaches to the shared (issues|pull) group). Reverting only the regex makes these fail and the suite exit 1, confirming they guard the fix.
  • Swept additional GitHub URL shapes (tab + query/fragment, deep nested paths, www., http://, /pull/ with no number, /blob/..., non-github hosts) — all parse as expected.
  • Stubbed-consumer test of generatePrDescriptions (typedi Container injection): a /pull/42/files row now gets the success update signature (both prDescriptionFetchedAt and a non-empty prShortDescription, with the ref {codeday, labs-gql, 42} extracted), while genuinely malformed URLs still get the blacklist-only signature.
  • Migration scope/idempotency against an isolated Postgres: seeded 7 representative Project rows and ran the migration SQL — exactly the 3 PR-tab blacklisted rows were reset; already-summarized, never-attempted, malformed, and non-github rows were untouched. Re-running updated 0 rows.
  • End-to-end data path: seeded a blacklisted …/pull/42/files row, applied the reset SQL, ran the real generatePrDescriptions task (real PrismaClient, external GitHub/OpenAI calls stubbed), and confirmed the row appears in the contributions-equivalent query with prUrl preserved verbatim and a non-empty prShortDescription.

Could not run:

  • prisma migrate deploy against a fresh database: it fails at a pre-existing 2022 migration (DROP INDEX "Student.username_unique" references an index no migration in the chain creates), which cascades to later migrations. Unrelated to this fix; the migration's SQL validity was instead verified by building the schema from schema.prisma (prisma db push) and executing the migration SQL against it.
  • Live /graphql endpoint smoke test: the dev environment has no Elasticsearch (the server fails to boot with a connection refused on the configured ELASTIC_URL) and the configured GITHUB_TOKEN/OPENROUTER_API_KEY are placeholder values GitHub rejects with 401 Bad credentials. The data-path test above exercises everything except the two external API calls.

Note: npx eslint . reports 285 parse errors across the repo from a pre-existing eslint/@typescript-eslint/parser incompatibility with the installed TypeScript (present on untouched files); not introduced or worsened by this change, and not run in CI.


Automatic Fixes PRs can be configured here.

@augmentcode

augmentcode Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor
🤖 Augment PR Summary

Summary: Broadens GitHub URL parsing to recognize PR and issue URLs with trailing tab or deep-link paths.
Data recovery: Adds a migration to requeue previously blacklisted PR-tab projects, plus regression coverage for the new URL shapes.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

"prShortDescription" = NULL
WHERE "prDescriptionFetchedAt" IS NOT NULL
AND "prShortDescription" IS NULL
AND "prUrl" ~ 'github\.com/[^/]+/[^/]+/pull/[0-9]+/';

@augmentcode augmentcode Bot Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prisma/migrations/20260925120000_reset_blacklisted_pr_tab_urls/migration.sql:6 also matches https://github.com/o/r/pull/42/, which the prior regex already parsed; if summarization returned no text, this migration resets it and causes another GitHub/OpenAI attempt despite it not being affected by this regression. The unanchored match likewise includes hosts such as notgithub.com, outside the intended GitHub-only recovery scope.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 6973637. Anchored the match to ^https?://(www.)?github.com/ and required a path segment after the PR number (pull/[0-9]+/[^/?#]), so plain pull// URLs (already parsed by the prior regex) and non-github hosts like notgithub.com are no longer reset.

… segment

Anchor the migration's prUrl match to github.com and require at least one
path segment after the PR number, so plain pull/<n>/ URLs (already parsed
by the prior regex) and non-github hosts are not reset unnecessarily.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant