Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/file-filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ backend_build_changes: &backend_build_changes
- 'Makefile'
- 'pyproject.toml'

backend_api_urls: &backend_api_urls
- '**/urls.py'
Comment on lines +50 to +51
Copy link
Member

Choose a reason for hiding this comment

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

This might mis-match some things. Not huge problem but I wonder if we can be slightly more specific.

Copy link
Member Author

Choose a reason for hiding this comment

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

it kinda mis-matches on purpose, there are gaps too.

The main entry file is src/sentry/api/urls.py but that also imports from:

  • src/sentry/workflow_engine/endpoints/urls.py
  • src/sentry/notifications/platform/api/endpoints/urls.py
  • src/sentry/preprod/api/endpoints/urls.py
  • and maybe more in the future.

So i'm trying to catch them all for now. Like i said before, the script is sus, but good enough to get started adopting getApiUrl() imo

Copy link
Member

Choose a reason for hiding this comment

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

we can add a comment maybe too

Copy link
Member Author

Choose a reason for hiding this comment

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


# `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.
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: Token Generation Fails Due to Undefined Variable

The api-url-typescript job's token generation and commit steps use env.SECRET_ACCESS == 'true'. Since SECRET_ACCESS is undefined, these steps are always skipped, preventing the job from obtaining a token or committing generated TypeScript changes. This differs from the pattern in other similar jobs.

Fix in Cursor Fix in Web

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
Expand Down
6 changes: 0 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions static/app/utils/api/knownSentryApiUrls.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
Expand Down Expand Up @@ -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/'
Expand All @@ -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/'
Expand Down Expand Up @@ -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/'
Expand Down Expand Up @@ -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/'
Expand Down
8 changes: 7 additions & 1 deletion tools/api_urls_to_typescript.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
# flake8: noqa: S002

import re
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Loading