Skip to content

Commit

Permalink
Merge pull request #81 from drasticactions/merge/develop-to-main
Browse files Browse the repository at this point in the history
+semver: minor
  • Loading branch information
drasticactions authored Nov 4, 2024
2 parents 81ebb9f + b3a7f0b commit 4261500
Show file tree
Hide file tree
Showing 24 changed files with 654 additions and 68 deletions.
64 changes: 50 additions & 14 deletions .github/workflows/nuget.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,28 @@
# This is a basic workflow to help you get started with Actions
name: Build Package

name: Nuget

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main", release-*, develop ]
pull_request:
branches: [ "main", release-*, develop ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of commits
fetch-depth: 0
submodules: 'true'

# Install .NET Core SDK
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x

# Pack Nuget
- name: Build and Pack Nugets
run: dotnet pack src/FishyFlip.sln --configuration Release --output nupkg

Expand All @@ -43,3 +31,51 @@ jobs:
with:
name: nupkg
path: nupkg/*.nupkg
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'true'

- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x

- name: Run FishyFlip.Tests
run: dotnet test src/FishyFlip.Tests/FishyFlip.Tests.csproj -- --report-trx --results-directory ../../dotnet-test-results

- name: Run WhiteWindLib.Tests
run: dotnet test src/WhiteWindLib.Tests/WhiteWindLib.Tests.csproj -- --report-trx --results-directory ../../dotnet-test-results

- name: Upload Test Results
uses: actions/upload-artifact@v4
with:
name: dotnet-test-results
path: dotnet-test-results
if: ${{ always() }}
publish:
needs: [build, test]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'

steps:
- name: Download Nuget Package
uses: actions/download-artifact@v4
with:
name: nupkg
path: nupkg

- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x

- name: Publish to NuGet
run: |
for f in ./nupkg/*.nupkg
do
dotnet nuget push $f --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
done
33 changes: 0 additions & 33 deletions .github/workflows/tests.yml

This file was deleted.

1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="Drastic.Utilities" Version="1.0.10" />
<PackageVersion Include="PublishSPAforGitHubPages.Build" Version="2.1.0" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.6.133" />
<PackageVersion Include="MSTest" Version="3.3.1" />
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.12.4" />
<PackageVersion Include="GitVersion.MSBuild" Version="6.0.2" />
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ For documentation, check out https://drasticactions.github.io/FishyFlip

### Third-Party Libraries

- [Nerdbank.GitVersioning](https://github.com/dotnet/Nerdbank.GitVersioning)
- [GitVersion](https://github.com/GitTools/GitVersion)

FishyFlip

Expand Down
2 changes: 1 addition & 1 deletion samples/Jetstream/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

atWebProtocol.OnRecordReceived += (sender, args) =>
{
Console.WriteLine($"Record Received: {args.Record.Type}");
Console.WriteLine($"Record Received: {args.Record.Kind}");
};

await atWebProtocol.ConnectAsync();
Expand Down
59 changes: 59 additions & 0 deletions src/FishyFlip.Tests/AnonymousTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,63 @@ public async Task DescribeRepoTest(string did)
Assert.IsTrue(describe.Did is not null);
Assert.AreEqual(describe.Did!.ToString(), repo.ToString());
}

[TestMethod]
public void MarkdownPostTest()
{
var markdownPost = @"Markdown Test: [FishyFlip](https://drasticactions.github.io/FishyFlip), #FishyFlip, [@drasticactions.dev](did:plc:yhgc5rlqhoezrx6fbawajxlh)";
var post = MarkdownPost.Parse(markdownPost);
Assert.IsTrue(post.OriginalMarkdown == markdownPost);
Assert.IsTrue(post.Post == "Markdown Test: FishyFlip, #FishyFlip, @drasticactions.dev");
Assert.IsTrue(post.Facets.Length == 3);
Assert.IsTrue(post.Facets[0].Features![0]!.Type == Constants.FacetTypes.Link);
Assert.IsTrue(post.Facets[0].Features![0]!.Uri == "https://drasticactions.github.io/FishyFlip");
Assert.IsTrue(post.Facets[0].Index!.ByteStart == 15);
Assert.IsTrue(post.Facets[0].Index!.ByteEnd == 24);
Assert.IsTrue(post.Facets[1].Features![0]!.Type == Constants.FacetTypes.Mention);
Assert.IsTrue(post.Facets[1].Features![0]!.Did!.ToString() == "did:plc:yhgc5rlqhoezrx6fbawajxlh");
Assert.IsTrue(post.Facets[1].Index!.ByteStart == 38);
Assert.IsTrue(post.Facets[1].Index!.ByteEnd == 57);
Assert.IsTrue(post.Facets[2].Features![0]!.Type == Constants.FacetTypes.Tag);
Assert.IsTrue(post.Facets[2].Features![0]!.Tag == "FishyFlip");
Assert.IsTrue(post.Facets[2].Index!.ByteStart == 26);
Assert.IsTrue(post.Facets[2].Index!.ByteEnd == 36);
}

[TestMethod]
public async Task ValidateFacetHelpers()

Check warning on line 145 in src/FishyFlip.Tests/AnonymousTests.cs

View workflow job for this annotation

GitHub Actions / test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 145 in src/FishyFlip.Tests/AnonymousTests.cs

View workflow job for this annotation

GitHub Actions / test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
var daDev = new FacetActorIdentifier(ATHandle.Create("drasticactions.dev")!, ATDid.Create("did:plc:okblbaji7rz243bluudjlgxt")!);
var daJp = new FacetActorIdentifier(ATHandle.Create("drasticactions.jp")!, ATDid.Create("did:plc:okblbaji7rz243bluudjl2bt")!);

var postText = "@drasticactions.dev This is a #test #test of #testing the #FishyFlip #API. https://github.com/drasticactions DAHome. @drasticactions.jp https://github.com/drasticactions/FishyFlip @drasticactions.dev Weee!";
var postHandles = ATHandle.FromPostText(postText);
Assert.IsTrue(postHandles.Length == 2);
Assert.IsTrue(postHandles[0].Handle == "drasticactions.dev");
Assert.IsTrue(postHandles[1].Handle == "drasticactions.jp");

var handleFacets = Facet.ForMentions(postText, new FacetActorIdentifier[] { daDev, daJp });

Assert.IsTrue(handleFacets.Length == 3);
Assert.IsTrue(handleFacets[0].Index!.ByteStart == 0);
Assert.IsTrue(handleFacets[0].Index!.ByteEnd == 19);
Assert.IsTrue(handleFacets[0].Features![0]!.Did! == daDev.Did);

Assert.IsTrue(handleFacets[1].Index!.ByteStart == 117);
Assert.IsTrue(handleFacets[1].Index!.ByteEnd == 135);
Assert.IsTrue(handleFacets[1].Features![0]!.Did! == daJp.Did);

Assert.IsTrue(handleFacets[2].Features![0]!.Did! == daDev.Did);
Assert.IsTrue(handleFacets[2].Index!.ByteStart == 180);
Assert.IsTrue(handleFacets[2].Index!.ByteEnd == 199);

var hashtagFacets = Facet.ForHashtags(postText);
Assert.IsTrue(hashtagFacets.Length == 5);
var uriFacets = Facet.ForUris(postText);
Assert.IsTrue(uriFacets.Length == 2);
var baseUriFacets = Facet.ForUris(postText, "DAHome", "https://github.com/drasticactions");
Assert.IsTrue(baseUriFacets.Length == 1);
var facets = handleFacets.Concat(hashtagFacets).Concat(uriFacets).Concat(baseUriFacets).ToArray();
Assert.IsTrue(facets.Length == 11);
}
}
32 changes: 32 additions & 0 deletions src/FishyFlip/Models/ATHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,38 @@ public static bool TryCreate(string uri, out ATHandle? atHandle)
}
}

/// <summary>
/// Gets the handles from a post text.
/// </summary>
/// <param name="post">Text of the post.</param>
/// <returns>Array of ATHandle.</returns>
public static ATHandle[] FromPostText(string post)
{
var handles = new List<ATHandle>();
var matches = Regex.Matches(post, @"@(?!http)[a-zA-Z0-9][-a-zA-Z0-9_.]{1,}");
foreach (Match match in matches)
{
if (match.Success)
{
var handle = match.Value;
if (handle.StartsWith("@"))
{
handle = handle.Substring(1);
}

if (HandleValidator.EnsureValidHandle(handle))
{
if (!handles.Any(n => n.Handle == handle))
{
handles.Add(new ATHandle(handle));
}
}
}
}

return handles.ToArray();
}

/// <summary>
/// Is the given string a valid ATHandle.
/// </summary>
Expand Down
14 changes: 10 additions & 4 deletions src/FishyFlip/Models/ATWebSocketCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public class ATWebSocketCommit
/// Initializes a new instance of the <see cref="ATWebSocketCommit"/> class.
/// </summary>
/// <param name="rev">The revision identifier.</param>
/// <param name="type">The type of the WebSocket commit.</param>
/// <param name="operation">The type of the WebSocket commit.</param>
/// <param name="collection">The collection name.</param>
/// <param name="rKey">The record key.</param>
/// <param name="record">The record associated with the commit.</param>
/// <param name="cid">The CID associated with the commit.</param>
public ATWebSocketCommit(string? rev, ATWebSocketCommitType type, string? collection, string? rKey, ATRecord? record, ATCid? cid)
public ATWebSocketCommit(string? rev, ATWebSocketCommitType operation, string? collection, string? rKey, ATRecord? record, ATCid? cid)
{
this.Rev = rev;
this.Type = type;
this.Operation = operation;
this.Collection = collection;
this.RKey = rKey;
this.Record = record;
Expand All @@ -36,7 +36,13 @@ public ATWebSocketCommit(string? rev, ATWebSocketCommitType type, string? collec
/// <summary>
/// Gets the type of the WebSocket commit.
/// </summary>
public ATWebSocketCommitType Type { get; }
public ATWebSocketCommitType Operation { get; }

/// <summary>
/// Gets the type of the WebSocket commit.
/// </summary>
[Obsolete("Use Operation instead.")]
public ATWebSocketCommitType Type => this.Operation;

/// <summary>
/// Gets the collection name.
Expand Down
14 changes: 10 additions & 4 deletions src/FishyFlip/Models/ATWebSocketRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public class ATWebSocketRecord
/// <summary>
/// Initializes a new instance of the <see cref="ATWebSocketRecord"/> class.
/// </summary>
/// <param name="type">Type.</param>
/// <param name="kind">Type.</param>
/// <param name="did">Did.</param>
/// <param name="commit">Commit.</param>
/// <param name="identity">Identity.</param>
/// <param name="account">Account.</param>
[JsonConstructor]
public ATWebSocketRecord(ATWebSocketEvent type, ATDid? did, ATWebSocketCommit? commit, ActorIdentity? identity, ActorAccount? account)
public ATWebSocketRecord(ATWebSocketEvent kind, ATDid? did, ATWebSocketCommit? commit, ActorIdentity? identity, ActorAccount? account)
{
this.Type = type;
this.Kind = kind;
this.Did = did;
this.Commit = commit;
this.Identity = identity;
Expand All @@ -30,7 +30,13 @@ public ATWebSocketRecord(ATWebSocketEvent type, ATDid? did, ATWebSocketCommit? c
/// <summary>
/// Gets the Type.
/// </summary>
public ATWebSocketEvent Type { get; }
public ATWebSocketEvent Kind { get; }

/// <summary>
/// Gets the Type.
/// </summary>
[Obsolete("Use Kind instead.")]
public ATWebSocketEvent Type => this.Kind;

/// <summary>
/// Gets the Commit.
Expand Down
Loading

0 comments on commit 4261500

Please sign in to comment.