Skip to content

Commit a32d8f5

Browse files
authored
Snippets5000: Fix case where file deleted and folder contains 1 code file (#535)
* Fix case where file del and folder contains 1 code file * Add test case
1 parent 4e04a8d commit a32d8f5

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

snippets5000/PullRequestSimulations/data.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,21 @@
5959
}
6060
]
6161
},
62+
{
63+
"Name": "Delete - Single file remains no project - Compile",
64+
"ExpectedResults": [
65+
{
66+
"ResultCode": 0,
67+
"DiscoveredProject": "snippets/good/normal/single_code_file/Now.cs"
68+
}
69+
],
70+
"Items": [
71+
{
72+
"ItemType": "Delete",
73+
"Path": "snippets/good/normal/single_code_file/OtherFile.cs"
74+
}
75+
]
76+
},
6277
{
6378
"Name": "Delete - Files from diff projs, find sln",
6479
"ExpectedResults": [

snippets5000/Snippets5000/PullRequestProcessor.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private async IAsyncEnumerable<DiscoveryResult> FindAllSolutionsAndProjects(stri
131131
/* SLN found no projs */ (not null, 1, 0, _, _, false, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_SLN_NOPROJ, item, project),
132132
/* SLN found no projs, del */ (not null, 1, 0, _, _, true, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_GOOD, item, project),
133133
/* Project found */ (not null, 0, 1, _, _, _, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_GOOD, item, project),
134-
/* Single .cs file compile */ (null, 0, 0, 1, _, _, _, true) => new DiscoveryResult(DiscoveryResult.RETURN_GOOD, item, item),
134+
/* Single .cs file compile */ (not null, 0, 0, 1, _, _, _, true) => new DiscoveryResult(DiscoveryResult.RETURN_GOOD, item, project),
135135
/* Code no proj */ (null, 0, 0, > 0, _, _, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_NOPROJ, item, ""),
136136
/* Code no proj */ (null, 0, 0, _, > 0, _, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_NOPROJ, item, ""),
137137
/* catch all */ _ => new DiscoveryResult(DiscoveryResult.RETURN_NOPROJ, item, "CONDITION NOT FOUND"),
@@ -231,8 +231,18 @@ static void ScanFile(string file, ref string? project, ref int countOfSln, ref i
231231

232232
// If a code file
233233
else if (EnvExtensionsCodeTriggers.Contains(ext, StringComparer.OrdinalIgnoreCase))
234+
{
234235
countOfCode++;
235236

237+
// Case for .NET 10 single file app
238+
// No solution or projects found, process a C# file
239+
if (countOfSln == 0 && countOfProjs == 0 && ext.Equals(".cs", StringComparison.OrdinalIgnoreCase))
240+
{
241+
// First code file can be a project, anything else is invalid
242+
project = countOfCode == 1 ? file : null;
243+
}
244+
}
245+
236246
// If a special trigger file
237247
else if (EnvFileTriggers.Contains(Path.GetFileName(file), StringComparer.OrdinalIgnoreCase))
238248
countOfSpecial++;

0 commit comments

Comments
 (0)