1+ using System . Security . Cryptography ;
2+ using System . Text ;
3+
14using NuGetUpdater . Core . Discover ;
25using NuGetUpdater . Core . Run ;
36using NuGetUpdater . Core . Run . ApiModel ;
@@ -27,7 +30,6 @@ public async Task<int> RunAsync(FileInfo jobFilePath, DirectoryInfo repoContents
2730 var jobFileContent = await File . ReadAllTextAsync ( jobFilePath . FullName ) ;
2831 var jobWrapper = RunWorker . Deserialize ( jobFileContent ) ;
2932 var job = jobWrapper . Job ;
30- var experimentsManager = ExperimentsManager . GetExperimentsManager ( job . Experiments ) ;
3133
3234 // Use the case-insensitive repo contents path if provided, otherwise use the original
3335 var actualRepoContentsPath = caseInsensitiveRepoContentsPath ?? repoContentsPath ;
@@ -190,10 +192,10 @@ internal CreateDependencySubmission BuildDependencySubmission(
190192 {
191193 Version = 1 ,
192194 Sha = baseCommitSha ,
193- Ref = $ "refs/heads/ { job . Source . Branch ?? "main" } " ,
195+ Ref = GetSymbolicRef ( job . Source . Branch ) ,
194196 Job = new CreateDependencySubmission . SubmissionJob
195197 {
196- Correlator = $ "dependabot-nuget- { directory . Replace ( "/" , "-" ) . TrimStart ( '-' ) } " ,
198+ Correlator = GetCorrelator ( directory ) ,
197199 Id = _jobId
198200 } ,
199201 Detector = new CreateDependencySubmission . SubmissionDetector
@@ -212,9 +214,36 @@ internal CreateDependencySubmission BuildDependencySubmission(
212214 } ;
213215 }
214216
217+ internal static string GetSymbolicRef ( string ? branch )
218+ {
219+ branch = ( branch ?? "main" ) . TrimStart ( '/' ) ;
220+ if ( branch . StartsWith ( "refs/" , StringComparison . OrdinalIgnoreCase ) )
221+ {
222+ return branch ;
223+ }
224+
225+ return $ "refs/heads/{ branch } ";
226+ }
227+
228+ internal static string GetCorrelator ( string directory )
229+ {
230+ var sanitized = directory . TrimStart ( '/' ) . Replace ( "/" , "-" ) . TrimStart ( '-' ) ;
231+ if ( Encoding . UTF8 . GetByteCount ( sanitized ) > 32 )
232+ {
233+ sanitized = Convert . ToHexStringLower ( SHA256 . HashData ( Encoding . UTF8 . GetBytes ( sanitized ) ) ) ;
234+ }
235+
236+ return string . IsNullOrEmpty ( sanitized ) ? "dependabot-nuget" : $ "dependabot-nuget-{ sanitized } ";
237+ }
238+
215239 internal static string GetDetectorVersion ( )
216240 {
217- var version = Environment . GetEnvironmentVariable ( "DEPENDABOT_VERSION" ) ?? "development" ;
241+ var version = Environment . GetEnvironmentVariable ( "DEPENDABOT_VERSION" ) ;
242+ if ( string . IsNullOrWhiteSpace ( version ) )
243+ {
244+ version = "development" ;
245+ }
246+
218247 var sha = Environment . GetEnvironmentVariable ( "DEPENDABOT_UPDATER_SHA" ) ;
219248 if ( ! string . IsNullOrEmpty ( sha ) )
220249 {
0 commit comments