Skip to content

Commit

Permalink
Feature/restore command (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
matzefriedrich authored Apr 19, 2024
1 parent 38595f8 commit eee7534
Show file tree
Hide file tree
Showing 62 changed files with 1,327 additions and 257 deletions.
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.0-alpha1.240419.1] - 2024-04-19

### Added
- [PR #6] Adds the `restore` command that can restore referenced Git repositories and output packages. (#5)

### Changed
- The functionality required to clone and build projects got refactored; service types for common tasks have been added and are now utilized by the `add` and `restore` commands. (#5)
- The tool can now look up the workspace configuration file `.nugit` in the current working directory or parent directories. Commands that require workspace information can now be used from any directory within the repository tree.
- Because lots of things require IO, from now on `System.IO.Abstractions` is used to make IO acess testable
- Support of implicit usings got disabled (namespace imports indicate dependencies and we wanna see them)

### Fixed
- Removes `REQUIRED` constraint from several boolean command-line flags. Opt-in flags are `false` by default, and get set to `true` if specified.

## [0.1.0-alpha1.240417.1] - 2024-04-17

This is the first pre-release version that comes with a basic set of features.

### Added
- [PR #1] Adds the `env` command that lists configuration values
- [PR #2] Adds the `init` command that can create a new workspace and the local NuGet feed.
- [PR #3] Add the `add` command that can clone repositories, find compatible .NET projects. It uses the `dotnet pack` command to build NuGet packages.
- [PR #4] Adds a bunch of tests
- The application can be packed and installed locally as a pre-release version and integrates nicely with the `dotnet` CLI.
51 changes: 39 additions & 12 deletions src/dotnet.nugit.Resources/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

142 changes: 122 additions & 20 deletions src/dotnet.nugit.Resources/Resources.resx
Original file line number Diff line number Diff line change
@@ -1,24 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">

</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ArgumentException_Value_cannot_be_null_or_whitespace" xml:space="preserve">
<value>Value cannot be null or whitespace.</value>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ArgumentException_Value_cannot_be_null_or_whitespace" xml:space="preserve">
<value>Value cannot be null or whitespace.</value>
</data>
<data name="Program_Help_description" xml:space="preserve">
<value>Build NuGet packages from GitHub and integrate them seamlessly.</value>
</data>
</root>
51 changes: 36 additions & 15 deletions src/dotnet.nugit.UnitTest/AddPackagesFromRepositoryCommandTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,72 @@ namespace dotnet.nugit.UnitTest
{
using Abstractions;
using Commands;
using LibGit2Sharp;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Services.Tasks;
using static Commands.ExitCodes;

public class AddPackagesFromRepositoryCommandTest
{
[Fact]
public async Task AddPackagesFromRepositoryCommand_ProcessRepositoryAsync_Test()
public async Task AddPackagesFromRepositoryCommand_ProcessRepositoryAsync_does_not_process_tags_if_head_only_specified_Test()
{
// Arrange
const string repositoryReference = "[email protected]:/owner/repo.git";
var feed = new LocalFeedInfo { Name = "TestFeed", LocalPath = "/tmp/this-path-does-not-exist" };

var feedService = new Mock<INuGetFeedService>();
var feedService = new Mock<INuGetFeedConfigurationService>();
feedService
.Setup(service => service.GetConfiguredLocalFeedAsync(It.IsAny<CancellationToken>()))
.ReturnsAsync(() => feed)
.Verifiable();

var findFilesService = new Mock<IFindFilesService>();
var dotnetUtility = new Mock<IDotNetUtility>();
var workspace = new Mock<INugitWorkspace>();

var git = new Mock<ILibGit2SharpAdapter>();
git
.Setup(adapter => adapter.TryCloneRepository(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()))
.Returns(true)
var repositoryMock = new Mock<IRepository>();
repositoryMock.SetupGet(repository => repository.Refs).Verifiable();

var openRepositoryMock = new Mock<IOpenRepositoryTask>();
openRepositoryMock
.Setup(task => task.OpenRepository(feed, It.IsAny<RepositoryUri>(), It.IsAny<TimeSpan?>(), true))
.Returns(repositoryMock.Object)
.Verifiable();

var buildPackagesTaskMock = new Mock<IBuildRepositoryPackagesTask>();
buildPackagesTaskMock
.Setup(task => task.BuildRepositoryPackagesAsync(It.IsAny<RepositoryReference>(), feed, repositoryMock.Object, null, null, It.IsAny<CancellationToken>()))
.Verifiable();

var sut = new AddPackagesFromRepositoryCommand(
feedService.Object,
findFilesService.Object,
dotnetUtility.Object,
workspace.Object,
git.Object,
OpenRepositoryTaskFactory,
BuildPackagesTaskFactory,
new NullLogger<AddPackagesFromRepositoryCommand>());

const string repositoryReference = "[email protected]:/owner/repo.git";
const bool headOnly = true;

// Act
int exitCode = await sut.ProcessRepositoryAsync(repositoryReference, true, CancellationToken.None);
int exitCode = await sut.ProcessRepositoryAsync(repositoryReference, headOnly, CancellationToken.None);

// Assert
Assert.Equal(ErrCannotOpen, exitCode);
Assert.Equal(Ok, exitCode);

openRepositoryMock.Verify(task => task.OpenRepository(feed, It.IsAny<RepositoryUri>(), It.IsAny<TimeSpan?>(), true), Times.Once);
buildPackagesTaskMock.Verify(task => task.BuildRepositoryPackagesAsync(It.IsAny<RepositoryReference>(), feed, repositoryMock.Object, null, null, It.IsAny<CancellationToken>()), Times.Once);
repositoryMock.VerifyGet(repository => repository.Refs, Times.Never);
return;

IBuildRepositoryPackagesTask BuildPackagesTaskFactory()
{
return buildPackagesTaskMock.Object;
}

git.Verify(adapter => adapter.TryCloneRepository(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<CancellationToken>()), Times.Once);
IOpenRepositoryTask OpenRepositoryTaskFactory()
{
return openRepositoryMock.Object;
}
}
}
}
Loading

0 comments on commit eee7534

Please sign in to comment.