Skip to content

Commit 911fd58

Browse files
committed
Call source builder API when source code is provided
1 parent 7e8273c commit 911fd58

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

src/olympia/lib/settings_base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ def get_language_url_map():
833833
'olympia.scanners.tasks.run_customs': {'queue': 'devhub'},
834834
'olympia.scanners.tasks.run_narc_on_version': {'queue': 'devhub'},
835835
'olympia.scanners.tasks.run_yara': {'queue': 'devhub'},
836+
'olympia.versions.tasks.call_source_builder': {'queue': 'devhub'},
836837
'olympia.versions.tasks.soft_block_versions': {'queue': 'devhub'},
837838
# Crons.
838839
'olympia.addons.tasks.update_addon_average_daily_users': {'queue': 'cron'},
@@ -1557,3 +1558,7 @@ def read_only_mode(env):
15571558
SWAGGER_SCHEMA_FILE = path('schema.yml')
15581559

15591560
SWAGGER_UI_ENABLED = env('SWAGGER_UI_ENABLED', default=False) or TARGET != 'production'
1561+
1562+
# Source builder settings.
1563+
SOURCE_BUILDER_API_URL = env('SOURCE_BUILDER_API_URL', default=None)
1564+
SOURCE_BUILDER_API_TIMEOUT = 5 # seconds
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Generated by Django 4.2.26 on 2025-11-13 08:55
2+
3+
from django.db import migrations
4+
from olympia.core.db.migrations import CreateWaffleSwitch
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('versions', '0050_remove_versionreviewerflags_needs_human_review_by_mad'),
11+
]
12+
13+
operations = [CreateWaffleSwitch('enable-source-builder')]

src/olympia/versions/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,8 @@ def flag_if_sources_were_provided(self, user):
826826
from olympia.activity.utils import log_and_notify
827827
from olympia.reviewers.models import NeedsHumanReview
828828

829+
from .tasks import call_source_builder
830+
829831
if self.source:
830832
# Add Activity Log, notifying staff, relevant reviewers and
831833
# other authors of the add-on.
@@ -835,6 +837,9 @@ def flag_if_sources_were_provided(self, user):
835837
reason = NeedsHumanReview.REASONS.PENDING_REJECTION_SOURCES_PROVIDED
836838
NeedsHumanReview.objects.create(version=self, reason=reason)
837839

840+
if waffle.switch_is_active('enable-source-builder'):
841+
call_source_builder.delay(version_pk=self.pk)
842+
838843
@classmethod
839844
def transformer(cls, versions):
840845
"""Attach all the compatible apps and the file to the versions."""

src/olympia/versions/tasks.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from django.db import transaction
99
from django.template import loader
1010

11+
import requests
1112
from django_statsd.clients import statsd
1213
from PIL import Image
1314

@@ -24,6 +25,7 @@
2425
from olympia.files.utils import get_background_images
2526
from olympia.lib.crypto.tasks import duplicate_addon_version
2627
from olympia.reviewers.models import NeedsHumanReview
28+
from olympia.scanners.tasks import make_adapter_with_retry
2729
from olympia.users.models import UserProfile
2830
from olympia.users.utils import get_task_user
2931
from olympia.versions.compare import VersionString
@@ -416,3 +418,32 @@ def soft_block_versions(version_ids, reason=REASON_VERSION_DELETED, **kw):
416418
),
417419
overwrite_block_metadata=False,
418420
)
421+
422+
423+
@task
424+
def call_source_builder(version_pk):
425+
log.info('Calling source builder API for Version %s', version_pk)
426+
427+
try:
428+
version = Version.objects.get(pk=version_pk)
429+
430+
with requests.Session() as http:
431+
adapter = make_adapter_with_retry()
432+
http.mount('http://', adapter)
433+
http.mount('https://', adapter)
434+
435+
json_payload = {
436+
'addon_guid': version.addon.guid,
437+
'version': version.version,
438+
'download_source_url': '',
439+
'license_slug': version.license.slug,
440+
}
441+
http.post(
442+
url=settings.SOURCE_BUILDER_API_URL,
443+
json=json_payload,
444+
timeout=settings.SOURCE_BUILDER_API_TIMEOUT,
445+
)
446+
except Exception:
447+
log.exception(
448+
'Error while calling source builder API for Version %s.', version_pk
449+
)

0 commit comments

Comments
 (0)