Skip to content

Commit 2e64654

Browse files
Improve DevOps logging for code owners linter (#9040)
* Improve DevOps logging for code owners linter * Fix missing brace * Update Program.cs * Update Program.cs * Update Program.cs Add a comment as to why we had to replace the newline with an encoded newline. --------- Co-authored-by: James Suplizio <jasupliz@microsoft.com>
1 parent 62fc71b commit 2e64654

File tree

1 file changed

+20
-4
lines changed
  • tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter

1 file changed

+20
-4
lines changed

tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs

+20-4
Original file line numberDiff line numberDiff line change
@@ -269,24 +269,40 @@ static int LintCodeownersFile(string teamUserBlobStorageUri,
269269
errors = baselineUtils.FilterErrorsUsingBaseline(errors);
270270
}
271271
}
272-
272+
bool loggingInDevOps = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SYSTEM_TEAMPROJECTID"));
273273
int returnCode = 0;
274274
// If there are errors, and this isn't a baseline generation, ensure the returnCode is non-zero and output the errors.
275275
if ((errors.Count > 0) && !generateBaseline)
276276
{
277277
returnCode = 1;
278278

279+
// DevOps only adds the first 4 errors to the github checks list so lets always add the generic one first and then as many of the individual ones as can be found afterwards
280+
if (loggingInDevOps)
281+
{
282+
Console.WriteLine($"##vso[task.logissue type=error;]There are linter errors. Please visit {linterErrorsHelpLink} for guidance on how to handle them.");
283+
}
284+
else
285+
{
286+
Console.WriteLine($"There are linter errors. Please visit {linterErrorsHelpLink} for guidance on how to handle them.");
287+
}
288+
279289
// Output the errors sorted ascending by line number and by type. If there's a block
280290
// error with the same starting line number as a single line error, the block error
281291
// should be output first.
282292
var errorsByLineAndType = errors.OrderBy(e => e.LineNumber).ThenBy(e => e.GetType().Name);
283293

284294
foreach (var error in errorsByLineAndType)
285295
{
286-
Console.WriteLine(error + Environment.NewLine);
296+
if (loggingInDevOps)
297+
{
298+
// Environment.NewLine needs to be replaced by an encoded NewLine "%0D%0A" in order to display on GitHub and DevOps checks
299+
Console.WriteLine($"##vso[task.logissue type=error;sourcepath={codeownersFileFullPath};linenumber={error.LineNumber};columnnumber=1;]{error.ToString().Replace(Environment.NewLine,"%0D%0A")}");
300+
}
301+
else
302+
{
303+
Console.WriteLine(error + Environment.NewLine);
304+
}
287305
}
288-
289-
Console.WriteLine($"There were linter errors. Please visit {linterErrorsHelpLink} for guidance on how to handle them.");
290306
}
291307
return returnCode;
292308
}

0 commit comments

Comments
 (0)