Skip to content

Commit

Permalink
Duplicate key error for tags table.
Browse files Browse the repository at this point in the history
Clear response param after group.
Update readme.
  • Loading branch information
ArneMaes0 committed Jan 30, 2024
1 parent b805448 commit b7b272b
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 91 deletions.
Binary file added Documentation/Organizations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Documentation/Workflows_AddWorkflowPage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,91 +1,97 @@
namespace Skyline.Protocol.PollManager.ResponseHandler.Repositories
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

using Newtonsoft.Json;

using Skyline.DataMiner.Scripting;
using Skyline.DataMiner.Utils.Github.API.V20221128.Repositories;
using Skyline.Protocol;
using Skyline.Protocol.API.Headers;
using Skyline.Protocol.Extensions;
using Skyline.Protocol.PollManager.RequestHandler.Repositories;
using Skyline.Protocol.Tables;

public static partial class RepositoriesResponseHandler
{
public static void HandleRepositoriesTagsResponse(SLProtocol protocol)
{
// Check status code
if (!protocol.IsSuccessStatusCode())
{
return;
}

// Parse response
var response = JsonConvert.DeserializeObject<List<RepositoryTagsResponse>>(Convert.ToString(protocol.GetParameter(Parameter.getrepositorytagscontent)));

if (response == null)
{
protocol.Log($"QA{protocol.QActionID}|ParseGetRepositoryTagsResponse|response was null.", LogType.Error, LogLevel.Level1);
return;
}

if (!response.Any())
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

using Newtonsoft.Json;

using Skyline.DataMiner.Scripting;
using Skyline.DataMiner.Utils.Github.API.V20221128.Repositories;
using Skyline.Protocol;
using Skyline.Protocol.API.Headers;
using Skyline.Protocol.Extensions;
using Skyline.Protocol.PollManager.RequestHandler.Repositories;
using Skyline.Protocol.Tables;

public static partial class RepositoriesResponseHandler
{
public static void HandleRepositoriesTagsResponse(SLProtocol protocol)
{
// Check status code
if (!protocol.IsSuccessStatusCode())
{
return;
}

// Parse response
var response = JsonConvert.DeserializeObject<List<RepositoryTagsResponse>>(Convert.ToString(protocol.GetParameter(Parameter.getrepositorytagscontent)));

if (response == null)
{
protocol.Log($"QA{protocol.QActionID}|ParseGetRepositoryTagsResponse|response was null.", LogType.Error, LogLevel.Level1);
return;
}

if (!response.Any())
{
// No tags for the repository
protocol.Log($"QA{protocol.QActionID}|ParseGetRepositoryTagsResponse|No tags for the repo.", LogType.Information, LogLevel.Level2);
return;
}

// Parse url to check which respository this issue is linked to
var pattern = "https:\\/\\/api.github.com\\/repos\\/(.*)\\/(.*)\\/commits\\/(.*)";
var options = RegexOptions.Multiline;

var match = Regex.Match(response[0]?.Commit.Url, pattern, options);
var owner = match.Groups[1].Value;
var name = match.Groups[2].Value;

// Update the tags table
var table = RepositoryTagsTable.GetTable();
foreach (var tag in response)
{
if (tag == null)
{
protocol.Log($"QA{protocol.QActionID}|GetRepositoryTagsResponse|Tag was null.", LogType.Error, LogLevel.Level1);
continue;
}

table.Rows.Add(new RepositoryTagsTableRow
{
ID = $"{owner}/{name}/commits/{tag.Name}",
Name = tag.Name,
RepositoryID = $"{owner}/{name}",
CommitSHA = tag.Commit?.Sha ?? Exceptions.NotAvailable,
});
}

if (table.Rows.Count > 0)
{
table.SaveToProtocol(protocol, true);
}

// Check if there are more tags to fetch
var linkHeader = Convert.ToString(protocol.GetParameter(Parameter.getrepositorytagslinkheader));
if (string.IsNullOrEmpty(linkHeader)) return;

var link = new LinkHeader(linkHeader);

protocol.Log($"QA{protocol.QActionID}|ParseGetRepositoryTagsResponse|Current page: {link.CurrentPage}", LogType.Information, LogLevel.Level2);
protocol.Log($"QA{protocol.QActionID}|ParseGetRepositoryTagsResponse|Has next page: {link.HasNext}", LogType.Information, LogLevel.Level2);

if (link.HasNext)
{
RepositoriesRequestHandler.HandleRepositoriesTagsRequest(protocol, owner, name, PollingConstants.PerPage, link.NextPage);
}
}
}
}

// Parse url to check which respository this issue is linked to
var pattern = "https:\\/\\/api.github.com\\/repos\\/(.*)\\/(.*)\\/commits\\/(.*)";
var options = RegexOptions.Multiline;

var match = Regex.Match(response[0]?.Commit.Url, pattern, options);
var owner = match.Groups[1].Value;
var name = match.Groups[2].Value;

// Update the tags table
var table = RepositoryTagsTable.GetTable();
foreach (var tag in response)
{
if (tag == null)
{
protocol.Log($"QA{protocol.QActionID}|GetRepositoryTagsResponse|Tag was null.", LogType.Error, LogLevel.Level1);
continue;
}

// Update existing workflow if found, otherwise create new one
var id = $"{owner}/{name}/commits/{tag.Name}";
var row = table.Rows.Find(wf => wf.ID == id) ?? new RepositoryTagsTableRow();
row.Name = tag.Name;
row.RepositoryID = $"{owner}/{name}";
row.CommitSHA = tag.Commit?.Sha ?? Exceptions.NotAvailable;

// If its a new row fill in ID and add it to the table.
if (String.IsNullOrEmpty(row.ID))
{
row.ID = id;
table.Rows.Add(row);
}
}

if (table.Rows.Count > 0)
{
table.SaveToProtocol(protocol, true);
}

// Check if there are more tags to fetch
var linkHeader = Convert.ToString(protocol.GetParameter(Parameter.getrepositorytagslinkheader));
if (string.IsNullOrEmpty(linkHeader)) return;

var link = new LinkHeader(linkHeader);

protocol.Log($"QA{protocol.QActionID}|ParseGetRepositoryTagsResponse|Current page: {link.CurrentPage}", LogType.Information, LogLevel.Level2);
protocol.Log($"QA{protocol.QActionID}|ParseGetRepositoryTagsResponse|Has next page: {link.HasNext}", LogType.Information, LogLevel.Level2);

if (link.HasNext)
{
RepositoriesRequestHandler.HandleRepositoriesTagsRequest(protocol, owner, name, PollingConstants.PerPage, link.NextPage);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ public static void HandleRepositoriesWorkflowsResponse(SLProtocol protocol)
return;
}

// Check if there are more workflows to fetch
var linkHeader = Convert.ToString(protocol.GetParameter(Parameter.getrepositoryworkflowslinkheader));
var link = new LinkHeader(linkHeader);

// Parse response
var response = JsonConvert.DeserializeObject<RepositoryWorkflowsResponse>(Convert.ToString(protocol.GetParameter(Parameter.getrepositoryworkflowscontent)));
var url = Convert.ToString(protocol.GetParameter(Parameter.getrepositoryworkflowsurl));
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ You can do a manual install by downloading the .dmprotocol package file from the

- [Configuration](#configuration)
- [Overview](#overview)
- [Organizations](#organizations)
- [Tags](#tags)
- [Releases](#releases)
- [Issues](#issues)
Expand All @@ -40,9 +41,15 @@ On the Repositories - Overview page you get a tree control that shows all the co
1. Tags
1. Releases
1. Issues
1. Workflows

![Repositories - Overview](Documentation/RepositoriesOverviewPage.png)

### Organizations
On the Organizations page you get an overview of the organizations the configured token is part of. You can enable repository tracking from this page. This will add all the repositories under the repository to the repositories table and start polling them.

![Organizations](Documentation/Organizations.png)

### Tags
The tags table contains all the tags from all the tracked repositories. Here you can find the tag name the repository it's linked with and the commit ID it was placed on.

Expand All @@ -63,7 +70,7 @@ The issues table contains all the issues from all the tracked repositories. Here
1. when it was created
1. ...

![Editor](Documentation/IssuesPage.png)
![Issues](Documentation/IssuesPage.png)

### Workflows
The workflows table contains all the workflows from all the tracked repositories. Here you can find some general information about the workflows, for example:
Expand All @@ -73,7 +80,9 @@ The workflows table contains all the workflows from all the tracked repositories
1. when it was created
1. ...

![Editor](Documentation/WorkflowsPage.png)
![Workflows](Documentation/WorkflowsPage.png)

![Add Workflow](Documentation/Workflows_AddWorkflowPage.png)

## About DataMiner

Expand Down
60 changes: 60 additions & 0 deletions protocol.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3912,6 +3912,7 @@ Are you sure you want to continue.]]>
<Type>action</Type>
<Content>
<Id>251</Id>
<Id>301</Id>
</Content>
</Trigger>
<Trigger id="252">
Expand All @@ -3921,6 +3922,7 @@ Are you sure you want to continue.]]>
<Type>action</Type>
<Content>
<Id>252</Id>
<Id>302</Id>
</Content>
</Trigger>
<Trigger id="253">
Expand All @@ -3930,6 +3932,7 @@ Are you sure you want to continue.]]>
<Type>action</Type>
<Content>
<Id>253</Id>
<Id>303</Id>
</Content>
</Trigger>
<Trigger id="254">
Expand All @@ -3939,6 +3942,7 @@ Are you sure you want to continue.]]>
<Type>action</Type>
<Content>
<Id>254</Id>
<Id>304</Id>
</Content>
</Trigger>
<Trigger id="255">
Expand All @@ -3948,6 +3952,7 @@ Are you sure you want to continue.]]>
<Type>action</Type>
<Content>
<Id>255</Id>
<Id>305</Id>
</Content>
</Trigger>
<Trigger id="260">
Expand All @@ -3957,6 +3962,7 @@ Are you sure you want to continue.]]>
<Type>action</Type>
<Content>
<Id>260</Id>
<Id>310</Id>
</Content>
</Trigger>
<Trigger id="261">
Expand All @@ -3966,6 +3972,7 @@ Are you sure you want to continue.]]>
<Type>action</Type>
<Content>
<Id>261</Id>
<Id>311</Id>
</Content>
</Trigger>
<Trigger id="270">
Expand All @@ -3975,6 +3982,7 @@ Are you sure you want to continue.]]>
<Type>action</Type>
<Content>
<Id>270</Id>
<Id>320</Id>
</Content>
</Trigger>
<Trigger id="271">
Expand All @@ -3984,6 +3992,7 @@ Are you sure you want to continue.]]>
<Type>action</Type>
<Content>
<Id>271</Id>
<Id>321</Id>
</Content>
</Trigger>
<Trigger id="276">
Expand All @@ -3993,6 +4002,7 @@ Are you sure you want to continue.]]>
<Type>action</Type>
<Content>
<Id>276</Id>
<Id>326</Id>
</Content>
</Trigger>
<Trigger id="278">
Expand Down Expand Up @@ -4137,6 +4147,56 @@ Are you sure you want to continue.]]>
<Type>clear</Type>
</Action>

<Action id="301">
<Name>Clear Repository Content</Name>
<On id="201">parameter</On>
<Type>clear</Type>
</Action>
<Action id="302">
<Name>Clear Repository Issues Content</Name>
<On id="202">parameter</On>
<Type>clear</Type>
</Action>
<Action id="303">
<Name>Clear Repository Tags Content</Name>
<On id="203">parameter</On>
<Type>clear</Type>
</Action>
<Action id="304">
<Name>Clear Repository Releases Content</Name>
<On id="204">parameter</On>
<Type>clear</Type>
</Action>
<Action id="305">
<Name>Clear Repository Workflows Content</Name>
<On id="205">parameter</On>
<Type>clear</Type>
</Action>
<Action id="310">
<Name>Clear User Organizations Content</Name>
<On id="210">parameter</On>
<Type>clear</Type>
</Action>
<Action id="311">
<Name>Clear Organization Repositories</Name>
<On id="211">parameter</On>
<Type>clear</Type>
</Action>
<Action id="320">
<Name>Clear Repository Content Content</Name>
<On id="220">parameter</On>
<Type>clear</Type>
</Action>
<Action id="321">
<Name>Clear Repository Content Content</Name>
<On id="221">parameter</On>
<Type>clear</Type>
</Action>
<Action id="326">
<Name>Clear Repository Secret Content</Name>
<On id="226">parameter</On>
<Type>clear</Type>
</Action>
<Action id="328">
<Name>Clear Get Repository Public Key Content</Name>
<On id="228">parameter</On>
Expand Down

0 comments on commit b7b272b

Please sign in to comment.