Skip to content

Commit 5731ef5

Browse files
committed
Fix importer & Split task CLI in two command lines
Fix bug in UI Signed-off-by: ziad hany <ziadhany2016@gmail.com>
1 parent ea47351 commit 5731ef5

File tree

5 files changed

+72
-67
lines changed

5 files changed

+72
-67
lines changed

fedcode/importer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ def run(self):
5454
if diff.a_path.startswith("."):
5555
continue
5656

57-
yaml_data_a_blob = (
57+
yaml_data_a_blob = dict(
5858
saneyaml.load(diff.a_blob.data_stream.read()) if diff.a_blob else None
5959
)
60-
yaml_data_b_blob = (
60+
yaml_data_b_blob = dict(
6161
saneyaml.load(diff.b_blob.data_stream.read()) if diff.b_blob else None
6262
)
6363

@@ -113,7 +113,7 @@ def vul_handler(change_type, repo_obj, yaml_data_a_blob, yaml_data_b_blob, a_pat
113113

114114
def pkg_handler(change_type, default_service, yaml_data_a_blob, yaml_data_b_blob):
115115
if change_type == "A":
116-
package = yaml_data_b_blob.get("package")
116+
package = yaml_data_b_blob.get("pacakge")
117117

118118
pkg, _ = Package.objects.get_or_create(purl=package, service=default_service)
119119

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# FederatedCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/nexB/federatedcode for support or download.
7+
# See https://aboutcode.org for more information about AboutCode.org OSS projects.
8+
#
9+
from django.core.management import BaseCommand
10+
11+
from fedcode.models import FederateRequest
12+
from fedcode.signatures import FEDERATEDCODE_PRIVATE_KEY
13+
from fedcode.signatures import HttpSignature
14+
15+
16+
class Command(BaseCommand):
17+
def handle(self, *args, **options):
18+
"""
19+
Federate Command is sending the http signed request to the target and save the status of the request
20+
"""
21+
22+
for rq in FederateRequest.objects.all().order_by("created_at"):
23+
if rq.done:
24+
continue
25+
26+
try:
27+
HttpSignature.signed_request(
28+
rq.target, rq.body, FEDERATEDCODE_PRIVATE_KEY, rq.key_id
29+
)
30+
rq.done = True
31+
rq.save()
32+
except Exception as e:
33+
rq.error_message = e
34+
finally:
35+
rq.save()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# FederatedCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/nexB/federatedcode for support or download.
7+
# See https://aboutcode.org for more information about AboutCode.org OSS projects.
8+
#
9+
from django.core.management import BaseCommand
10+
11+
from fedcode.importer import Importer
12+
from fedcode.models import SyncRequest
13+
14+
15+
class Command(BaseCommand):
16+
def handle(self, *args, **options):
17+
"""
18+
The Sync Command is responsible for running the Importer and updating the status of pending sync requests.
19+
"""
20+
for sync_r in SyncRequest.objects.all().order_by("created_at"):
21+
if sync_r.done:
22+
continue
23+
24+
try:
25+
repo = sync_r.repo
26+
repo.git_repo_obj.remotes.origin.pull()
27+
importer = Importer(repo, repo.admin)
28+
importer.run()
29+
sync_r.done = True
30+
except Exception as e:
31+
sync_r.error_message = e
32+
finally:
33+
sync_r.save()

fedcode/management/commands/tasks.py

Lines changed: 0 additions & 63 deletions
This file was deleted.

federatedcode/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
redirect_vulnerability,
8383
name="vulnerability-page",
8484
),
85-
path("notes/<uuid:note_id>", NoteView.as_view(), name="note-page"),
85+
path("notes/<uuid:uuid>", NoteView.as_view(), name="note-page"),
8686
path("api/v0/users/@<str:username>", UserProfile.as_view(), name="user-ap-profile"),
8787
path(
8888
"api/v0/purls/@<path:purl_string>/",

0 commit comments

Comments
 (0)