Skip to content

Commit cfb4598

Browse files
committed
landing_worker: delete patch content after landing (bug 1879536)
- delete patch content after landing - add one-time cli command to do this for previously landed jobs - update tests to reflect new behaviour
1 parent fb22533 commit cfb4598

File tree

3 files changed

+58
-32
lines changed

3 files changed

+58
-32
lines changed

landoapi/cli.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ def run_post_deploy_sequence():
107107
)
108108

109109

110+
@cli.command(name="clean-landing-job-patches")
111+
def clean_landing_job_patches():
112+
"""Iterate over all landed jobs and delete their patches."""
113+
from landoapi.models.landing_job import LandingJob, LandingJobStatus
114+
from landoapi.storage import db, db_subsystem
115+
116+
db_subsystem.ensure_ready()
117+
jobs = LandingJob.query.filter(LandingJob.status == LandingJobStatus.LANDED).all()
118+
for job in jobs:
119+
for revision in job.revisions:
120+
revision.patch_bytes = b""
121+
db.session.commit()
122+
123+
110124
@cli.command(context_settings={"ignore_unknown_options": True})
111125
@click.argument("celery_arguments", nargs=-1, type=click.UNPROCESSED)
112126
def celery(celery_arguments):

landoapi/workers/landing_worker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,11 @@ def run_job(
439439
LandingJobAction.LAND, commit_id=commit_id, commit=True, db=db
440440
)
441441

442+
# Patches are no longer necessary, delete them.
443+
for revision in job.revisions:
444+
revision.patch_bytes = b""
445+
db.session.commit()
446+
442447
mots_path = Path(hgrepo.path) / "mots.yaml"
443448
if mots_path.exists():
444449
logger.info(f"{mots_path} found, setting reviewer data.")

tests/test_try.py

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,23 @@ def test_try_api_success_hgexport(
245245
worker = LandingWorker(sleep_seconds=0.01)
246246
hgrepo = HgRepo(hg_clone.strpath)
247247

248+
assert len(job.revisions) == 1, "Job should be landing a single revision."
249+
revision = job.revisions[0]
250+
assert revision.patch_bytes == (
251+
b"# HG changeset patch\n"
252+
b"# User Test User <test@example.com>\n"
253+
b"# Date 0 +0000\n"
254+
b"# Diff Start Line 6\n"
255+
b"add another file.\n"
256+
b"\n"
257+
b"diff --git a/test.txt b/test.txt\n"
258+
b"--- a/test.txt\n"
259+
b"+++ b/test.txt\n"
260+
b"@@ -1,1 +1,2 @@\n"
261+
b" TEST\n"
262+
b"+adding another line"
263+
), "Patch diff should be parsed from patch body."
264+
248265
assert worker.run_job(job, repo, hgrepo, treestatus)
249266
assert job.status == LandingJobStatus.LANDED
250267
assert len(job.landed_commit_id) == 40
@@ -267,20 +284,7 @@ def test_try_api_success_hgexport(
267284
assert (
268285
revision.patch_data["timestamp"] == "0"
269286
), "Timestamp should be parsed from `Date` header."
270-
assert revision.patch_bytes == (
271-
b"# HG changeset patch\n"
272-
b"# User Test User <test@example.com>\n"
273-
b"# Date 0 +0000\n"
274-
b"# Diff Start Line 6\n"
275-
b"add another file.\n"
276-
b"\n"
277-
b"diff --git a/test.txt b/test.txt\n"
278-
b"--- a/test.txt\n"
279-
b"+++ b/test.txt\n"
280-
b"@@ -1,1 +1,2 @@\n"
281-
b" TEST\n"
282-
b"+adding another line"
283-
), "Patch diff should be parsed from patch body."
287+
assert revision.patch_bytes == b"", "Patch diff should be cleared after landing."
284288

285289

286290
def test_try_api_success_gitformatpatch(
@@ -334,6 +338,26 @@ def test_try_api_success_gitformatpatch(
334338
worker = LandingWorker(sleep_seconds=0.01)
335339
hgrepo = HgRepo(hg_clone.strpath)
336340

341+
assert len(job.revisions) == 1, "Job should be landing a single revision."
342+
revision = job.revisions[0]
343+
344+
assert revision.patch_bytes == (
345+
b"# HG changeset patch\n"
346+
b"# User Connor Sheehan <sheehan@mozilla.com>\n"
347+
b"# Date 1657139769 +0000\n"
348+
b"# Diff Start Line 8\n"
349+
b"add another file\n"
350+
b"\n"
351+
b"add another file to the repo.\n"
352+
b"\n"
353+
b"diff --git a/test.txt b/test.txt\n"
354+
b"--- a/test.txt\n"
355+
b"+++ b/test.txt\n"
356+
b"@@ -1,1 +1,2 @@\n"
357+
b" TEST\n"
358+
b"+adding another line"
359+
), "Patch diff should be parsed from patch body."
360+
337361
# Assert the job landed against the expected commit hash.
338362
assert worker.run_job(job, repo, hgrepo, treestatus)
339363
assert job.status == LandingJobStatus.LANDED
@@ -343,8 +367,6 @@ def test_try_api_success_gitformatpatch(
343367
), "Target changeset should match the passed value."
344368

345369
# Test the revision content matches expected.
346-
assert len(job.revisions) == 1, "Job should have landed a single revision."
347-
revision = job.revisions[0]
348370
assert (
349371
revision.patch_data["author_name"] == "Connor Sheehan"
350372
), "Patch author should be parsed from `From` header."
@@ -357,19 +379,4 @@ def test_try_api_success_gitformatpatch(
357379
assert (
358380
revision.patch_data["timestamp"] == "1657139769"
359381
), "Timestamp should be parsed from `Date` header."
360-
assert revision.patch_bytes == (
361-
b"# HG changeset patch\n"
362-
b"# User Connor Sheehan <sheehan@mozilla.com>\n"
363-
b"# Date 1657139769 +0000\n"
364-
b"# Diff Start Line 8\n"
365-
b"add another file\n"
366-
b"\n"
367-
b"add another file to the repo.\n"
368-
b"\n"
369-
b"diff --git a/test.txt b/test.txt\n"
370-
b"--- a/test.txt\n"
371-
b"+++ b/test.txt\n"
372-
b"@@ -1,1 +1,2 @@\n"
373-
b" TEST\n"
374-
b"+adding another line"
375-
), "Patch diff should be parsed from patch body."
382+
assert revision.patch_bytes == b"", "Patch diff should be cleared after landing."

0 commit comments

Comments
 (0)