diff --git a/.github/file-filters.yml b/.github/file-filters.yml index 5a5bb5b1c8685f..ed77c971ced78e 100644 --- a/.github/file-filters.yml +++ b/.github/file-filters.yml @@ -47,6 +47,9 @@ backend_build_changes: &backend_build_changes - 'Makefile' - 'pyproject.toml' +backend_api_urls: &backend_api_urls + - '**/urls.py' + # `backend_src` filters on files that are backend changes excluding # changes to the tests/ directory and changes to typescript related config files. # If you want to filter on *all* backend files, use the `backend_all` filter. diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index be2eb92e04944a..bd082512a3458c 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -27,6 +27,7 @@ jobs: api_docs: ${{ steps.changes.outputs.api_docs }} backend: ${{ steps.changes.outputs.backend_all }} backend_dependencies: ${{ steps.changes.outputs.backend_dependencies }} + backend_api_urls: ${{ steps.changes.outputs.backend_api_urls }} backend_any_type: ${{ steps.changes.outputs.backend_any_type }} migration_lockfile: ${{ steps.changes.outputs.migration_lockfile }} steps: @@ -245,6 +246,41 @@ jobs: github-token: ${{ steps.token.outputs.token }} message: ':snowflake: re-freeze requirements' + api-url-typescript: + if: needs.files-changed.outputs.backend_api_urls == 'true' + needs: files-changed + name: api url typescript generation + runs-on: ubuntu-24.04 + timeout-minutes: 10 + steps: + - # get a non-default github token so that any changes are verified by CI + if: env.SECRET_ACCESS == 'true' + uses: getsentry/action-github-app-token@d4b5da6c5e37703f8c3b3e43abb5705b46e159cc # v3.0.0 + id: token + with: + app_id: ${{ vars.SENTRY_INTERNAL_APP_ID }} + private_key: ${{ secrets.SENTRY_INTERNAL_APP_PRIVATE_KEY }} + + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + + - name: Setup sentry env + uses: ./.github/actions/setup-sentry + id: setup + with: + mode: backend-ci + + - name: Sync API Urls to TypeScirpt + run: | + python3 -m tools.api_urls_to_typescript + + - name: Apply any file changes + # note: this runs "always" or else it's skipped when pre-commit fails + if: env.SECRET_ACCESS == 'true' && startsWith(github.ref, 'refs/pull') && always() + uses: getsentry/action-github-commit@31f6706ca1a7b9ad6d22c1b07bf3a92eabb05632 # v2.0.0 + with: + github-token: ${{ steps.token.outputs.token }} + message: ':hammer_and_wrench: Sync API Urls to TypeScirpt' + migration: if: needs.files-changed.outputs.migration_lockfile == 'true' needs: files-changed diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 08514004902478..04aac4c911b468 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -135,12 +135,6 @@ repos: stages: [pre-push] entry: bash -c 'if [ -n "${SENTRY_KNIP_PRE_PUSH:-}" ]; then exec ./node_modules/.bin/knip; fi' -- - - id: gen-ts-api-urls - name: gen-ts-api-urls - language: system - files: /urls\.py$ - entry: python3 -m tools.api_urls_to_typescript - - repo: https://github.com/pre-commit/pygrep-hooks rev: v1.10.0 hooks: diff --git a/static/app/utils/api/knownSentryApiUrls.generated.ts b/static/app/utils/api/knownSentryApiUrls.generated.ts index 2cdab59151b9ef..2e6a675855b5f2 100644 --- a/static/app/utils/api/knownSentryApiUrls.generated.ts +++ b/static/app/utils/api/knownSentryApiUrls.generated.ts @@ -275,6 +275,7 @@ export type KnownSentryApiUrls = | '/organizations/$organizationIdOrSlug/flags/signing-secrets/' | '/organizations/$organizationIdOrSlug/flags/signing-secrets/$signingSecretId/' | '/organizations/$organizationIdOrSlug/fork/' + | '/organizations/$organizationIdOrSlug/forwarding/' | '/organizations/$organizationIdOrSlug/group-search-views/' | '/organizations/$organizationIdOrSlug/group-search-views/$viewId/' | '/organizations/$organizationIdOrSlug/group-search-views/$viewId/starred/' @@ -347,6 +348,8 @@ export type KnownSentryApiUrls = | '/organizations/$organizationIdOrSlug/integration-requests/' | '/organizations/$organizationIdOrSlug/integrations/' | '/organizations/$organizationIdOrSlug/integrations/$integrationId/' + | '/organizations/$organizationIdOrSlug/integrations/$integrationId/channel-validate/' + | '/organizations/$organizationIdOrSlug/integrations/$integrationId/channels/' | '/organizations/$organizationIdOrSlug/integrations/$integrationId/issues/' | '/organizations/$organizationIdOrSlug/integrations/$integrationId/migrate-opsgenie/' | '/organizations/$organizationIdOrSlug/integrations/$integrationId/repos/' @@ -360,6 +363,7 @@ export type KnownSentryApiUrls = | '/organizations/$organizationIdOrSlug/issues-count/' | '/organizations/$organizationIdOrSlug/issues-metrics/' | '/organizations/$organizationIdOrSlug/issues-stats/' + | '/organizations/$organizationIdOrSlug/issues-timeseries/' | '/organizations/$organizationIdOrSlug/issues/' | '/organizations/$organizationIdOrSlug/issues/$issueId/' | '/organizations/$organizationIdOrSlug/issues/$issueId/activities/' @@ -625,6 +629,7 @@ export type KnownSentryApiUrls = | '/projects/$organizationIdOrSlug/$projectIdOrSlug/performance/configure/' | '/projects/$organizationIdOrSlug/$projectIdOrSlug/plugins/' | '/projects/$organizationIdOrSlug/$projectIdOrSlug/plugins/$pluginId/' + | '/projects/$organizationIdOrSlug/$projectIdOrSlug/preprod-artifact/rerun-analysis/$headArtifactId/' | '/projects/$organizationIdOrSlug/$projectIdOrSlug/preprodartifacts/$headArtifactId/build-details/' | '/projects/$organizationIdOrSlug/$projectIdOrSlug/preprodartifacts/$headArtifactId/delete/' | '/projects/$organizationIdOrSlug/$projectIdOrSlug/preprodartifacts/$headArtifactId/install-details/' @@ -697,6 +702,7 @@ export type KnownSentryApiUrls = | '/projects/$organizationIdOrSlug/$projectIdOrSlug/user-stats/' | '/projects/$organizationIdOrSlug/$projectIdOrSlug/users/' | '/projects/$organizationIdOrSlug/pr-comments/$repoName/$prNumber/' + | '/projects/$organizationIdOrSlug/pull-requests/size-analysis/$artifactId/' | '/projects/$organizationIdOrSlug/pullrequest-details/$repoName/$prNumber/' | '/prompts-activity/' | '/publickeys/relocations/' diff --git a/tools/api_urls_to_typescript.py b/tools/api_urls_to_typescript.py index cb47ba39b707fc..2fbb67e0a08269 100644 --- a/tools/api_urls_to_typescript.py +++ b/tools/api_urls_to_typescript.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 # flake8: noqa: S002 import re @@ -155,7 +156,7 @@ def replace_named_group(match: re.Match[str]) -> str: return route -if __name__ == "__main__": +def main() -> int: import sys from sentry.runner import configure @@ -185,3 +186,8 @@ def replace_named_group(match: re.Match[str]) -> str: "\n".join([f" | '{r}'" for r in route_patterns]) + ";\n", ] ) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main())