Skip to content

Commit 504ea29

Browse files
brettfoCopilot
andcommitted
address PR review feedback
- Remove unused experimentsManager variable (TreatWarningsAsErrors) - Normalize branch ref to avoid double-prefixing refs/heads/ - Hash long directory names in correlator (matching Ruby's 32-byte threshold) - Use string.IsNullOrWhiteSpace for DEPENDABOT_VERSION fallback - Guard nuget/script/run against missing/empty version file Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6458f0b commit 504ea29

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Graph/GraphWorker.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using System.Security.Cryptography;
2+
using System.Text;
3+
14
using NuGetUpdater.Core.Discover;
25
using NuGetUpdater.Core.Run;
36
using 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
{

nuget/script/run

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22
# shellcheck disable=all
33

4-
export DEPENDABOT_VERSION=$(cat "$DEPENDABOT_HOME/.dependabot-version")
4+
VERSION_FILE="$DEPENDABOT_HOME/.dependabot-version"
5+
if [ -f "$VERSION_FILE" ] && [ -s "$VERSION_FILE" ]; then
6+
export DEPENDABOT_VERSION=$(cat "$VERSION_FILE")
7+
fi
58
pwsh "$DEPENDABOT_HOME/dependabot-updater/bin/main.ps1" $*

0 commit comments

Comments
 (0)