Skip to content

Commit

Permalink
Repo fixes, remove rule application, and update documentation (#54)
Browse files Browse the repository at this point in the history
This allows checkout of a branch when no commits exists, create a tracked branch, and remove a rule application from a branch. This also update the documentation to have a better quickstart sample.

This fixes #51, #52, #53.
  • Loading branch information
stevenkuhn authored Dec 5, 2019
1 parent ff3f085 commit cbfcf47
Show file tree
Hide file tree
Showing 14 changed files with 798 additions and 257 deletions.
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mode: ContinuousDelivery
next-version: 0.1.0
next-version: 0.2.0
branches: {}
ignore:
sha: []
124 changes: 66 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,88 @@
# Git Storage for InRule
InRuleGitStorage
====

This project adds support for storing and managing InRule rule applications in a custom Git repository.
[![Nuget](https://img.shields.io/nuget/vpre/Sknet.InRuleGitStorage)](https://www.nuget.org/packages/Sknet.InRuleGitStorage)

## Getting Started
This project allows you to store and manage your [InRule](https://www.inrule.com/)® business rules in a Git repository as an alternative to the built-in support of the file system and irCatalog.

### Installing
# Features

- Initialize a new InRule git repository
- Open an existing InRule git repository
- Clone, pull from, and push to a remote InRule git repository
- Create, remove, and checkout a branch
- Commit (serialize a `RuleApplicationDef` into a git commit)
- Merge branches (_merge conflict support is a work in progress_)
- Get rule application (deserialize the current branch into a `RuleApplicationDef`)
- Get a list of rule applications

# Quickstart

## Installing

```powershell
Install-Package Sknet.InRuleGitStorage -IncludePrerelease
```

## Usage

### Create a new repository
```csharp
InRuleGitRepository.Init(@"C:\path\to\your\repo");
```batch
dotnet add package Sknet.InRuleGitStorage --version 0.2.0
```

### Create your first commit
```csharp
using (var repo = InRuleGitRepository.Open(@"C:\path\to\your\repo"))
{
var ruleAppDef = new RuleApplicationDef("MyRuleApp");
## Basic example

var identity = new Identity("Alex Doe", "[email protected]");
var signature = new Signature(identity, DateTimeOffset.Now);
repo.Commit(ruleAppDef, "My first commit", signature, signature);
}
```

### Get a rule application from the current branch
```csharp
using (var repo = InRuleGitRepository.Open(@"C:\path\to\your\repo"))
// Create a new repository in a local directory
InRuleGitRepository.Init("/path/to/local/repo");

// Get a new instance of your local InRule Git repository
using (var repo = InRuleGitRepository.Open("/path/to/local/repo"))
{
var ruleAppDef = repo.GetRuleApplication("MyRuleApp");
// Create a new rule application and commit it to the "master" branch
var ruleApp = new RuleApplicationDef("QuickstartSample");
repo.Commit(ruleApp, "Add quickstart sample rule application");

// Get the rule application from the Git repository
ruleApp = repo.GetRuleApplication("QuickstartSample");
}
```

## Examples

### Create multiple commits across different branches
## Remote repository example

```csharp
var repoPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"MyInRuleRepository");

var identity = new Identity("John Doe", "[email protected]");
// Clone the public samples repository to a local directory
InRuleGitRepository.Clone(
sourceUrl: "https://github.com/stevenkuhn/InRuleGitStorage-Samples.git",
destinationPath: "/path/to/local/repo");

// Create a repository in the current user's _My Documents_ folder
InRuleGitRepository.Init(repoPath);
using (var repo = InRuleGitRepository.Open(repoPath))
// Get a new instance of your local InRule Git repository
using (var repo = InRuleGitRepository.Open("/path/to/local/repo"))
{
// Update the rule application and create commits in `master`.
var ruleAppDef = new RuleApplicationDef("MyRuleApp");
var entityDef = ruleAppDef.Entities.Add(new EntityDef("MyEntity"));

repo.Commit(ruleAppDef, "My first commit",
new Signature(identity, DateTimeOffset.Now),
new Signature(identity, DateTimeOffset.Now));

entityDef.Fields.Add(new FieldDef("MyField1", DataType.String));

repo.Commit(ruleAppDef, "My second commit",
new Signature(identity, DateTimeOffset.Now),
new Signature(identity, DateTimeOffset.Now));

// Create a new branch called `my-new-branch` and set it as the current branch.
repo.CreateBranch("my-new-branch");
repo.Checkout("my-new-branch");
entityDef.Fields.Add(new FieldDef("MyField2", DataType.String));
entityDef.Fields.Add(new FieldDef("MyField3", DataType.Integer));

// Update the rule application and commit the change to `my-new-branch`.
repo.Commit(ruleAppDef, "My third commit",
new Signature(identity, DateTimeOffset.Now),
new Signature(identity, DateTimeOffset.Now));
// Create a local branch that is tracked to the remote "v0.2.0" branch
repo.CreateTrackedBranch("v0.2.0", "origin");

// Switch the current branch to the newly created tracked branch
repo.Checkout("v0.2.0");

// Create a local branch from the "v0.2.0" branch
repo.CreateBranch("invoice-date-field");

// Switch the current branch to the newly created local branch
repo.Checkout("invoice-date-field");

// Get the InvoiceSample rule application from the repository, add an invoice date
// field, and commit that change to the current branch
var ruleApp = repo.GetRuleApplication("InvoiceSample");
ruleApp.Entities["Invoice"].Fields.Add(new FieldDef("Date", DataType.DateTime));
repo.Commit(ruleApp, "Add invoice date field");

// Switch back to the previous branch that does not have the field change
repo.Checkout("v0.2.0");

// Merge the invoice date field change into the current branch
repo.Merge("invoice-date-field");

// Delete the original branch containing the invoice date field change since the
// change now exists in the "v0.2.0" branch
repo.RemoveBranch("invoice-date-field");
}
```
2 changes: 1 addition & 1 deletion docs/coverpage.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![logo](assets/img/logo.svg ':size=200')

# InRuleGitStorage<small>0.1.0</small>
# InRuleGitStorage<small>0.2.0</small>

>Store and manage your <a href="https://www.inrule.com/" style="text-decoration: underline rgba(51, 51, 51, 0.2);">InRule</a>® business rules in a Git repository.
Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Git Storage for InRule</title>
<title>Sknet.InRuleGitStorage</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="Description">
<meta name="description" content="Sknet.InRuleGitStorage is a library for storing and managing InRule® business rules in a Git repository.">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple.css">

Expand Down
6 changes: 3 additions & 3 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ InRuleGitStorage is a NuGet package that can be installed using a package instal
## Package Manager

```powershell
PM> Install-Package Sknet.InRuleGitStorage -Version 0.1.0
PM> Install-Package Sknet.InRuleGitStorage -Version 0.2.0
```

## .NET CLI

```batch
dotnet add package Sknet.InRuleGitStorage --version 0.1.0
dotnet add package Sknet.InRuleGitStorage --version 0.2.0
```

## Package Reference

```xml
<PackageReference Include="Sknet.InRuleGitStorage" Version="0.1.0" />
<PackageReference Include="Sknet.InRuleGitStorage" Version="0.2.0" />
```
60 changes: 60 additions & 0 deletions docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,63 @@ This project allows you to store and manage your [InRule](https://www.inrule.com
- Get rule application (deserialize the current branch into a `RuleApplicationDef`)
- Get a list of rule applications

## Quickstart

### Basic example

```csharp
// Create a new repository in a local directory
InRuleGitRepository.Init("/path/to/local/repo");

// Get a new instance of your local InRule Git repository
using (var repo = InRuleGitRepository.Open("/path/to/local/repo"))
{
// Create a new rule application and commit it to the "master" branch
var ruleApp = new RuleApplicationDef("QuickstartSample");
repo.Commit(ruleApp, "Add quickstart sample rule application");

// Get the rule application from the Git repository
ruleApp = repo.GetRuleApplication("QuickstartSample");
}
```

### Remote repository example

```csharp
// Clone the public samples repository to a local directory
InRuleGitRepository.Clone(
sourceUrl: "https://github.com/stevenkuhn/InRuleGitStorage-Samples.git",
destinationPath: "/path/to/local/repo");

// Get a new instance of your local InRule Git repository
using (var repo = InRuleGitRepository.Open("/path/to/local/repo"))
{
// Create a local branch that is tracked to the remote "v0.2.0" branch
repo.CreateBranch("v0.2.0", "origin");

// Switch the current branch to the newly created tracked branch
repo.Checkout("v0.2.0");

// Create a local branch from the "v0.2.0" branch
repo.CreateBranch("invoice-date-field");

// Switch the current branch to the newly created local branch
repo.Checkout("invoice-date-field");

// Get the InvoiceSample rule application from the repository, add an invoice date
// field, and commit that change to the current branch
var ruleApp = repo.GetRuleApplication("InvoiceSample");
ruleApp.Entities["Invoice"].Fields.Add(new FieldDef("Date", DataType.DateTime));
repo.Commit(ruleApp, "Add invoice date field");

// Switch back to the previous branch that does not have the field change
repo.Checkout("v0.2.0");

// Merge the invoice date field change into the current branch
repo.Merge("invoice-date-field");

// Delete the original branch containing the invoice date field change since the
// change now exists in the "v0.2.0" branch
repo.RemoveBranch("invoice-date-field");
}
```
Loading

0 comments on commit cbfcf47

Please sign in to comment.