From d359eda10c6a2f0f7531d9eba6b34a931cd09688 Mon Sep 17 00:00:00 2001 From: Stephanie Anderson Date: Tue, 24 Nov 2026 19:34:16 +0100 Subject: [PATCH 1/2] ref(validate-pr)!: Remove the action The action is no longer used: its caller workflows have been removed from almost all dependent repositories, and the rest have a removal pull request open. BREAKING CHANGE: getsentry/github-workflows/validate-pr no longer exists. Co-Authored-By: Claude Fable 5.2 --- CHANGELOG.md | 4 + README.md | 6 - validate-pr/README.md | 97 ---------- validate-pr/action.yml | 32 ---- validate-pr/scripts/validate-pr.js | 297 ----------------------------- 5 files changed, 4 insertions(+), 432 deletions(-) delete mode 100644 validate-pr/README.md delete mode 100644 validate-pr/action.yml delete mode 100644 validate-pr/scripts/validate-pr.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 055e26e..26ef46b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Breaking Changes + +- Validate PR - Remove the action. Workflows that still use `getsentry/github-workflows/validate-pr` fail once they point at a ref without it, so delete the workflow from your repository. ([#PRNUM](https://github.com/getsentry/github-workflows/pull/PRNUM)) + ### Features - Skip CI - Add an action that tells whether a push to a pull request only changes files that need no CI, such as Markdown, since a head whose run passed. Jobs gated on its `skip` output don't run for a CHANGELOG fix-up. ([#187](https://github.com/getsentry/github-workflows/pull/187)) diff --git a/README.md b/README.md index 22782ac..046175c 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,6 @@ Runs DangerJS on Pull Requests with a pre-configured set of rules. **[📖 View full documentation →](danger/README.md)** -### Validate PR - -Validates non-maintainer PRs against contribution guidelines and enforces draft status. - -**[📖 View full documentation →](validate-pr/README.md)** - ### Skip CI Tells whether a push to a pull request only changes files that need no CI, such as Markdown, so expensive jobs can be skipped. diff --git a/validate-pr/README.md b/validate-pr/README.md deleted file mode 100644 index 7403d04..0000000 --- a/validate-pr/README.md +++ /dev/null @@ -1,97 +0,0 @@ -# Validate PR - -Advisory validation for non-maintainer pull requests against contribution guidelines. Posts a single friendly comment when a PR doesn't reference an issue with prior maintainer discussion. **PRs are never closed, and no labels are applied.** - -## What it does - -For PRs from non-maintainer authors, the action checks that the PR body references a GitHub issue where the PR author and a maintainer have discussed the approach. When that's not the case, the action posts one short advisory comment inviting the contributor to start with an issue. Maintainers (`admin` or `maintain` role), bots of GitHub Apps owned by Sentry, and a hard-coded list of trusted bots are exempt. - -Small PRs (< 100 lines changed, excluding lock files) are skipped entirely — typo fixes and tiny bug fixes don't need to go through the issue-discussion loop. - -## Usage - -Create `.github/workflows/validate-pr.yml` in your repository: - -```yaml -name: Validate PR - -on: - pull_request_target: - types: [opened] - -jobs: - validate-pr: - runs-on: ubuntu-24.04 - permissions: - pull-requests: write - steps: - - uses: getsentry/github-workflows/validate-pr@ - with: - app-id: ${{ vars.SDK_MAINTAINER_BOT_APP_ID }} - private-key: ${{ secrets.SDK_MAINTAINER_BOT_PRIVATE_KEY }} -``` - -Pin to a specific commit SHA (consumers in `getsentry/*` already follow this convention). The `pull-requests: write` permission is needed because the action posts comments on the PR. - -## Inputs - -| Input | Required | Description | -|-------|----------|-------------| -| `app-id` | Yes | GitHub App ID for the SDK Maintainer Bot | -| `private-key` | Yes | GitHub App private key for the SDK Maintainer Bot | - -## Validation rules - -### Skipped entirely - -- PR author is in the trusted-bot allowlist (Dependabot, Renovate, Codecov AI, etc.) -- PR author is the bot user of a GitHub App owned by the `getsentry` organization or the `sentry` enterprise (e.g. `sentry-junior[bot]`) -- PR author has `admin`, `maintain`, `push`, or `write` access on the repo -- PR has fewer than 100 lines changed (`additions + deletions`), excluding common lock files - -### Lock files excluded from line counts - -Matched by basename, case-insensitive: - -| Ecosystem | File | -|-----------|------| -| Rust | `Cargo.lock` | -| JS | `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml` | -| Python | `Pipfile.lock`, `poetry.lock`, `uv.lock` | -| Ruby | `Gemfile.lock` | -| PHP | `composer.lock` | -| Go | `go.sum` (`go.mod` is hand-edited and stays counted) | -| Elixir | `mix.lock` | -| Dart/Flutter | `pubspec.lock` | -| .NET/NuGet | `packages.lock.json` | -| CocoaPods | `Podfile.lock` | -| Nix | `flake.lock` | - -### Issue reference check - -For PRs that reach validation, the action scans the PR body for issue references in these formats: - -- `#123` (same-repo) -- `getsentry/repo#123` (cross-repo) -- `https://github.com/getsentry/repo/issues/123` (full URL) -- With optional keywords: `Fixes #123`, `Closes getsentry/repo#123`, etc. - -The PR is considered compliant if **any** referenced issue passes all of: - -- The issue is fetchable and in a `getsentry` repository -- If the issue has assignees, the PR author is one of them -- Both the PR author and a maintainer have participated in the issue discussion - -If no referenced issue passes, the action posts one advisory comment. The PR remains open and reviewable; no labels or status checks are applied. The comment is idempotent — workflow re-runs on the same PR will not produce duplicates. - -## Updating from earlier revisions - -Earlier revisions of this action closed non-compliant PRs and applied labels (`violating-contribution-guidelines`, `missing-issue-reference`, `missing-maintainer-discussion`, `issue-already-assigned`). The current version does neither — it only posts a comment. - -To update an existing consumer: - -- Bump the pinned commit SHA to the latest on `main`. -- Change `types: [opened, reopened]` → `types: [opened]`. -- Remove any code that reads the `was-closed` output (it no longer exists). - -Existing labels on old PRs are not removed automatically. Clean them up with a one-off script if desired. diff --git a/validate-pr/action.yml b/validate-pr/action.yml deleted file mode 100644 index d5b78b3..0000000 --- a/validate-pr/action.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: 'Validate PR' -description: 'Validates non-maintainer PRs against contribution guidelines' -author: 'Sentry' - -inputs: - app-id: - description: 'GitHub App ID for the SDK Maintainer Bot' - required: true - private-key: - description: 'GitHub App private key for the SDK Maintainer Bot' - required: true - -runs: - using: 'composite' - steps: - - name: Generate GitHub App token - id: app-token - uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v2 - with: - app-id: ${{ inputs.app-id }} - private-key: ${{ inputs.private-key }} - - - name: Validate PR - id: validate - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 - env: - APP_SLUG: ${{ steps.app-token.outputs.app-slug }} - with: - github-token: ${{ steps.app-token.outputs.token }} - script: | - const script = require('${{ github.action_path }}/scripts/validate-pr.js'); - await script({ github, context, core }); diff --git a/validate-pr/scripts/validate-pr.js b/validate-pr/scripts/validate-pr.js deleted file mode 100644 index 9679588..0000000 --- a/validate-pr/scripts/validate-pr.js +++ /dev/null @@ -1,297 +0,0 @@ -// @ts-check - -/** - * Advisory validation for community PRs. Posts a single friendly comment - * when the PR doesn't reference an issue with maintainer discussion. - * Never closes PRs, never applies labels. - * - * @param {object} params - * @param {import('@actions/github').getOctokit} params.github - * @param {import('@actions/github').context} params.context - * @param {import('@actions/core')} params.core - */ -module.exports = async ({ github, context, core }) => { - const pullRequest = context.payload.pull_request; - const repo = context.repo; - const prAuthor = pullRequest.user.login; - const contributingUrl = `https://github.com/${repo.owner}/${repo.repo}/blob/${context.payload.repository.default_branch}/CONTRIBUTING.md`; - - // --- Step 0: Skip allowed bots and service accounts --- - const ALLOWED_BOTS = [ - 'codecov-ai[bot]', - 'dependabot[bot]', - 'getsentry-bot', - 'github-actions[bot]', - 'renovate[bot]', - ]; - if (ALLOWED_BOTS.includes(prAuthor)) { - core.info(`PR author ${prAuthor} is an allowed bot. Skipping.`); - return; - } - - // --- Step 0b: Skip bots of GitHub Apps owned by Sentry --- - // App bot users are never repo collaborators, so the write-access check - // below reports `none` for them even when the app can push. Match the owner - // by type and immutable ID: owner logins are not unique across types (e.g. - // a `sentry` user account exists that is unrelated to the `sentry` enterprise). - const SENTRY_APP_OWNERS = [ - { type: 'organization', id: 1396951 }, // getsentry - { type: 'enterprise', id: 79916 }, // sentry - ]; - if (pullRequest.user.type === 'Bot' && prAuthor.endsWith('[bot]')) { - const authorAppSlug = prAuthor.slice(0, -'[bot]'.length); - try { - const { data: app } = await github.rest.apps.getBySlug({ app_slug: authorAppSlug }); - const ownerType = app.owner?.type?.toLowerCase(); - if (SENTRY_APP_OWNERS.some((o) => o.type === ownerType && o.id === app.owner?.id)) { - core.info(`PR author ${prAuthor} is a Sentry-owned GitHub App. Skipping.`); - return; - } - } catch (e) { - core.warning(`Could not look up GitHub App ${authorAppSlug} (${e.message}); proceeding.`); - } - } - - // --- Helpers: cached collaborator-role lookup --- - const roleCache = new Map(); - async function getRole(owner, repoName, username) { - const key = `${owner}/${repoName}:${username}`; - if (roleCache.has(key)) return roleCache.get(key); - let roleName = null; - try { - const { data } = await github.rest.repos.getCollaboratorPermissionLevel({ - owner, - repo: repoName, - username, - }); - roleName = data.role_name; - } catch { - // noop — roleName stays null - } - roleCache.set(key, roleName); - return roleName; - } - - async function hasWriteAccess(owner, repoName, username) { - const role = await getRole(owner, repoName, username); - return ['admin', 'maintain', 'push', 'write'].includes(role); - } - - async function isMaintainer(owner, repoName, username) { - const role = await getRole(owner, repoName, username); - return ['admin', 'maintain'].includes(role); - } - - // --- Step 1: Skip if PR author has write+ access --- - if (await hasWriteAccess(repo.owner, repo.repo, prAuthor)) { - core.info(`PR author ${prAuthor} has write+ access. Skipping.`); - return; - } - core.info(`PR author ${prAuthor} does not have write access.`); - - // --- Step 2: Small-PR bypass (excluding lock files) --- - const LOCK_FILE_BASENAMES = new Set([ - 'cargo.lock', - 'package-lock.json', - 'yarn.lock', - 'pnpm-lock.yaml', - 'pipfile.lock', - 'poetry.lock', - 'uv.lock', - 'gemfile.lock', - 'composer.lock', - 'go.sum', - 'mix.lock', - 'pubspec.lock', - 'packages.lock.json', - 'podfile.lock', - 'flake.lock', - ]); - const SMALL_PR_THRESHOLD = 100; - - const aggregateLOC = (pullRequest.additions || 0) + (pullRequest.deletions || 0); - if (aggregateLOC < SMALL_PR_THRESHOLD) { - core.info( - `PR has ${aggregateLOC} lines changed (< ${SMALL_PR_THRESHOLD}). Skipping.` - ); - return; - } - - // Stage 2: fetch file list and recompute excluding lock files. On API - // failure, fall through to validation rather than aborting — a transient - // GitHub error shouldn't break the action. - let files = null; - try { - files = await github.paginate(github.rest.pulls.listFiles, { - owner: repo.owner, - repo: repo.repo, - pull_number: pullRequest.number, - per_page: 100, - }); - } catch (e) { - core.warning( - `Could not fetch PR file list (${e.message}); skipping lock-file exclusion and proceeding to validation.` - ); - } - if (files) { - function basenameLower(path) { - const idx = path.lastIndexOf('/'); - return (idx >= 0 ? path.slice(idx + 1) : path).toLowerCase(); - } - const nonLockLOC = files - .filter((f) => !LOCK_FILE_BASENAMES.has(basenameLower(f.filename))) - .reduce((sum, f) => sum + (f.additions || 0) + (f.deletions || 0), 0); - if (nonLockLOC < SMALL_PR_THRESHOLD) { - core.info( - `PR has ${nonLockLOC} non-lock-file lines changed (< ${SMALL_PR_THRESHOLD}). Skipping.` - ); - return; - } - } - - // --- Step 3: Parse issue references from PR body --- - const body = pullRequest.body || ''; - const issueRefs = []; - const seen = new Set(); - - // Pattern 1: full GitHub URLs - const urlPattern = /https?:\/\/github\.com\/(getsentry)\/([\w.-]+)\/issues\/(\d+)/gi; - for (const match of body.matchAll(urlPattern)) { - const key = `${match[1]}/${match[2]}#${match[3]}`; - if (!seen.has(key)) { - seen.add(key); - issueRefs.push({ owner: match[1], repo: match[2], number: parseInt(match[3]) }); - } - } - - // Pattern 2: cross-repo references (getsentry/repo#123) - const crossRepoPattern = /(?:(?:fix|fixes|fixed|close|closes|closed|resolve|resolves|resolved)\s+)?(getsentry)\/([\w.-]+)#(\d+)/gi; - for (const match of body.matchAll(crossRepoPattern)) { - const key = `${match[1]}/${match[2]}#${match[3]}`; - if (!seen.has(key)) { - seen.add(key); - issueRefs.push({ owner: match[1], repo: match[2], number: parseInt(match[3]) }); - } - } - - // Pattern 3: same-repo references (#123) - const sameRepoPattern = /(?:(?:fix|fixes|fixed|close|closes|closed|resolve|resolves|resolved)\s+)?(? 0) { - const assignedToAuthor = issue.assignees.some((a) => a.login === prAuthor); - if (!assignedToAuthor) { - core.info(`Issue ${ref.owner}/${ref.repo}#${ref.number} is assigned to someone else.`); - continue; - } - } - - // Discussion check: PR author and a maintainer must both have participated. - const comments = await github.paginate(github.rest.issues.listComments, { - owner: ref.owner, - repo: ref.repo, - issue_number: ref.number, - per_page: 100, - }); - - const prAuthorParticipated = - issue.user?.login === prAuthor || - comments.some((c) => c.user?.login === prAuthor); - - if (!prAuthorParticipated) { - core.info(`Issue ${ref.owner}/${ref.repo}#${ref.number} has no PR author participation.`); - continue; - } - - const usersToCheck = new Set(); - if (issue.user?.login && issue.user.login !== prAuthor) { - usersToCheck.add(issue.user.login); - } - for (const comment of comments) { - if (comment.user?.login && comment.user.login !== prAuthor) { - usersToCheck.add(comment.user.login); - } - } - - let maintainerParticipated = false; - for (const user of usersToCheck) { - if (await isMaintainer(repo.owner, repo.repo, user)) { - maintainerParticipated = true; - core.info(`Maintainer ${user} participated in ${ref.owner}/${ref.repo}#${ref.number}.`); - break; - } - } - - if (maintainerParticipated) { - core.info(`Issue ${ref.owner}/${ref.repo}#${ref.number} has valid discussion. PR is allowed.`); - return; - } - core.info(`Issue ${ref.owner}/${ref.repo}#${ref.number} lacks maintainer participation.`); - } - - // --- Step 5: Validation failed — post one warm comment (idempotent) --- - // The bot's GitHub login is `${app.slug}[bot]`. We get the slug from the - // composite action via the APP_SLUG env var (sourced from - // create-github-app-token's `app-slug` output) — calling - // apps.getAuthenticated() here would fail because it requires JWT auth - // and the github client is authenticated with an installation token. - const appSlug = process.env.APP_SLUG; - if (!appSlug) { - core.setFailed( - 'APP_SLUG env var is not set. The validate-pr composite action must pass app-slug from create-github-app-token to the script.' - ); - return; - } - const botLogin = `${appSlug}[bot]`; - - const existing = await github.paginate(github.rest.issues.listComments, { - ...repo, - issue_number: pullRequest.number, - per_page: 100, - }); - if (existing.some((c) => c.user?.login === botLogin)) { - core.info(`Bot ${botLogin} already commented on this PR. Skipping.`); - return; - } - - const commentBody = [ - '👋 Thanks for sending this our way! Before a maintainer reviews the code, we ask community contributors to align with us on the approach first — it keeps your time pointed at changes we can land.', - '', - 'The easiest way is to open or find a GitHub issue and discuss the approach with a maintainer there, then link that issue from this PR. If the issue is already assigned to someone else, please check in with them (or with us) before continuing — otherwise two people may end up working on the same task.', - '', - `See our [contributing guidelines](${contributingUrl}) for the full picture.`, - ].join('\n'); - - await github.rest.issues.createComment({ - ...repo, - issue_number: pullRequest.number, - body: commentBody, - }); - core.info('Posted advisory comment. PR remains open.'); -}; From 41f1ef54172032bb7b6353c41235c2f6ad4362ea Mon Sep 17 00:00:00 2001 From: Stephanie Anderson Date: Tue, 24 Nov 2026 19:34:23 +0100 Subject: [PATCH 2/2] docs: Link the changelog entry to the pull request Co-Authored-By: Claude Fable 5.2 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26ef46b..51722ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Breaking Changes -- Validate PR - Remove the action. Workflows that still use `getsentry/github-workflows/validate-pr` fail once they point at a ref without it, so delete the workflow from your repository. ([#PRNUM](https://github.com/getsentry/github-workflows/pull/PRNUM)) +- Validate PR - Remove the action. Workflows that still use `getsentry/github-workflows/validate-pr` fail once they point at a ref without it, so delete the workflow from your repository. ([#189](https://github.com/getsentry/github-workflows/pull/189)) ### Features