You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expands the existing `source-code-management-platform.mdx` doc with
content compiled from the
[`scm-platform`](https://github.com/getsentry/scm-platform/) repo.
## What's new
- **Two usage modes**: in-process (monolith) vs RPC client (external
services)
- **All 70+ actions** grouped by category (PRs, issues, comments,
reactions, reviews, git objects, check runs)
- Pagination and ETag caching patterns
- Error handling guidance
- Local dev workflow using `bin/github-server` + `bin/github-client`
- Supported providers and the `isinstance` guard pattern the `Facade`
requires
Generated with assistance from Junior.
---------
Co-authored-by: junior <junior@sentry.io>
Co-authored-by: Colton Allen <colton.allen@sentry.io>
from scm.actions import SourceCodeManager, create_issue_reaction, create_issue_comment
43
44
```
44
45
45
-
By default the SourceCodeManager class can not execute any methods without the type checker complaining. To smooth over service-provider variations, the SCM ships a capability system. You must statically assert that your "scm" instance is capable of executing a particular action or set of actions prior to calling an action function.
46
+
By default the `SourceCodeManager` cannot execute methods without a capability assertion. Use `isinstance` guards to assert that the provider supports the action you need:
46
47
47
48
```python
48
-
from sentry.scm.types import CreateIssueReactionProtocol, CreateIssueCommentProtocol
49
-
49
+
from scm.types import CreateIssueReactionProtocol, CreateIssueCommentProtocol
from scm.providers.github.providerimport GitHubProvider
81
80
82
81
ifisinstance(scm, GitHubProvider):
83
-
#do github specific work.
82
+
#GitHub-specific work
84
83
...
85
84
```
86
85
87
-
This pattern is discouraged, however, and is hidden within the `private` module. It is preferred that you interact with service-providers on a capability basis so that your feature is automatically enabled for new service-providers but we understand that this is not always desired.
86
+
Prefer capability-based checks so your feature is automatically available to new providers.
87
+
88
+
### RPC Client Usage (External Services)
89
+
90
+
The `SourceCodeManager` is fully accessible over RPC from services outside the monolith:
The RPC client implements the same protocol interfaces as the in-process client, so all `isinstance` guards and action functions work identically.
88
110
89
-
SCM actions will raise exceptions on failure. All exceptions are subclassed by `SCMError`. It is recommended that you catch these failures and handle them in some way.
111
+
## Error Handling
112
+
113
+
All SCM actions raise exceptions on failure. Every exception is a subclass of `SCMError`:
The SCM exposes the following actions. For more information (and more up to date information) browse the `/src/sentry/scm/actions.py` file in the `getsentry/sentry` repository.
101
-
102
-
-`compare_commits`
103
-
-`create_branch`
104
-
-`create_check_run`
105
-
-`create_git_blob`
106
-
-`create_git_commit`
107
-
-`create_git_tree`
108
-
-`create_issue_comment`
109
-
-`create_issue_comment_reaction`
110
-
-`create_issue_reaction`
111
-
-`create_pull_request`
112
-
-`create_pull_request_comment`
113
-
-`create_pull_request_comment_reaction`
114
-
-`create_pull_request_draft`
115
-
-`create_pull_request_reaction`
116
-
-`create_review`
117
-
-`create_review_comment_file`
118
-
-`create_review_comment_reply`
119
-
-`delete_issue_comment`
120
-
-`delete_issue_comment_reaction`
121
-
-`delete_issue_reaction`
122
-
-`delete_pull_request_comment`
123
-
-`delete_pull_request_comment_reaction`
124
-
-`delete_pull_request_reaction`
125
-
-`get_archive_link`
126
-
-`get_branch`
127
-
-`get_check_run`
128
-
-`get_commit`
129
-
-`get_commits`
130
-
-`get_commits_by_path`
131
-
-`get_file_content`
132
-
-`get_git_commit`
133
-
-`get_issue_comment_reactions`
134
-
-`get_issue_comments`
135
-
-`get_issue_reactions`
136
-
-`get_pull_request`
137
-
-`get_pull_request_comment_reactions`
138
-
-`get_pull_request_comments`
139
-
-`get_pull_request_commits`
140
-
-`get_pull_request_diff`
141
-
-`get_pull_request_files`
142
-
-`get_pull_request_reactions`
143
-
-`get_pull_requests`
144
-
-`get_tree`
145
-
-`minimize_comment`
146
-
-`request_review`
147
-
-`update_branch`
148
-
-`update_check_run`
149
-
-`update_pull_request`
150
-
151
-
### Source Code Manager RPC
152
-
153
-
The Source Code Manager is exposed over RPC and may be accessed with the client library in your microservice.
124
+
## Pagination
125
+
126
+
List endpoints return a typed dict result. Use `PaginationParams` to traverse pages:
-`cursor`: opaque token from the previous page's `next_cursor`
139
+
-`per_page`: number of items per page
140
+
-`next_cursor` is `None` when there are no more pages
141
+
142
+
143
+
## Event Stream
166
144
167
-
Source code management service providers will push events to Sentry. The Source Code Management Platform exposes a typed, event-stream interface which may be listened to by interested implementers.
145
+
SCM providers push events to Sentry. Register typed listeners using the `@scm_event_stream.listen_for` decorator:
168
146
169
147
```python
170
148
from sentry.scm.stream import CheckRunEvent, scm_event_stream
Event stream listeners are isolated. They run asynchronously in their own worker process.
156
+
Listeners are isolated and run asynchronously in their own worker processes.
179
157
180
-
The event stream supports the following event types.
158
+
Supported event types:
181
159
182
160
-`CheckRunEvent`
183
161
-`CommentEvent`
184
162
-`PullRequestEvent`
185
163
186
-
### Observability
164
+
## Actions Reference
165
+
166
+
For the full list of available actions and their signatures, see [`src/scm/actions.py`](https://github.com/getsentry/scm-platform/blob/main/src/scm/actions.py).
167
+
168
+
## Observability
187
169
188
170
Both subsystems emit metrics under the `sentry.scm` namespace:
189
171
@@ -199,3 +181,35 @@ Both subsystems emit metrics under the `sentry.scm` namespace:
199
181
|`sentry.scm.run_listener.queue_time`| Time from webhook receipt to task start |
200
182
|`sentry.scm.run_listener.task_time`| Time to execute the listener |
201
183
|`sentry.scm.run_listener.real_time`| End-to-end time from webhook receipt to listener completion |
184
+
185
+
## Local Development
186
+
187
+
The `scm-platform` repo includes CLI scripts for running an RPC server and client locally against the real GitHub API.
188
+
189
+
### Start the RPC server
190
+
191
+
```bash
192
+
# Populate .credentials with your GitHub App credentials (KEY=VALUE, one per line):
0 commit comments