Skip to content

Commit

Permalink
Improve DevOps logging for code owners linter (#9040)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
weshaggard and JimSuplizio authored Sep 26, 2024
1 parent 62fc71b commit 2e64654
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions tools/codeowners-utils/Azure.Sdk.Tools.CodeownersLinter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,24 +269,40 @@ static int LintCodeownersFile(string teamUserBlobStorageUri,
errors = baselineUtils.FilterErrorsUsingBaseline(errors);
}
}

bool loggingInDevOps = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("SYSTEM_TEAMPROJECTID"));
int returnCode = 0;
// If there are errors, and this isn't a baseline generation, ensure the returnCode is non-zero and output the errors.
if ((errors.Count > 0) && !generateBaseline)
{
returnCode = 1;

// 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
if (loggingInDevOps)
{
Console.WriteLine($"##vso[task.logissue type=error;]There are linter errors. Please visit {linterErrorsHelpLink} for guidance on how to handle them.");
}
else
{
Console.WriteLine($"There are linter errors. Please visit {linterErrorsHelpLink} for guidance on how to handle them.");
}

// Output the errors sorted ascending by line number and by type. If there's a block
// error with the same starting line number as a single line error, the block error
// should be output first.
var errorsByLineAndType = errors.OrderBy(e => e.LineNumber).ThenBy(e => e.GetType().Name);

foreach (var error in errorsByLineAndType)
{
Console.WriteLine(error + Environment.NewLine);
if (loggingInDevOps)
{
// Environment.NewLine needs to be replaced by an encoded NewLine "%0D%0A" in order to display on GitHub and DevOps checks
Console.WriteLine($"##vso[task.logissue type=error;sourcepath={codeownersFileFullPath};linenumber={error.LineNumber};columnnumber=1;]{error.ToString().Replace(Environment.NewLine,"%0D%0A")}");
}
else
{
Console.WriteLine(error + Environment.NewLine);
}
}

Console.WriteLine($"There were linter errors. Please visit {linterErrorsHelpLink} for guidance on how to handle them.");
}
return returnCode;
}
Expand Down

0 comments on commit 2e64654

Please sign in to comment.