-
Notifications
You must be signed in to change notification settings - Fork 6
feat: daily digest of contributor pull requests #59
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ae60e0d
feat: daily digest of contributor pull requests
Bilb bf09585
fix: split a repository block that outgrows a Discord message
Bilb d3ce603
fix: never report private repositories, and stop naming excluded repo…
Bilb 4fef646
refactor: drop the flags that widened which repositories the digest r…
Bilb ca8a885
Merge remote-tracking branch 'origin/main' into feat/contributor-pr-d…
Bilb b34c5fe
fix: name the CLI's reason when a zero exit still reports is_error
Bilb b9fa5d4
refactor: move the retry, Discord transport, dedup state and env help…
Bilb 8d67302
refactor: build the pull request digest on the shared helpers
Bilb 2b4c699
feat: let the shared retry read an HTTP-date Retry-After and take a t…
Bilb 36702d3
refactor: post the Crowdin report through the shared retry and webhoo…
Bilb 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| """ | ||
| cd crowdin && python -m unittest discover | ||
| """ | ||
| import contextlib | ||
| import io | ||
| import os | ||
| import sys | ||
| import unittest | ||
|
|
||
| import requests | ||
|
|
||
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | ||
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
| import report_multiple_translations as report # noqa: E402 | ||
| from shared.testing import FakeResponse, FakeSession, NoSleep, Patched # noqa: E402 | ||
|
|
||
|
|
||
| class ApiResponse(FakeResponse): | ||
| def raise_for_status(self): | ||
| if self.status_code >= 400: | ||
| raise requests.HTTPError(f"{self.status_code}", response=self) | ||
|
|
||
|
|
||
| class WebhookSession(FakeSession): | ||
| def __enter__(self): | ||
| return self | ||
|
|
||
| def __exit__(self, *exc): | ||
| return False | ||
|
|
||
|
|
||
| class TestRequestWithRetry(unittest.TestCase): | ||
| def test_a_client_error_raises_rather_than_returning(self): | ||
| """Callers read the body straight off the response, so a 4xx has to stop them.""" | ||
| with self.assertRaises(requests.HTTPError): | ||
| report.request_with_retry(FakeSession([ApiResponse({}, status_code=404)]), | ||
| "GET", "https://x") | ||
|
|
||
| def test_crowdins_budget_is_ten_attempts_at_sixty_seconds(self): | ||
| session = FakeSession([ApiResponse({}, status_code=503)] * 9 + [ApiResponse({"ok": 1})]) | ||
| with NoSleep(): | ||
| self.assertEqual(report.request_with_retry(session, "GET", "https://x").json(), {"ok": 1}) | ||
| self.assertEqual(len(session.calls), 10) | ||
| self.assertEqual({kw["timeout"] for _, _, kw in session.calls}, {60}) | ||
|
|
||
|
|
||
| class TestPostToDiscord(unittest.TestCase): | ||
| def post(self, responses, messages): | ||
| session = WebhookSession(responses) | ||
| with Patched(report.requests, Session=lambda: session), \ | ||
| contextlib.redirect_stdout(io.StringIO()): | ||
| report.post_to_discord("https://hook", messages) | ||
| return session | ||
|
|
||
| def test_every_message_accepted_posts_nothing_else(self): | ||
| session = self.post([FakeResponse({}, status_code=204)] * 2, [{"embeds": []}] * 2) | ||
| self.assertEqual(len(session.calls), 2) | ||
|
|
||
| def test_a_rejection_posts_a_plain_warning_then_exits(self): | ||
| responses = [FakeResponse({}, status_code=204), FakeResponse({}, status_code=400), | ||
| FakeResponse({}, status_code=204)] | ||
| with self.assertRaises(SystemExit) as caught: | ||
| self.post(responses, [{"embeds": []}] * 3) | ||
| self.assertIn("1 of 3", str(caught.exception)) | ||
|
|
||
| def test_the_warning_is_plain_content_the_webhook_cannot_reject_for_size(self): | ||
| session = WebhookSession([FakeResponse({}, status_code=400), FakeResponse({}, status_code=204)]) | ||
| with Patched(report.requests, Session=lambda: session), \ | ||
| contextlib.redirect_stdout(io.StringIO()), self.assertRaises(SystemExit): | ||
| report.post_to_discord("https://hook", [{"embeds": [{"title": "x" * 9000}]}]) | ||
| self.assertEqual(list(session.calls[1][2]["json"]), ["content"]) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Oops, something went wrong.
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.
don't use real users here, or use Bilb