Skip to content

Commit

Permalink
Rename package to CodeOwners (#9)
Browse files Browse the repository at this point in the history
rebranding
  • Loading branch information
vhatsura authored Jul 25, 2022
1 parent 32bb3b0 commit aad576a
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 78 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CodeOwners Parser
# CodeOwners

![GitHub Actions Badge](https://github.com/vhatsura/codeowners-parser/actions/workflows/continuous.integration.yml/badge.svg)
[![NuGet Badge](https://buildstats.info/nuget/CodeOwnersParser)](https://www.nuget.org/packages/CodeOwnersParser/)
![GitHub Actions Badge](https://github.com/vhatsura/codeowners/actions/workflows/continuous.integration.yml/badge.svg)
[![NuGet Badge](https://buildstats.info/nuget/CodeOwners)](https://www.nuget.org/packages/CodeOwners/)

## Installation

Expand All @@ -14,13 +14,12 @@ Install-Package CodeOwnersParser
```csharp
using CodeOwners;

CodeOwnersParser.Parse("* @global-owner1 @global-owner2");
IEnumerable<CodeOwnersEntry> entries = CodeOwnersSerializer.Deserialize("* @global-owner1 @global-owner2");

string content = CodeOwnersSerializer.Serialize(entries);
```

## Roadmap

* [X] Parse method
* [X] Benchmark
* [ ] IsValid method
* [ ] GitLab support
* [ ] Continuous Integration
19 changes: 19 additions & 0 deletions benchmarks/CodeOwners.Benchmarks/CodeOwners.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.1"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\CodeOwners\CodeOwners.csproj"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace CodeOwners.Benchmarks;

[MemoryDiagnoser]
public class CodeOwnersParserBenchmark
public class CodeOwnersSerializerBenchmark
{
private readonly string _oneLine = "* @global-owner";

Expand Down Expand Up @@ -64,8 +64,8 @@ public class CodeOwnersParserBenchmark
/apps/github";

[Benchmark]
public IList<CodeOwnersEntry> OneLine() => CodeOwnersParser.Parse(_oneLine).ToList();
public IList<CodeOwnersEntry> OneLine() => CodeOwnersSerializer.Deserialize(_oneLine).ToList();

[Benchmark]
public IList<CodeOwnersEntry> MultiLine() => CodeOwnersParser.Parse(_multiLine).ToList();
public IList<CodeOwnersEntry> MultiLine() => CodeOwnersSerializer.Deserialize(_multiLine).ToList();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BenchmarkDotNet.Running;
using CodeOwners.Benchmarks;

BenchmarkRunner.Run<CodeOwnersParserBenchmark>();
BenchmarkRunner.Run<CodeOwnersSerializerBenchmark>();

This file was deleted.

6 changes: 3 additions & 3 deletions codeowners-parser.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeOwnersParser", "src\CodeOwnersParser\CodeOwnersParser.csproj", "{3280E767-7294-4865-A1AE-9F94D3571929}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeOwners", "src\CodeOwners\CodeOwners.csproj", "{3280E767-7294-4865-A1AE-9F94D3571929}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeOwnersParser.Tests", "tests\CodeOwnersParser.Tests\CodeOwnersParser.Tests.csproj", "{5534E36E-2362-4940-B49E-7E19C3FD446E}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeOwners.Tests", "tests\CodeOwners.Tests\CodeOwners.Tests.csproj", "{5534E36E-2362-4940-B49E-7E19C3FD446E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeOwnersParser.Benchmarks", "benchmarks\CodeOwnersParser.Benchmarks\CodeOwnersParser.Benchmarks.csproj", "{33FA15AD-8517-487F-95F3-FE4919ECF1DF}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeOwners.Benchmarks", "benchmarks\CodeOwners.Benchmarks\CodeOwners.Benchmarks.csproj", "{33FA15AD-8517-487F-95F3-FE4919ECF1DF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
<Nullable>enable</Nullable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Authors>Vadim Hatsura</Authors>
<Description>The parser for CODEOWNERS file.</Description>
<PackageTags>codeowners, github, parser</PackageTags>
<Description>The serializer for CODEOWNERS format.</Description>
<PackageTags>codeowners, github, serializer</PackageTags>
<Copyright>Copyright (c) 2022 - Present</Copyright>
<PackageProjectUrl>https://github.com/vhatsura/codeowners-parser</PackageProjectUrl>
<RepositoryUrl>https://github.com/vhatsura/codeowners-parser</RepositoryUrl>
<PackageProjectUrl>https://github.com/vhatsura/codeowners</PackageProjectUrl>
<RepositoryUrl>https://github.com/vhatsura/codeowners</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>All</AnalysisMode>
<AnalysisLevel>latest</AnalysisLevel>
<RootNamespace>CodeOwners</RootNamespace>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ namespace CodeOwners;
public record CodeOwnersEntry(string Pattern, IList<string> Owners);

/// <summary>
/// The parser for CODEOWNERS format
/// The serializer for CODEOWNERS format
/// </summary>
public static class CodeOwnersParser
public static class CodeOwnersSerializer
{
/// <summary>
/// Parses CODEOWNERS content
/// Deserializes CODEOWNERS content
/// </summary>
/// <param name="content">The content in CODEOWNERS format</param>
/// <returns>The list of CODEOWNERS entries</returns>
/// <exception cref="ArgumentNullException">The <paramref name="content"/> is null</exception>
public static IEnumerable<CodeOwnersEntry> Parse(string content)
public static IEnumerable<CodeOwnersEntry> Deserialize(string content)
{
if (content == null)
throw new ArgumentNullException(nameof(content));
Expand All @@ -38,6 +38,28 @@ public static IEnumerable<CodeOwnersEntry> Parse(string content)
}
}

/// <summary>
/// Serializes codeowners entries to CODEOWNERS content
/// </summary>
/// <param name="entries">Codeowners entries</param>
/// <returns>The content in CODEOWNERS format</returns>
public static string Serialize(IEnumerable<CodeOwnersEntry> entries)
{
if (entries == null)
throw new ArgumentNullException(nameof(entries));

var stringBuilder = new StringBuilder();

foreach (var entry in entries)
{
#pragma warning disable CA1305
stringBuilder.AppendLine($"{entry.Pattern} {string.Join(" ", entry.Owners)}");
#pragma warning restore CA1305
}

return stringBuilder.ToString();
}

private static CodeOwnersEntry? ParseLine(StringLexer lexer, StringBuilder stringBuilder)
{
while (!lexer.EndOfLine)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions tests/CodeOwners.Tests/CodeOwners.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>

</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.7.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0"/>
<PackageReference Include="Snapshooter.Xunit" Version="0.7.1"/>
<PackageReference Include="xunit" Version="2.4.1"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\CodeOwners\CodeOwners.csproj"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
using FluentAssertions;
using Snapshooter.Xunit;
using Xunit;

namespace CodeOwners.Tests;

public class CodeOwnersParserTests
public class CodeOwnersSerializerTests
{
public static IEnumerable<object[]> CorrectData
{
Expand Down Expand Up @@ -66,17 +67,18 @@ public static IEnumerable<object[]> CorrectData

[Theory]
[MemberData(nameof(CorrectData))]
public void Parse_ShouldParseContentCorrectly(string content, IEnumerable<CodeOwnersEntry> expectedResult)
public void Deserialize_ShouldDeserializeContentCorrectly(string content,
IEnumerable<CodeOwnersEntry> expectedResult)
{
// Arrange + Act
var result = CodeOwnersParser.Parse(content);
var result = CodeOwnersSerializer.Deserialize(content);

// Assert
result.Should().BeEquivalentTo(expectedResult);
}

[Fact]
public void Parse_ShouldParseMultiLineContentCorrectly()
public void Deserialize_ShouldDeserializeMultiLineContentCorrectly()
{
// Arrange
var content = @"# This is a comment.
Expand Down Expand Up @@ -135,7 +137,7 @@ public void Parse_ShouldParseMultiLineContentCorrectly()
/apps/github";

// Act
var result = CodeOwnersParser.Parse(content);
var result = CodeOwnersSerializer.Deserialize(content);

// Assert
result.Should().BeEquivalentTo(new List<CodeOwnersEntry>
Expand All @@ -153,4 +155,38 @@ public void Parse_ShouldParseMultiLineContentCorrectly()
new("/apps/github", new List<string>())
});
}


[Fact]
public void Serialize_ShouldSerializeOneLineContentCorrectly()
{
// Arrange
var codeOwners =
new List<CodeOwnersEntry> { new("*", new List<string> { "@global-owner1", "@global-owner2" }) };

// Act
var result = CodeOwnersSerializer.Serialize(codeOwners);

// Assert
result.MatchSnapshot();
}

[Fact]
public void Serialize_ShouldSerializeMultiLineContentCorrectly()
{
// Arrange
var codeOwners =
new List<CodeOwnersEntry>
{
new("*", new List<string> { "@global-owner1", "@global-owner2" }),
new("*.js", new List<string> { "@js-owner" }),
new("*.go", new List<string> { "[email protected]" }),
};

// Act
var result = CodeOwnersSerializer.Serialize(codeOwners);

// Assert
result.MatchSnapshot();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* @global-owner1 @global-owner2
*.js @js-owner
*.go docs@example.com
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @global-owner1 @global-owner2
30 changes: 0 additions & 30 deletions tests/CodeOwnersParser.Tests/CodeOwnersParser.Tests.csproj

This file was deleted.

0 comments on commit aad576a

Please sign in to comment.