Skip to content

Commit bac1509

Browse files
committed
revisions: add revision worker and mots integration (bug 1740107)
This is a work in progress, do not merge! - add new command (lando-cli revision-worker) to start new worker - add new `revision-worker` that pre-processes revisions - add method to parse diff and list affected files (should move to mots) - store module output in revision model - add mots to requirements file - include revision info via API endpoint - create abstract Worker class, use asyncio (bug 1744327) - add phab integrations and proper loop/process functionality - run pre/post mots query - check mots hashes - refactored revision worker and landing worker - implement stack hashes - functional multi edge search - working mots implementation - remove s3/boto/etc. dependencies - add patch caching - add many to many fields + association to revisions/landing jobs - fix or temporarily mark tests as xfail (see TODOs) - create /patches volume in Dockerfiles
1 parent 47cc26e commit bac1509

35 files changed

+2024
-1331
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[flake8]
22
max-line-length = 88
33
select = C,E,F,W,B,B9
4-
ignore = E203, E501, W503, B006
4+
ignore = E203, E501, W503, B006, E712, E711
55
exclude =
66
.hg,
77
.git,

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ __pycache__
66
*.pyc
77
/.db/
88
/.vscode
9+
notes

.hgrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[ui]
2+
username=lando<lando@lando.test>

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ RUN chown -R app:app /app
5252

5353
# Create repos directory for transplanting in landing-worker
5454
RUN mkdir /repos
55+
RUN chown -R app:app /repos
56+
57+
RUN mkdir /patches
58+
RUN chown -R app:app /patches
59+
60+
RUN echo "[ui]" > /root/.hgrc
61+
RUN echo "username = revision worker <revision_worker@lando.test>" >> /root/.hgrc
5562

5663
# Run as a non-privileged user
5764
USER app

Dockerfile-dev

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ENV PYTHONUNBUFFERED=1
1111
ENV FLASK_RUN_PORT=9000
1212
ENV FLASK_RUN_HOST=0.0.0.0
1313
ENV FLASK_DEBUG=1
14+
ENV HTTP_ALLOWED=1
1415

1516
ENTRYPOINT ["lando-cli"]
1617
CMD ["run"]
@@ -42,7 +43,15 @@ RUN chown -R app:app /app
4243
RUN mkdir /repos
4344
RUN chown -R app:app /repos
4445

46+
RUN mkdir /patches
47+
RUN chown -R app:app /patches
48+
49+
RUN echo "[ui]" > /root/.hgrc
50+
RUN echo "username = revision worker <revision_worker@lando.test>" >> /root/.hgrc
51+
4552
# Run as a non-privileged user
4653
USER app
4754

55+
# RUN 'echo -e "api-lefsv24henzsbzpw337bhizawuyh\n" | moz-phab install-certificate'
56+
4857
WORKDIR /app

landoapi/api/landing_jobs.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from landoapi import auth
1212
from landoapi.models.landing_job import LandingJob, LandingJobStatus, LandingJobAction
13+
from landoapi.models.revisions import RevisionStatus
1314
from landoapi.storage import db
1415

1516
logger = logging.getLogger(__name__)
@@ -63,6 +64,8 @@ def put(landing_job_id, data):
6364

6465
if landing_job.status in (LandingJobStatus.SUBMITTED, LandingJobStatus.DEFERRED):
6566
landing_job.transition_status(LandingJobAction.CANCEL)
67+
for revision in landing_job.get_revisions():
68+
revision.status = RevisionStatus.STALE
6669
db.session.commit()
6770
return {"id": landing_job.id}, 200
6871
else:

landoapi/api/revisions.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from landoapi import auth
1111
from landoapi.decorators import require_phabricator_api_key
1212
from landoapi.models import SecApprovalRequest
13+
from landoapi.models.revisions import Revision, RevisionStatus
1314
from landoapi.projects import get_secure_project_phid
1415
from landoapi.revisions import revision_is_secure
1516
from landoapi.secapproval import send_sanitized_commit_message_for_review
@@ -90,3 +91,40 @@ def request_sec_approval(data=None):
9091
db.session.commit()
9192

9293
return {}, 200
94+
95+
96+
@require_phabricator_api_key(optional=True)
97+
def process(revision_id, diff_id, target_phid):
98+
revision = Revision.query.filter(
99+
Revision.revision_id == revision_id,
100+
).one_or_none()
101+
if revision:
102+
# Update with target phid and mark revision as stale.
103+
if revision.diff_id != diff_id:
104+
logger.info(
105+
f"diff_id changed for revision "
106+
f"{revision.revision_id} {revision.diff_id} -> {diff_id}"
107+
)
108+
revision.diff_id = diff_id
109+
revision.target = target_phid
110+
revision.status = RevisionStatus.STALE
111+
else:
112+
# Create a new revision and add all relevant info.
113+
revision = Revision(
114+
revision_id=revision_id,
115+
diff_id=diff_id,
116+
target=target_phid,
117+
status=RevisionStatus.NEW,
118+
)
119+
db.session.add(revision)
120+
logger.info(
121+
f"Revision {revision.revision_id} added with diff_id {revision.diff_id}"
122+
)
123+
db.session.commit()
124+
125+
126+
def get_stack_hashes(revision_id):
127+
revision = Revision.query.filter(Revision.id == revision_id).one_or_none()
128+
if revision:
129+
return revision.stack_hashes, 200
130+
return {}, 404

landoapi/api/stacks.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from flask import current_app, g
99
from landoapi.commit_message import format_commit_message
1010
from landoapi.decorators import require_phabricator_api_key
11+
from landoapi.models.revisions import Revision
1112
from landoapi.phabricator import PhabricatorClient, PhabricatorAPIException
1213
from landoapi.projects import (
1314
get_sec_approval_project_phid,
@@ -112,6 +113,9 @@ def get(revision_id):
112113

113114
revisions_response = []
114115
for _phid, revision in stack_data.revisions.items():
116+
lando_revision = Revision.query.filter(
117+
Revision.revision_id == revision["id"]
118+
).one_or_none()
115119
revision_phid = PhabricatorClient.expect(revision, "phid")
116120
fields = PhabricatorClient.expect(revision, "fields")
117121
diff_phid = PhabricatorClient.expect(fields, "diffPHID")
@@ -179,6 +183,9 @@ def get(revision_id):
179183
"reviewers": serialize_reviewers(reviewers, users, projects, diff_phid),
180184
"is_secure": secure,
181185
"is_using_secure_commit_message": commit_description.sanitized,
186+
"lando_revision": lando_revision.serialize()
187+
if lando_revision
188+
else None,
182189
}
183190
)
184191

0 commit comments

Comments
 (0)