Skip to content

Commit

Permalink
Merge pull request #704 from conda-forge/two-org-three-lint-args
Browse files Browse the repository at this point in the history
feat: handle per-recipe errors in linting
  • Loading branch information
beckermr authored Oct 1, 2024
2 parents e353a55 + ea09e0a commit 4c4c682
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
24 changes: 22 additions & 2 deletions conda_forge_webservices/github_actions_integration/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
)
from .api_sessions import create_api_sessions
from .rerendering import rerender
from .linting import make_lint_comment, build_and_make_lint_comment, set_pr_status
from .linting import (
make_lint_comment,
build_and_make_lint_comment,
set_pr_status,
get_recipes_for_linting,
)
from .version_updating import update_version, update_pr_title


Expand Down Expand Up @@ -144,7 +149,12 @@ def main_run_task(task, repo, pr_number, task_data_dir, requested_version):
elif task == "lint":
_pull_docker_image()
try:
lints, hints = lint_feedstock(feedstock_dir, use_container=True)
res = lint_feedstock(feedstock_dir, use_container=True)
if len(res) == 2:
lints, hints = res
errors = {}
else:
lints, hints, errors = res
lint_error = False
except Exception as err:
LOGGER.warning("LINTING ERROR: %s", repr(err))
Expand All @@ -156,6 +166,7 @@ def main_run_task(task, repo, pr_number, task_data_dir, requested_version):
task_data["task_results"]["lint_error"] = lint_error
task_data["task_results"]["lints"] = lints
task_data["task_results"]["hints"] = hints
task_data["task_results"]["errors"] = errors
else:
raise ValueError(f"Task `{task}` is not valid!")

Expand Down Expand Up @@ -395,6 +406,15 @@ def main_finalize_task(task_data_dir):
)
sys.exit(1)
elif task == "lint":
if task_results.get("errors"):
recipes_to_lint, _ = get_recipes_for_linting(
gh, gh_repo, pr.number, task_results["lints"], task_results["hints"]
)
if any(
task_results["errors"].get(rec, False) for rec in recipes_to_lint
):
task_results["lint_error"] = True

if task_results["lint_error"]:
_message = dedent_with_escaped_continue(
"""
Expand Down
38 changes: 23 additions & 15 deletions conda_forge_webservices/github_actions_integration/linting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
from .utils import dedent_with_escaped_continue


def get_recipes_for_linting(gh, repo, pr_id, lints, hints):
fnames = set(hints.keys()) | set(lints.keys())

if repo.name == "staged-recipes":
pr = repo.get_pull(pr_id)
recipes_to_lint = set(f.filename for f in pr.get_files())
recipes_to_lint = set(
fname
for fname in recipes_to_lint
if fname
not in ["recipes/example/meta.yaml", "recipes/example-v1/recipe.yaml"]
)
else:
recipes_to_lint = set(fnames)

return recipes_to_lint, fnames


def _is_mergeable(repo, pr_id):
mergeable = None
while mergeable is None:
Expand Down Expand Up @@ -92,25 +110,15 @@ def build_and_make_lint_comment(gh, repo, pr_id, lints, hints):
)
status = "merge_conflict"
else:
fnames = set(hints.keys()) | set(lints.keys())

if repo.name == "staged-recipes":
pr = repo.get_pull(pr_id)
recipes_to_lint = set(f.filename for f in pr.get_files())
recipes_to_lint = set(
fname
for fname in recipes_to_lint
if fname
not in ["recipes/example/meta.yaml", "recipes/example-v1/recipe.yaml"]
)
else:
recipes_to_lint = set(fnames)
recipes_to_lint, all_recipes = get_recipes_for_linting(
gh, repo, pr_id, lints, hints
)

linted_recipes = []
all_pass = True
messages = []
hints_found = False
for fname in fnames:
for fname in all_recipes:
if fname not in recipes_to_lint:
continue

Expand Down Expand Up @@ -167,7 +175,7 @@ def build_and_make_lint_comment(gh, repo, pr_id, lints, hints):
""".format("\n".join(messages)),
)

if not fnames:
if not all_recipes:
message = dedent_with_escaped_continue(
"""
Hi! This is the friendly automated conda-forge-linting service.
Expand Down

0 comments on commit 4c4c682

Please sign in to comment.