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: update a PR with everything or nothing #3400

Merged
merged 1 commit into from
Dec 13, 2024
Merged
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
79 changes: 34 additions & 45 deletions conda_forge_tick/update_prs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,35 @@
KEEP_PR_FRACTION = 0.5


def _combined_update_function(pr_json: dict, dry_run: bool) -> dict:
return_it = False

Check warning on line 34 in conda_forge_tick/update_prs.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/update_prs.py#L34

Added line #L34 was not covered by tests

pr_data = refresh_pr(pr_json, dry_run=dry_run)
if pr_data is not None:
return_it = True
pr_json.update(pr_data)

Check warning on line 39 in conda_forge_tick/update_prs.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/update_prs.py#L36-L39

Added lines #L36 - L39 were not covered by tests

pr_data = close_out_labels(pr_json, dry_run=dry_run)
if pr_data is not None:
return_it = True
pr_json.update(pr_data)

Check warning on line 44 in conda_forge_tick/update_prs.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/update_prs.py#L41-L44

Added lines #L41 - L44 were not covered by tests

pr_data = refresh_pr(pr_json, dry_run=dry_run)
if pr_data is not None:
return_it = True
pr_json.update(pr_data)

Check warning on line 49 in conda_forge_tick/update_prs.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/update_prs.py#L46-L49

Added lines #L46 - L49 were not covered by tests

pr_data = close_out_dirty_prs(pr_json, dry_run=dry_run)
if pr_data is not None:
return_it = True
pr_json.update(pr_data)

Check warning on line 54 in conda_forge_tick/update_prs.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/update_prs.py#L51-L54

Added lines #L51 - L54 were not covered by tests

if return_it:
return pr_json

Check warning on line 57 in conda_forge_tick/update_prs.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/update_prs.py#L56-L57

Added lines #L56 - L57 were not covered by tests
else:
return None

Check warning on line 59 in conda_forge_tick/update_prs.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/update_prs.py#L59

Added line #L59 was not covered by tests


def _update_pr(update_function, dry_run, gx, job, n_jobs):
failed_refresh = 0
succeeded_refresh = 0
Expand Down Expand Up @@ -112,61 +141,21 @@
return succeeded_refresh, failed_refresh


def update_graph_pr_status(
gx: nx.DiGraph,
dry_run: bool = False,
job=1,
n_jobs=1,
) -> nx.DiGraph:
succeeded_refresh, failed_refresh = _update_pr(refresh_pr, dry_run, gx, job, n_jobs)

logger.info(f"JSON Refresh failed for {failed_refresh} PRs")
logger.info(f"JSON Refresh succeed for {succeeded_refresh} PRs")
return gx


def close_labels(
gx: nx.DiGraph,
dry_run: bool = False,
job=1,
n_jobs=1,
) -> nx.DiGraph:
succeeded_refresh, failed_refresh = _update_pr(
close_out_labels,
dry_run,
gx,
job,
n_jobs,
)

logger.info(f"bot re-run failed for {failed_refresh} PRs")
logger.info(f"bot re-run succeed for {succeeded_refresh} PRs")
return gx


def close_dirty_prs(
def update_pr_combined(
gx: nx.DiGraph,
dry_run: bool = False,
job=1,
n_jobs=1,
) -> nx.DiGraph:
succeeded_refresh, failed_refresh = _update_pr(
close_out_dirty_prs,
dry_run,
gx,
job,
n_jobs,
_combined_update_function, dry_run, gx, job, n_jobs
)

logger.info(f"close dirty PRs failed for {failed_refresh} PRs")
logger.info(f"close dirty PRs succeed for {succeeded_refresh} PRs")
logger.info(f"JSON Refresh failed for {failed_refresh} PRs")
logger.info(f"JSON Refresh succeed for {succeeded_refresh} PRs")

Check warning on line 155 in conda_forge_tick/update_prs.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/update_prs.py#L154-L155

Added lines #L154 - L155 were not covered by tests
return gx


def main(ctx: CliContext, job: int = 1, n_jobs: int = 1) -> None:
gx = load_existing_graph()

gx = close_labels(gx, ctx.dry_run, job=job, n_jobs=n_jobs)
gx = update_graph_pr_status(gx, ctx.dry_run, job=job, n_jobs=n_jobs)
# This function needs to run last since it edits the actual pr json!
gx = close_dirty_prs(gx, ctx.dry_run, job=job, n_jobs=n_jobs)
update_pr_combined(gx, ctx.dry_run, job=job, n_jobs=n_jobs)

Check warning on line 161 in conda_forge_tick/update_prs.py

View check run for this annotation

Codecov / codecov/patch

conda_forge_tick/update_prs.py#L161

Added line #L161 was not covered by tests
Loading