Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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