Skip to content
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

Consider articles outdated if their front matter contains outdated: true #10

Closed
wants to merge 2 commits into from
Closed
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
30 changes: 30 additions & 0 deletions tests/test_check_outdated_articles.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,36 @@ def test__list_outdated_translations(self, root):

assert multiset(translations_to_outdate) == multiset(utils.remove(article_paths, "en.md"))

def test__list_outdated_translations__no_specific_hash(self, root):
utils.set_up_dummy_repo()
article_paths = [
'wiki/Article/en.md',
'wiki/Article/fr.md',
'wiki/Article/pt-br.md',
'wiki/Article/zh-tw.md',
]

utils.create_files(root, *((path, '# Article') for path in article_paths[:-1]))

zh_tw_contents = textwrap.dedent("""
---
outdated: true
---

# Article
""")
utils.create_files(root, (article_paths[-1], zh_tw_contents))
utils.stage_all_and_commit("add some articles")

utils.create_files(root, (article_paths[0], '# Article\n\nThis is an article in English.'))
utils.stage_all_and_commit("add english article content")
translations_to_outdate = list(outdater.list_outdated_translations(
set(utils.remove(article_paths, "en.md")),
set()
))

assert multiset(translations_to_outdate) == multiset(utils.remove(article_paths, "en.md", "zh-tw.md"))

def test__outdate_translations(self, root):
utils.set_up_dummy_repo()
article_paths = [
Expand Down
9 changes: 8 additions & 1 deletion wikitools_cli/commands/check_outdated_articles.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
# The front matter tag which contains the commit hash since which the translation is not up to date
OUTDATED_HASH_TAG = "outdated_since"

# The front matter tag which shows that the article is outdated since some unknown moment of time
OUTDATED_TAG = "outdated"

# The script flag which will automatically outdate translations
AUTOFIX_FLAG = "--autofix"
AUTOFIX_FLAG_SHORT = "-f"
Expand Down Expand Up @@ -90,7 +93,11 @@ def list_outdated_translations(all_translations, modified_translations):

with open(article_file, "r", encoding='utf-8') as fd:
front_matter = article_parser.load_front_matter(fd)
if OUTDATED_HASH_TAG in front_matter or front_matter.get(OUTDATED_TRANSLATION_TAG, False):
if (
OUTDATED_HASH_TAG in front_matter or
front_matter.get(OUTDATED_TRANSLATION_TAG, False) or
front_matter.get(OUTDATED_TAG, False)
):
continue

yield article_file
Expand Down