Repository navigation
feat: Add Dependabot alerts stream #611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
akashmalbari
wants to merge
5
commits into
MeltanoLabs:main
Choose a base branch
from
akashmalbari:fix/590-dependabot-alerts-stream
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8b357b4
feat: add Dependabot alerts stream
akashmalbari 217f41f
fix: make Dependabot alerts opt-in
akashmalbari b357dc6
Make mypy happy
edgarrmondragon b0229c7
fix: tolerate unavailable Dependabot alerts
akashmalbari a938dbe
fix: retry tolerated stream rate limits
akashmalbari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| """Tests for the Dependabot alerts stream.""" | ||
|
|
||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
| from requests import Response | ||
| from singer_sdk.exceptions import RetriableAPIError | ||
|
|
||
| from tap_github.repository_streams import DependabotAlertsStream | ||
| from tap_github.tap import TapGitHub | ||
|
|
||
| from .fixtures import repo_list_config # noqa: F401 | ||
|
|
||
|
|
||
| def test_dependabot_alerts_stream_is_incremental_and_cursor_paginated(repo_list_config): # noqa: F811 | ||
| """Dependabot alerts use the repository endpoint and updated-time state.""" | ||
| stream = DependabotAlertsStream(TapGitHub(config=repo_list_config)) | ||
|
|
||
| assert stream.path == "/repos/{org}/{repo}/dependabot/alerts" | ||
| assert stream.replication_key == "updated_at" | ||
| assert stream.use_fake_since_parameter is True | ||
| assert stream.use_cursor_pagination is True | ||
| assert stream.selected_by_default is False | ||
| assert stream.parent_stream_type is not None | ||
| assert stream.parent_stream_type.__name__ == "RepositoryStream" | ||
| assert "dependency" in stream.schema["properties"] | ||
| assert "security_advisory" in stream.schema["properties"] | ||
| assert "security_vulnerability" in stream.schema["properties"] | ||
| assert "dependabot_alerts" in TapGitHub(config=repo_list_config).streams | ||
|
|
||
|
|
||
| def test_dependabot_alerts_stream_tolerates_unavailable_alerts_permission( | ||
| repo_list_config, # noqa: F811 | ||
| ): | ||
| """Do not fail a sync when the token cannot access Dependabot alerts.""" | ||
| stream = DependabotAlertsStream(TapGitHub(config=repo_list_config)) | ||
| response = Response() | ||
| response.status_code = 403 | ||
| response.url = ( | ||
| "https://api.github.com/repos/MeltanoLabs/tap-github/dependabot/alerts" | ||
| ) | ||
| response.reason = "Forbidden" | ||
| response._content = b'{"message": "Resource not accessible"}' | ||
|
|
||
| stream.validate_response(response) | ||
|
|
||
| assert stream.tolerated_http_errors == [404, 403] | ||
| assert list(stream.parse_response(response)) == [] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("message", "is_primary_rate_limit"), | ||
| [ | ||
| ("API rate limit exceeded", True), | ||
| ("You have exceeded a secondary rate limit", False), | ||
| ], | ||
| ) | ||
| def test_dependabot_alerts_stream_retries_rate_limits( | ||
| repo_list_config, # noqa: F811 | ||
| message, | ||
| is_primary_rate_limit, | ||
| ): | ||
| """Retry rate-limit 403s even though permission-denied 403s are tolerated.""" | ||
| stream = DependabotAlertsStream(TapGitHub(config=repo_list_config)) | ||
| response = Response() | ||
| response.status_code = 403 | ||
| response.url = ( | ||
| "https://api.github.com/repos/MeltanoLabs/tap-github/dependabot/alerts" | ||
| ) | ||
| response.reason = "Forbidden" | ||
| response._content = f'{{"message": "{message}"}}'.encode() | ||
|
|
||
| with ( | ||
| patch.object(stream.authenticator, "get_next_auth_token") as rotate_token, | ||
| patch("tap_github.client.time.sleep") as sleep, | ||
| pytest.raises(RetriableAPIError, match="403 Client Error"), | ||
| ): | ||
| stream.validate_response(response) | ||
|
|
||
| if is_primary_rate_limit: | ||
| rotate_token.assert_called_once_with() | ||
| sleep.assert_not_called() | ||
| else: | ||
| rotate_token.assert_not_called() | ||
| sleep.assert_called_once() | ||
|
|
||
|
|
||
| def test_dependabot_alerts_stream_requests_updated_alerts_descending(repo_list_config): # noqa: F811 | ||
| """Ensure pagination can stop after the saved incremental bookmark.""" | ||
| stream = DependabotAlertsStream(TapGitHub(config=repo_list_config)) | ||
|
|
||
| params = stream.get_url_params( | ||
| {"org": "MeltanoLabs", "repo": "tap-github", "repo_id": 365087920}, | ||
| None, | ||
| ) | ||
|
|
||
| assert params["sort"] == "updated" | ||
| assert params["direction"] == "desc" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied in 343a0f7. The stream now tolerates 404/403 responses and the regression test verifies that a missing Dependabot-alerts permission completes without records.\n\nValidated with
uv run pytest tests/test_dependabot_alerts.py, Ruff check/format, mypy, and ty.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Actually... could this swallow a
403that is in fact a rate-limit, which should be retried?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed and fixed in 34d74c7. The REST client now lets primary and secondary rate-limit 403s reach the existing retry logic before considering a status tolerated; non-rate-limit 403s and 404s remain tolerated for this stream.\n\nAdded regression coverage for both rate-limit responses plus the missing-permission case. Validated with
uv run pytest tests/test_dependabot_alerts.py, Ruff check/format, mypy, and ty.