// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Linq;
namespace EpicGames.Horde.Issues
{
///
/// Fingerprint for an issue
///
public interface IIssueFingerprint
{
///
/// The type of issue, which defines the handler to use for it
///
public string Type { get; }
///
/// Template string for the issue summary
///
public string SummaryTemplate { get; }
///
/// List of keys which identify this issue.
///
public IReadOnlySet Keys { get; }
///
/// Set of keys which should trigger a negative match
///
public IReadOnlySet? RejectKeys { get; }
///
/// Collection of additional metadata added by the handler
///
public IReadOnlySet? Metadata { get; }
///
/// Filter for changes that should be included in this issue
///
public string ChangeFilter { get; }
}
///
/// Extension methods for
///
public static class IssueFingerprintExtensions
{
///
/// Checks if a fingerprint matches another fingerprint
///
/// The first fingerprint to compare
/// The other fingerprint to compare to
/// True is the fingerprints match
public static bool IsMatch(this IIssueFingerprint fingerprint, IIssueFingerprint other)
{
if (!fingerprint.Type.Equals(other.Type, StringComparison.Ordinal))
{
return false;
}
if (!fingerprint.SummaryTemplate.Equals(other.SummaryTemplate, StringComparison.Ordinal))
{
return false;
}
if (fingerprint.Keys.Count == 0)
{
if (other.Keys.Count > 0)
{
return false;
}
}
else
{
if (!fingerprint.Keys.Any(x => other.Keys.Contains(x)))
{
return false;
}
}
if (fingerprint.RejectKeys != null && fingerprint.RejectKeys.Any(x => other.Keys.Contains(x)))
{
return false;
}
return true;
}
///
/// Checks if a fingerprint matches another fingerprint for creating a new span
///
/// The first fingerprint to compare
/// The other fingerprint to compare to
/// True is the fingerprints match
public static bool IsMatchForNewSpan(this IIssueFingerprint fingerprint, IIssueFingerprint other)
{
if (!fingerprint.Type.Equals(other.Type, StringComparison.Ordinal))
{
return false;
}
if (fingerprint.RejectKeys != null && fingerprint.RejectKeys.Any(x => other.Keys.Contains(x)))
{
return false;
}
return true;
}
}
}