Skip to content

Commit

Permalink
Add tags for is QA (#45)
Browse files Browse the repository at this point in the history
* Add tags for is QA

* make changes

* refactor

---------

Co-authored-by: jdickson <[email protected]>
  • Loading branch information
joeldickson and dicko2 authored Dec 12, 2024
1 parent 4050870 commit ac4cc33
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
19 changes: 18 additions & 1 deletion src/Agoda.DevFeedback.AspNetStartup/TimedStartupPublisher.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Agoda.DevFeedback.Common;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Agoda.DevFeedback.AspNetStartup
Expand All @@ -8,14 +11,28 @@ internal static class TimedStartupPublisher
{
public static void Publish(string type, TimeSpan timeTaken)
{
const string TagPrefix = "DEVFEEDBACK_TAG_";

var gitContext = GitContextReader.GetGitContext();

// Use LINQ and dictionary comprehension for cleaner tag collection
var tags = Environment.GetEnvironmentVariables()
.Cast<DictionaryEntry>()
.Select(entry => (Key: entry.Key.ToString()!, Value: entry.Value?.ToString()))
.Where(entry => entry.Key.StartsWith(TagPrefix, StringComparison.OrdinalIgnoreCase)
&& !string.IsNullOrEmpty(entry.Value))
.ToDictionary(
entry => entry.Key[TagPrefix.Length..].ToLowerInvariant(),
entry => entry.Value!
);

var result = new DevFeedbackData(
metricsVersion: Assembly.GetExecutingAssembly().GetName().Version?.ToString(),
type: type,
projectName: Assembly.GetEntryAssembly()?.GetName().Name,
timeTaken: timeTaken.TotalMilliseconds.ToString(),
gitContext: gitContext
gitContext: gitContext,
tags: tags
);

DevFeedbackPublisher.Publish(apiEndpoint: null, result, DevLocalDataType.Build);
Expand Down
9 changes: 7 additions & 2 deletions src/Agoda.DevFeedback.Common/DevFeedbackData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Agoda.DevFeedback.Common
Expand Down Expand Up @@ -47,13 +48,16 @@ public class DevFeedbackData
[JsonProperty("date")]
public DateTime Date { get; set; }

[JsonProperty("tags")]
public Dictionary<string,string> Tags { get; set; }

public DevFeedbackData(
string metricsVersion,
string type,
string projectName,
string timeTaken,
GitContext gitContext
)
GitContext gitContext,
Dictionary<string,string> tags = null)
{
Id = Guid.NewGuid();
Type = type;
Expand All @@ -69,6 +73,7 @@ GitContext gitContext
RepositoryName = gitContext.RepositoryName;
Branch = gitContext.BranchName;
Date = DateTime.UtcNow;
Tags = tags;
}
}
}

0 comments on commit ac4cc33

Please sign in to comment.