3131 DiffScanResult ,
3232 PackageComparisonResult ,
3333 create_diff_scan_result ,
34+ matching_full_scan_url ,
35+ normalize_report_url ,
3436)
3537from socketsecurity .core .exceptions import APIResourceNotFound
38+ from socketsecurity .core .report_urls import add_query_params
3639
3740from .resource_utils import check_file_count_against_ulimit
3841from .socket_config import SocketConfig
@@ -1315,8 +1318,9 @@ def create_full_scan_with_report_url(
13151318 raise
13161319
13171320 # Construct report URL
1318- base_socket = "https://socket.dev/dashboard/org"
1319- diff .report_url = f"{ base_socket } /{ self .config .org_slug } /sbom/{ new_full_scan .id } "
1321+ diff .old_scan_url = None
1322+ diff .new_scan_url = normalize_report_url (new_full_scan .html_report_url )
1323+ diff .report_url = diff .new_scan_url
13201324 diff .diff_url = diff .report_url
13211325 diff .set_scan_ids (new_full_scan .id )
13221326 diff .is_full_scan = True
@@ -2050,6 +2054,9 @@ def _get_diff_scan_result(
20502054 # them, so omit_unchanged and the bounded cached-polling contract cannot be
20512055 # bypassed by an eager response.
20522056 artifacts_dict = None
2057+ completed_diff_url = None
2058+ completed_old_scan_url = None
2059+ completed_new_scan_url = None
20532060
20542061 # cached=true is the polling contract (202 while computing, 200 when
20552062 # ready). The API ignores omit_license_details when cached=true - cached
@@ -2098,6 +2105,13 @@ def _get_diff_scan_result(
20982105 f"Error fetching diff scan { diff_scan_id } : unexpected response: { str (response )[:500 ]} "
20992106 )
21002107 artifacts_dict = scan ["artifacts" ]
2108+ completed_diff_url = normalize_report_url (scan .get ("html_url" ))
2109+ completed_old_scan_url = matching_full_scan_url (
2110+ scan .get ("before_full_scan" ), head_full_scan_id
2111+ )
2112+ completed_new_scan_url = matching_full_scan_url (
2113+ scan .get ("after_full_scan" ), new_full_scan_id
2114+ )
21012115 log .info (
21022116 "Diff scan comparison ready in "
21032117 f"{ time .monotonic () - poll_start :.2f} s: id={ diff_scan_id } , "
@@ -2115,7 +2129,13 @@ def _get_diff_scan_result(
21152129 last_interval = interval
21162130 interval = min (interval * DIFF_SCAN_POLL_BACKOFF_MULTIPLIER , DIFF_SCAN_POLL_MAX_INTERVAL_SECONDS )
21172131
2118- return create_diff_scan_result (artifacts_dict , diff_scan_id )
2132+ return create_diff_scan_result (
2133+ artifacts_dict ,
2134+ diff_scan_id ,
2135+ diff_url = completed_diff_url ,
2136+ old_scan_url = completed_old_scan_url ,
2137+ new_scan_url = completed_new_scan_url ,
2138+ )
21192139
21202140 def get_diff_scan_artifacts (
21212141 self ,
@@ -2231,18 +2251,20 @@ def _get_package_comparison(
22312251
22322252 if comparison is None :
22332253 try :
2234- diff_artifacts = (
2235- self .sdk .fullscans .stream_diff (
2254+ stream_response = self .sdk .fullscans .stream_diff (
22362255 self .config .org_slug ,
22372256 head_full_scan_id ,
22382257 new_full_scan_id ,
22392258 use_types = True ,
22402259 include_license_details = str (include_license_details ).lower ()
2241- ). data . artifacts
2242- )
2260+ )
2261+ diff_artifacts = stream_response . data . artifacts
22432262 comparison = DiffScanResult (
22442263 artifacts = diff_artifacts ,
22452264 diff_scan_id = None ,
2265+ diff_url = normalize_report_url (
2266+ getattr (stream_response .data , "diff_report_url" , None )
2267+ ),
22462268 )
22472269 except APIFailure as e :
22482270 log .error (f"API Error: { e } " )
@@ -2327,6 +2349,9 @@ def _get_package_comparison(
23272349 removed_packages = removed_packages ,
23282350 packages = packages ,
23292351 diff_scan_id = comparison .diff_scan_id ,
2352+ diff_url = comparison .diff_url ,
2353+ old_scan_url = comparison .old_scan_url ,
2354+ new_scan_url = comparison .new_scan_url ,
23302355 )
23312356
23322357 def get_added_and_removed_packages (
@@ -2409,6 +2434,7 @@ def create_new_diff(
24092434 head_full_scan_id = self .resolve_base_full_scan_id (params )
24102435
24112436 # If no head scan exists, create an empty baseline scan
2437+ baseline_report_url = None
24122438 if head_full_scan_id is None :
24132439 log .info ("No previous scan found - creating empty baseline scan" )
24142440 new_params = copy .deepcopy (params .__dict__ )
@@ -2424,6 +2450,7 @@ def create_new_diff(
24242450 try :
24252451 head_full_scan = self .create_full_scan (empty_files , tmp_params , base_paths = base_paths )
24262452 head_full_scan_id = head_full_scan .id
2453+ baseline_report_url = normalize_report_url (head_full_scan .html_report_url )
24272454 log .info (
24282455 "Baseline selected: source=empty "
24292456 f"scan_id={ json .dumps (head_full_scan_id )} "
@@ -2513,22 +2540,26 @@ def create_new_diff(
25132540 diff = self .create_diff_report (added_packages , removed_packages , unchanged_packages )
25142541 diff .packages = packages
25152542
2516- base_socket = "https://socket.dev/dashboard/org"
25172543 diff .set_scan_ids (
25182544 new_full_scan .id ,
25192545 old_scan_id = head_full_scan_id ,
25202546 diff_scan_id = comparison .diff_scan_id ,
25212547 )
25222548
2523- report_url = f"{ base_socket } /{ self .config .org_slug } /sbom/{ diff .id } "
2524- if not params .include_license_details :
2525- report_url += "?include_license_details=false"
2526- diff .report_url = report_url
2527-
2528- if head_full_scan_id is not None :
2529- diff .diff_url = f"{ base_socket } /{ self .config .org_slug } /diff/{ head_full_scan_id } /{ diff .id } "
2530- else :
2531- diff .diff_url = diff .report_url
2549+ old_scan_url = comparison .old_scan_url or baseline_report_url
2550+ new_scan_url = comparison .new_scan_url or normalize_report_url (
2551+ new_full_scan .html_report_url
2552+ )
2553+ diff .old_scan_url = old_scan_url
2554+ diff .new_scan_url = new_scan_url
2555+ diff .report_url = (
2556+ new_scan_url
2557+ if params .include_license_details
2558+ else add_query_params (
2559+ new_scan_url , {"include_license_details" : "false" }
2560+ )
2561+ )
2562+ diff .diff_url = comparison .diff_url
25322563
25332564 # PR/MR runs previously logged only the scan IDs, so a CI log had no link to the
25342565 # result. Logged here rather than at each call site so every diff flow gets it.
0 commit comments