mirror of
https://github.com/actions/runner.git
synced 2025-12-19 08:50:41 +00:00
problem matcher default severity (#203)
This commit is contained in:
@@ -20,6 +20,7 @@ namespace GitHub.Runner.Worker
|
|||||||
|
|
||||||
public sealed class IssueMatcher
|
public sealed class IssueMatcher
|
||||||
{
|
{
|
||||||
|
private string _defaultSeverity;
|
||||||
private string _owner;
|
private string _owner;
|
||||||
private IssuePattern[] _patterns;
|
private IssuePattern[] _patterns;
|
||||||
private IssueMatch[] _state;
|
private IssueMatch[] _state;
|
||||||
@@ -27,6 +28,7 @@ namespace GitHub.Runner.Worker
|
|||||||
public IssueMatcher(IssueMatcherConfig config, TimeSpan timeout)
|
public IssueMatcher(IssueMatcherConfig config, TimeSpan timeout)
|
||||||
{
|
{
|
||||||
_owner = config.Owner;
|
_owner = config.Owner;
|
||||||
|
_defaultSeverity = config.Severity;
|
||||||
_patterns = config.Patterns.Select(x => new IssuePattern(x , timeout)).ToArray();
|
_patterns = config.Patterns.Select(x => new IssuePattern(x , timeout)).ToArray();
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
@@ -37,13 +39,26 @@ namespace GitHub.Runner.Worker
|
|||||||
{
|
{
|
||||||
if (_owner == null)
|
if (_owner == null)
|
||||||
{
|
{
|
||||||
_owner = String.Empty;
|
_owner = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _owner;
|
return _owner;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string DefaultSeverity
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_defaultSeverity == null)
|
||||||
|
{
|
||||||
|
_defaultSeverity = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _defaultSeverity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public IssueMatch Match(string line)
|
public IssueMatch Match(string line)
|
||||||
{
|
{
|
||||||
// Single pattern
|
// Single pattern
|
||||||
@@ -54,7 +69,7 @@ namespace GitHub.Runner.Worker
|
|||||||
|
|
||||||
if (regexMatch.Success)
|
if (regexMatch.Success)
|
||||||
{
|
{
|
||||||
return new IssueMatch(null, pattern, regexMatch.Groups);
|
return new IssueMatch(null, pattern, regexMatch.Groups, DefaultSeverity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@@ -95,7 +110,7 @@ namespace GitHub.Runner.Worker
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return
|
// Return
|
||||||
return new IssueMatch(runningMatch, pattern, regexMatch.Groups);
|
return new IssueMatch(runningMatch, pattern, regexMatch.Groups, DefaultSeverity);
|
||||||
}
|
}
|
||||||
// Not the last pattern
|
// Not the last pattern
|
||||||
else
|
else
|
||||||
@@ -169,7 +184,7 @@ namespace GitHub.Runner.Worker
|
|||||||
|
|
||||||
public sealed class IssueMatch
|
public sealed class IssueMatch
|
||||||
{
|
{
|
||||||
public IssueMatch(IssueMatch runningMatch, IssuePattern pattern, GroupCollection groups)
|
public IssueMatch(IssueMatch runningMatch, IssuePattern pattern, GroupCollection groups, string defaultSeverity = null)
|
||||||
{
|
{
|
||||||
File = runningMatch?.File ?? GetValue(groups, pattern.File);
|
File = runningMatch?.File ?? GetValue(groups, pattern.File);
|
||||||
Line = runningMatch?.Line ?? GetValue(groups, pattern.Line);
|
Line = runningMatch?.Line ?? GetValue(groups, pattern.Line);
|
||||||
@@ -178,6 +193,11 @@ namespace GitHub.Runner.Worker
|
|||||||
Code = runningMatch?.Code ?? GetValue(groups, pattern.Code);
|
Code = runningMatch?.Code ?? GetValue(groups, pattern.Code);
|
||||||
Message = runningMatch?.Message ?? GetValue(groups, pattern.Message);
|
Message = runningMatch?.Message ?? GetValue(groups, pattern.Message);
|
||||||
FromPath = runningMatch?.FromPath ?? GetValue(groups, pattern.FromPath);
|
FromPath = runningMatch?.FromPath ?? GetValue(groups, pattern.FromPath);
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(Severity) && !string.IsNullOrEmpty(defaultSeverity))
|
||||||
|
{
|
||||||
|
Severity = defaultSeverity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string File { get; }
|
public string File { get; }
|
||||||
@@ -256,6 +276,9 @@ namespace GitHub.Runner.Worker
|
|||||||
[DataMember(Name = "owner")]
|
[DataMember(Name = "owner")]
|
||||||
private string _owner;
|
private string _owner;
|
||||||
|
|
||||||
|
[DataMember(Name = "severity")]
|
||||||
|
private string _severity;
|
||||||
|
|
||||||
[DataMember(Name = "pattern")]
|
[DataMember(Name = "pattern")]
|
||||||
private IssuePatternConfig[] _patterns;
|
private IssuePatternConfig[] _patterns;
|
||||||
|
|
||||||
@@ -265,7 +288,7 @@ namespace GitHub.Runner.Worker
|
|||||||
{
|
{
|
||||||
if (_owner == null)
|
if (_owner == null)
|
||||||
{
|
{
|
||||||
_owner = String.Empty;
|
_owner = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _owner;
|
return _owner;
|
||||||
@@ -277,6 +300,24 @@ namespace GitHub.Runner.Worker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Severity
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_severity == null)
|
||||||
|
{
|
||||||
|
_severity = string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _severity;
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_severity = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public IssuePatternConfig[] Patterns
|
public IssuePatternConfig[] Patterns
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -303,6 +344,17 @@ namespace GitHub.Runner.Worker
|
|||||||
throw new ArgumentException("Owner must not be empty");
|
throw new ArgumentException("Owner must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate severity
|
||||||
|
switch ((_severity ?? string.Empty).ToUpperInvariant())
|
||||||
|
{
|
||||||
|
case "":
|
||||||
|
case "ERROR":
|
||||||
|
case "WARNING":
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentException($"Matcher '{_owner}' contains unexpected default severity '{_severity}'");
|
||||||
|
}
|
||||||
|
|
||||||
// Validate at least one pattern
|
// Validate at least one pattern
|
||||||
if (_patterns == null || _patterns.Length == 0)
|
if (_patterns == null || _patterns.Length == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.Linq;
|
|
||||||
using GitHub.Runner.Worker;
|
using GitHub.Runner.Worker;
|
||||||
using GitHub.Services.WebApi;
|
using GitHub.Services.WebApi;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
@@ -353,6 +350,48 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
config.Validate();
|
config.Validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
[Trait("Level", "L0")]
|
||||||
|
[Trait("Category", "Worker")]
|
||||||
|
public void Matcher_MultiplePatterns_DefaultSeverity()
|
||||||
|
{
|
||||||
|
var config = JsonUtility.FromString<IssueMatchersConfig>(@"
|
||||||
|
{
|
||||||
|
""problemMatcher"": [
|
||||||
|
{
|
||||||
|
""owner"": ""myMatcher"",
|
||||||
|
""severity"": ""warning"",
|
||||||
|
""pattern"": [
|
||||||
|
{
|
||||||
|
""regexp"": ""^(ERROR)?(?: )?(.+):$"",
|
||||||
|
""severity"": 1,
|
||||||
|
""code"": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""regexp"": ""^(.+)$"",
|
||||||
|
""message"": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
");
|
||||||
|
config.Validate();
|
||||||
|
var matcher = new IssueMatcher(config.Matchers[0], TimeSpan.FromSeconds(1));
|
||||||
|
|
||||||
|
var match = matcher.Match("ABC:");
|
||||||
|
match = matcher.Match("not-working");
|
||||||
|
Assert.Equal("warning", match.Severity);
|
||||||
|
Assert.Equal("ABC", match.Code);
|
||||||
|
Assert.Equal("not-working", match.Message);
|
||||||
|
|
||||||
|
match = matcher.Match("ERROR ABC:");
|
||||||
|
match = matcher.Match("not-working");
|
||||||
|
Assert.Equal("ERROR", match.Severity);
|
||||||
|
Assert.Equal("ABC", match.Code);
|
||||||
|
Assert.Equal("not-working", match.Message);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[Trait("Level", "L0")]
|
[Trait("Level", "L0")]
|
||||||
[Trait("Category", "Worker")]
|
[Trait("Category", "Worker")]
|
||||||
@@ -754,6 +793,43 @@ namespace GitHub.Runner.Common.Tests.Worker
|
|||||||
Assert.Equal("myMatcher", matcher.Owner);
|
Assert.Equal("myMatcher", matcher.Owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
[Trait("Level", "L0")]
|
||||||
|
[Trait("Category", "Worker")]
|
||||||
|
public void Matcher_SinglePattern_DefaultSeverity()
|
||||||
|
{
|
||||||
|
var config = JsonUtility.FromString<IssueMatchersConfig>(@"
|
||||||
|
{
|
||||||
|
""problemMatcher"": [
|
||||||
|
{
|
||||||
|
""owner"": ""myMatcher"",
|
||||||
|
""severity"": ""warning"",
|
||||||
|
""pattern"": [
|
||||||
|
{
|
||||||
|
""regexp"": ""^(ERROR)?(?: )?(.+): (.+)$"",
|
||||||
|
""severity"": 1,
|
||||||
|
""code"": 2,
|
||||||
|
""message"": 3
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
");
|
||||||
|
config.Validate();
|
||||||
|
var matcher = new IssueMatcher(config.Matchers[0], TimeSpan.FromSeconds(1));
|
||||||
|
|
||||||
|
var match = matcher.Match("ABC: not-working");
|
||||||
|
Assert.Equal("warning", match.Severity);
|
||||||
|
Assert.Equal("ABC", match.Code);
|
||||||
|
Assert.Equal("not-working", match.Message);
|
||||||
|
|
||||||
|
match = matcher.Match("ERROR ABC: not-working");
|
||||||
|
Assert.Equal("ERROR", match.Severity);
|
||||||
|
Assert.Equal("ABC", match.Code);
|
||||||
|
Assert.Equal("not-working", match.Message);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
[Trait("Level", "L0")]
|
[Trait("Level", "L0")]
|
||||||
[Trait("Category", "Worker")]
|
[Trait("Category", "Worker")]
|
||||||
|
|||||||
Reference in New Issue
Block a user