Skip to content

Commit

Permalink
Updates to support Nuget packages (#651)
Browse files Browse the repository at this point in the history
* code gardening

* code gardening

* Updates to capture the value correctly
  • Loading branch information
samsmithnz committed Nov 12, 2023
1 parent 4cf18ed commit 571ac7f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/RepoGovernance.Core/SummaryItemsDA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ public static List<UserOwnerRepo> GetRepos(string user)
;
}

public static async Task<int> UpdateSummaryItemNuGetPackageStats(string? connectionString,
public static async Task<int> UpdateSummaryItemNuGetPackageStats(
string? connectionString,
string user,
string owner,
string repo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ public async Task<int> UpdateSummaryItem(string user, string owner, string repo)
}

[HttpPost("UpdateSummaryItemNuGetPackageStats")]
public async Task<int> UpdateSummaryItemNuGetPackageStats(NuGetPayload nugetPayload)
public async Task<int> UpdateSummaryItemNuGetPackageStats(NuGetPayload nugetPayload)
{
if (nugetPayload != null)
{
string? repo = nugetPayload?.Repo;
string? owner = nugetPayload?.Owner;
string? user = nugetPayload?.User;
string? jsonPayload = nugetPayload?.JsonPayload;
//There is some weirdness when the json is embedded in this object and then the object is serialized a second time - it returns an array of strings.
string? jsonPayload = nugetPayload?.JsonPayloadString;
string? payloadType = nugetPayload?.PayloadType;

if (repo == null || owner == null || user == null || jsonPayload == null)
if (repo == null || owner == null || user == null || jsonPayload == null || payloadType == null)
{
return -1;
}
Expand Down
30 changes: 27 additions & 3 deletions src/RepoGovernance.Service/Models/NuGetPayload.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace RepoGovernance.Service.Models
using System.Text;

namespace RepoGovernance.Service.Models
{
public class NuGetPayload
{
public NuGetPayload(string user, string owner, string repo, string jsonPayload, string payloadType)
public NuGetPayload(string user, string owner, string repo, string[] jsonPayload, string payloadType)
{
User = user;
Owner = owner;
Expand All @@ -13,7 +15,29 @@ public NuGetPayload(string user, string owner, string repo, string jsonPayload,
public string? User { get; set; }
public string? Owner { get; set; }
public string? Repo { get; set; }
public string? JsonPayload { get; set; }
//There is some weirdness when the json is embedded in this object and then the object is serialized a second time - it returns an array of strings.
public string[]? JsonPayload { get; set; }
public string JsonPayloadString
{
get
{
if (JsonPayload == null)
{
return string.Empty;
}
return UsingLoopStringBuilder(JsonPayload);
}
}
public string? PayloadType { get; set; }

private string UsingLoopStringBuilder(string[] array)
{
StringBuilder result = new();
foreach (string item in array)
{
result.Append(item);
}
return result.ToString();
}
}
}

0 comments on commit 571ac7f

Please sign in to comment.