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

fix: parse out jinja2 when updating the team #803

Merged
merged 2 commits into from
Dec 15, 2024
Merged
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
51 changes: 51 additions & 0 deletions conda_forge_webservices/tests/test_update_teams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from conda_forge_webservices.update_teams import get_recipe_dummy_meta

import pytest


@pytest.mark.parametrize(
"recipe_content, res",
[
(
"""\
{% set version = "0.1" %}

blah: five

extra:
recipe-maintainers:
- a
- b
- c
""",
{"a", "b", "c"},
),
(
"""\
{% set version = "0.1" %}

extra:
feedstock-name: {{ name }}
recipe-maintainers:
- a
- b
""",
{"a", "b"},
),
(
"""\
{% set version = "0.1" %}

extra:
feedstock-name: ${{ name }}
recipe-maintainers:
- a
- d
""",
{"a", "d"},
),
],
)
def test_get_recipe_dummy_meta(recipe_content, res):
meta = get_recipe_dummy_meta(recipe_content)
assert set(meta.meta["extra"]["recipe-maintainers"]) == res
33 changes: 24 additions & 9 deletions conda_forge_webservices/update_teams.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import github
import os
import re
import logging

from conda_smithy.github import configure_github_team
Expand All @@ -11,6 +12,16 @@

LOGGER = logging.getLogger("conda_forge_webservices.update_teams")

JINJA_PAT = re.compile(r"\{\{([^\{\}]*)\}\}")


def _jinja2_repl(match):
return "${{" + match.group(1) + "}}"


def _filter_jinja2(line):
return JINJA_PAT.sub(_jinja2_repl, line)


@cache
def get_filter_out_members():
Expand Down Expand Up @@ -52,6 +63,18 @@ def get_recipe_contents(gh_repo):
return resp.decoded_content.decode("utf-8")


def get_recipe_dummy_meta(recipe_content):
keep_lines = []
skip = 0
for line in recipe_content.splitlines():
if line.strip().startswith("extra:"):
skip += 1
if skip > 0:
keep_lines.append(_filter_jinja2(line))
assert skip == 1, "team update failed due to > 1 'extra:' sections"
return DummyMeta("\n".join(keep_lines))


def update_team(org_name, repo_name, commit=None):
if not repo_name.endswith("-feedstock"):
return
Expand All @@ -71,15 +94,7 @@ def update_team(org_name, repo_name, commit=None):
gh_repo = org.get_repo(repo_name)

recipe_content = get_recipe_contents(gh_repo)
keep_lines = []
skip = 0
for line in recipe_content.splitlines():
if line.strip().startswith("extra:"):
skip += 1
if skip > 0:
keep_lines.append(line)
assert skip == 1, "team update failed due to > 1 'extra:' sections"
meta = DummyMeta("\n".join(keep_lines))
meta = get_recipe_dummy_meta(recipe_content)

(
current_maintainers,
Expand Down
Loading