Skip to content

Commit

Permalink
fix publish script type mapping, add extension methods to Index types
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Feb 29, 2024
1 parent e8364ee commit e70323b
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 3 deletions.
14 changes: 12 additions & 2 deletions scripts/publish-pending-packages.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@ type AVPRClient.ValidationPackage with
p.PatchVersion <- i.Metadata.PatchVersion
p.PackageContent <- File.ReadAllBytes(i.RepoPath)
p.ReleaseDate <- DateTimeOffset.Now
p.Tags <- i.Metadata.Tags
p.Tags <- (
i.Metadata.Tags
|> Array.map (fun tag ->
let t = AVPRClient.OntologyAnnotation()
t.Name <- tag.Name
t.TermAccessionNumber <- tag.TermAccessionNumber
t.TermSourceREF <- tag.TermSourceREF
t
)
)
p.ReleaseNotes <- i.Metadata.ReleaseNotes
p.Authors <-
p.Authors <- (
i.Metadata.Authors
|> Array.map (fun author ->
let a = AVPRClient.Author()
Expand All @@ -59,6 +68,7 @@ type AVPRClient.ValidationPackage with
a.AffiliationLink <- author.AffiliationLink
a
)
)
p

static member toJson (p: AVPRClient.ValidationPackage) =
Expand Down
6 changes: 5 additions & 1 deletion src/AVPRClient/AVPRClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
<RepositoryType>git</RepositoryType>
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/RELEASE_NOTES.md"))</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageVersion>0.0.2</PackageVersion>
<PackageVersion>0.0.3</PackageVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AVPRIndex\AVPRIndex.fsproj" />
</ItemGroup>

</Project>
94 changes: 94 additions & 0 deletions src/AVPRClient/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using AVPRIndex;
using YamlDotNet.Core.Tokens;
using static AVPRIndex.Domain;

namespace AVPRClient
{
public static class Extensions
{
public static AVPRClient.ValidationPackage toValidationPackage(
this AVPRIndex.Domain.ValidationPackageIndex indexedPackage,
DateTimeOffset releaseDate
)
{
return new AVPRClient.ValidationPackage
{
Name = indexedPackage.Metadata.Name,
Description = indexedPackage.Metadata.Description,
MajorVersion = indexedPackage.Metadata.MajorVersion,
MinorVersion = indexedPackage.Metadata.MinorVersion,
PatchVersion = indexedPackage.Metadata.PatchVersion,
PackageContent = File.ReadAllBytes(indexedPackage.RepoPath),
ReleaseDate = releaseDate,
Tags =
indexedPackage.Metadata.Tags
.Select(tag =>
{
return new AVPRClient.OntologyAnnotation
{
Name = tag.Name,
TermAccessionNumber = tag.TermAccessionNumber,
TermSourceREF = tag.TermSourceREF
};
})
.ToList(),
ReleaseNotes = indexedPackage.Metadata.ReleaseNotes,
Authors =
indexedPackage.Metadata.Authors
.Select(author =>
{
return new AVPRClient.Author
{
FullName = author.FullName,
Email = author.Email,
Affiliation = author.Affiliation,
AffiliationLink = author.AffiliationLink
};
})
.ToList()
};
}

public static AVPRClient.ValidationPackage toValidationPackage(
this AVPRIndex.Domain.ValidationPackageIndex indexedPackage
)
{
return indexedPackage.toValidationPackage(DateTimeOffset.Now);
}

public static AVPRClient.PackageContentHash toPackageContentHash(
this AVPRIndex.Domain.ValidationPackageIndex indexedPackage,
bool HashFileDirectly = false
)
{
if ( HashFileDirectly)
{
MD5 md5 = MD5.Create();
return new AVPRClient.PackageContentHash
{
Hash = Convert.ToHexString(md5.ComputeHash(File.ReadAllBytes(indexedPackage.RepoPath))),
PackageMajorVersion = indexedPackage.Metadata.MajorVersion,
PackageMinorVersion = indexedPackage.Metadata.MinorVersion,
PackagePatchVersion = indexedPackage.Metadata.PatchVersion
};
}
else
{
return new AVPRClient.PackageContentHash
{
Hash = indexedPackage.ContentHash,
PackageMajorVersion = indexedPackage.Metadata.MajorVersion,
PackageMinorVersion = indexedPackage.Metadata.MinorVersion,
PackagePatchVersion = indexedPackage.Metadata.PatchVersion
};
}
}
}
}
4 changes: 4 additions & 0 deletions src/AVPRClient/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## v0.0.3

- Add extensions that connect AVPRIndex and AVPRClient types

## v0.0.2

- Regen with for additional metadata fields
Expand Down

0 comments on commit e70323b

Please sign in to comment.