-
Notifications
You must be signed in to change notification settings - Fork 0
Gate stale translations on the change, not the whole repository #16
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,140 @@ | ||
| """--since: gate on the staleness this change caused, not the repository's. | ||
|
|
||
| Without it the gate reads the whole repository, so one edit to an English page | ||
| cannot go green without every translation of it in the same change, and a page | ||
| someone left behind last month reddens a pull request that touched no | ||
| documentation at all. | ||
|
|
||
| --since narrows *stale* to the English pages that changed against a ref. | ||
| missing, unstamped and orphaned stay absolute: they are structural, and none of | ||
| them asks the author for translation work their change did not create. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from conftest import DocsRepo | ||
|
|
||
| from halos_docs_tools import translation_status | ||
|
|
||
|
|
||
| def run(*argv: str) -> int: | ||
| return translation_status.main(list(argv)) | ||
|
|
||
|
|
||
| def test_a_page_this_change_did_not_touch_does_not_fail(docs_repo: DocsRepo): | ||
| docs_repo.source("other.md") | ||
| docs_repo.translation("fi", "other.md") | ||
| docs_repo.translation("sv", "other.md") | ||
| base = docs_repo.commit() | ||
|
|
||
| # Someone else's page went stale earlier; this change edits nothing. | ||
| docs_repo.source("other.md", "# Title\n\nEdited without translating.\n") | ||
| docs_repo.commit() | ||
| stale_base = docs_repo.git("rev-parse", "HEAD") | ||
|
|
||
| docs_repo.write("unrelated.txt", "not documentation\n") | ||
|
|
||
| assert run("--check") == 1 | ||
| assert run("--check", "--since", stale_base) == 0 | ||
| assert base # the earlier state is what stale_base was measured against | ||
|
|
||
|
|
||
| def test_a_page_this_change_edited_still_fails(docs_repo: DocsRepo): | ||
| base = docs_repo.commit() | ||
| docs_repo.source("index.md", "# Title\n\nEdited in this change.\n") | ||
|
|
||
| assert run("--check", "--since", base) == 1 | ||
|
|
||
|
|
||
| def test_a_missing_translation_fails_however_old(docs_repo: DocsRepo): | ||
| docs_repo.source("lonely.md") | ||
| base = docs_repo.commit() | ||
| docs_repo.write("unrelated.txt", "not documentation\n") | ||
|
|
||
| assert run("--check", "--since", base) == 1 | ||
|
|
||
|
|
||
| def test_an_unstamped_translation_fails_however_old(docs_repo: DocsRepo): | ||
| docs_repo.translation("fi", "index.md", stamp=None) | ||
| base = docs_repo.commit() | ||
| docs_repo.write("unrelated.txt", "not documentation\n") | ||
|
|
||
| assert run("--check", "--since", base) == 1 | ||
|
|
||
|
|
||
| def test_an_orphaned_translation_fails_however_old(docs_repo: DocsRepo): | ||
| # An orphan has no English source left, so it cannot be stamped from one. | ||
| docs_repo.translation("fi", "gone.md", stamp="0" * 40) | ||
| base = docs_repo.commit() | ||
| docs_repo.write("unrelated.txt", "not documentation\n") | ||
|
|
||
| assert run("--check", "--since", base) == 1 | ||
|
|
||
|
|
||
| def test_what_was_not_gated_on_is_stated(docs_repo: DocsRepo, capsys): | ||
| docs_repo.source("other.md") | ||
| docs_repo.translation("fi", "other.md") | ||
| docs_repo.translation("sv", "other.md") | ||
| docs_repo.source("other.md", "# Title\n\nEdited without translating.\n") | ||
| base = docs_repo.commit() | ||
|
|
||
| assert run("--check", "--since", base) == 0 | ||
| out = capsys.readouterr().out | ||
| assert "other.md" in out | ||
| # A green run that quietly forgave two stale translations reads exactly | ||
| # like a repository with none. | ||
| assert "2" in out and "not gated on" in out | ||
|
|
||
|
|
||
| def test_a_ref_that_does_not_resolve_is_not_a_pass(docs_repo: DocsRepo, capsys): | ||
| docs_repo.source("index.md", "# Title\n\nEdited in this change.\n") | ||
|
|
||
| assert run("--check", "--since", "no-such-ref") == 2 | ||
| assert "no-such-ref" in capsys.readouterr().out | ||
|
|
||
|
|
||
| def test_since_on_a_plain_report_is_refused(docs_repo: DocsRepo, capsys): | ||
| # The report shows everything by design, so --since would change nothing. | ||
| # Silently inert is worse: the caller believes it scoped something. | ||
| assert run("--since", "HEAD") == 2 | ||
| out = capsys.readouterr().out | ||
| assert "--check" in out and "--comment" in out | ||
|
|
||
|
|
||
| def test_the_comment_omits_what_the_gate_excused(docs_repo: DocsRepo, capsys): | ||
| """The comment body is the verdict, so it must agree with the verdict. | ||
|
|
||
| render_comment covers every entry the gate fails on. Under --since the gate | ||
| fails on fewer, and a comment naming a page the run passed on sends its | ||
| author to translate something nobody asked them for. | ||
| """ | ||
| docs_repo.source("stale-already.md") | ||
| docs_repo.translation("fi", "stale-already.md") | ||
| docs_repo.translation("sv", "stale-already.md") | ||
| docs_repo.source("stale-already.md", "# Title\n\nEdited without translating.\n") | ||
| base = docs_repo.commit() | ||
|
|
||
| assert run("--comment", "--check", "--since", base) == 0 | ||
| body = capsys.readouterr().out | ||
| assert "stale-already.md" not in body | ||
| assert "not gated on" not in body | ||
|
|
||
|
|
||
| def test_the_comment_can_be_scoped_without_gating(docs_repo: DocsRepo, capsys): | ||
| """The workflow's comment step wants the scope, not the exit status.""" | ||
| docs_repo.source("stale-already.md") | ||
| docs_repo.translation("fi", "stale-already.md") | ||
| docs_repo.translation("sv", "stale-already.md") | ||
| docs_repo.source("stale-already.md", "# Title\n\nEdited without translating.\n") | ||
| base = docs_repo.commit() | ||
|
|
||
| assert run("--comment", "--since", base) == 0 | ||
| assert "stale-already.md" not in capsys.readouterr().out | ||
|
|
||
|
|
||
| def test_the_comment_still_names_what_this_change_broke(docs_repo: DocsRepo, capsys): | ||
| base = docs_repo.commit() | ||
| docs_repo.source("index.md", "# Title\n\nEdited in this change.\n") | ||
|
|
||
| assert run("--comment", "--check", "--since", base) == 1 | ||
| assert "index.md" in capsys.readouterr().out |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.