Skip to content

Commit cbfcf47

Browse files
authored
Repo fixes, remove rule application, and update documentation (#54)
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.
1 parent ff3f085 commit cbfcf47

File tree

14 files changed

+798
-257
lines changed

14 files changed

+798
-257
lines changed

GitVersion.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mode: ContinuousDelivery
2-
next-version: 0.1.0
2+
next-version: 0.2.0
33
branches: {}
44
ignore:
55
sha: []

README.md

Lines changed: 66 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,88 @@
1-
# Git Storage for InRule
1+
InRuleGitStorage
2+
====
23

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

5-
## Getting Started
6+
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.
67

7-
### Installing
8+
# Features
9+
10+
- Initialize a new InRule git repository
11+
- Open an existing InRule git repository
12+
- Clone, pull from, and push to a remote InRule git repository
13+
- Create, remove, and checkout a branch
14+
- Commit (serialize a `RuleApplicationDef` into a git commit)
15+
- Merge branches (_merge conflict support is a work in progress_)
16+
- Get rule application (deserialize the current branch into a `RuleApplicationDef`)
17+
- Get a list of rule applications
18+
19+
# Quickstart
20+
21+
## Installing
822

923
```powershell
1024
Install-Package Sknet.InRuleGitStorage -IncludePrerelease
1125
```
1226

13-
## Usage
14-
15-
### Create a new repository
16-
```csharp
17-
InRuleGitRepository.Init(@"C:\path\to\your\repo");
27+
```batch
28+
dotnet add package Sknet.InRuleGitStorage --version 0.2.0
1829
```
1930

20-
### Create your first commit
21-
```csharp
22-
using (var repo = InRuleGitRepository.Open(@"C:\path\to\your\repo"))
23-
{
24-
var ruleAppDef = new RuleApplicationDef("MyRuleApp");
31+
## Basic example
2532

26-
var identity = new Identity("Alex Doe", "alex.doe@example.org");
27-
var signature = new Signature(identity, DateTimeOffset.Now);
28-
repo.Commit(ruleAppDef, "My first commit", signature, signature);
29-
}
30-
```
31-
32-
### Get a rule application from the current branch
3333
```csharp
34-
using (var repo = InRuleGitRepository.Open(@"C:\path\to\your\repo"))
34+
// Create a new repository in a local directory
35+
InRuleGitRepository.Init("/path/to/local/repo");
36+
37+
// Get a new instance of your local InRule Git repository
38+
using (var repo = InRuleGitRepository.Open("/path/to/local/repo"))
3539
{
36-
var ruleAppDef = repo.GetRuleApplication("MyRuleApp");
40+
// Create a new rule application and commit it to the "master" branch
41+
var ruleApp = new RuleApplicationDef("QuickstartSample");
42+
repo.Commit(ruleApp, "Add quickstart sample rule application");
43+
44+
// Get the rule application from the Git repository
45+
ruleApp = repo.GetRuleApplication("QuickstartSample");
3746
}
3847
```
3948

40-
## Examples
41-
42-
### Create multiple commits across different branches
49+
## Remote repository example
4350

4451
```csharp
45-
var repoPath = Path.Combine(
46-
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
47-
"MyInRuleRepository");
48-
49-
var identity = new Identity("John Doe", "john.doe@example.org");
52+
// Clone the public samples repository to a local directory
53+
InRuleGitRepository.Clone(
54+
sourceUrl: "https://github.com/stevenkuhn/InRuleGitStorage-Samples.git",
55+
destinationPath: "/path/to/local/repo");
5056

51-
// Create a repository in the current user's _My Documents_ folder
52-
InRuleGitRepository.Init(repoPath);
53-
using (var repo = InRuleGitRepository.Open(repoPath))
57+
// Get a new instance of your local InRule Git repository
58+
using (var repo = InRuleGitRepository.Open("/path/to/local/repo"))
5459
{
55-
// Update the rule application and create commits in `master`.
56-
var ruleAppDef = new RuleApplicationDef("MyRuleApp");
57-
var entityDef = ruleAppDef.Entities.Add(new EntityDef("MyEntity"));
58-
59-
repo.Commit(ruleAppDef, "My first commit",
60-
new Signature(identity, DateTimeOffset.Now),
61-
new Signature(identity, DateTimeOffset.Now));
62-
63-
entityDef.Fields.Add(new FieldDef("MyField1", DataType.String));
64-
65-
repo.Commit(ruleAppDef, "My second commit",
66-
new Signature(identity, DateTimeOffset.Now),
67-
new Signature(identity, DateTimeOffset.Now));
68-
69-
// Create a new branch called `my-new-branch` and set it as the current branch.
70-
repo.CreateBranch("my-new-branch");
71-
repo.Checkout("my-new-branch");
72-
entityDef.Fields.Add(new FieldDef("MyField2", DataType.String));
73-
entityDef.Fields.Add(new FieldDef("MyField3", DataType.Integer));
74-
75-
// Update the rule application and commit the change to `my-new-branch`.
76-
repo.Commit(ruleAppDef, "My third commit",
77-
new Signature(identity, DateTimeOffset.Now),
78-
new Signature(identity, DateTimeOffset.Now));
60+
// Create a local branch that is tracked to the remote "v0.2.0" branch
61+
repo.CreateTrackedBranch("v0.2.0", "origin");
62+
63+
// Switch the current branch to the newly created tracked branch
64+
repo.Checkout("v0.2.0");
65+
66+
// Create a local branch from the "v0.2.0" branch
67+
repo.CreateBranch("invoice-date-field");
68+
69+
// Switch the current branch to the newly created local branch
70+
repo.Checkout("invoice-date-field");
71+
72+
// Get the InvoiceSample rule application from the repository, add an invoice date
73+
// field, and commit that change to the current branch
74+
var ruleApp = repo.GetRuleApplication("InvoiceSample");
75+
ruleApp.Entities["Invoice"].Fields.Add(new FieldDef("Date", DataType.DateTime));
76+
repo.Commit(ruleApp, "Add invoice date field");
77+
78+
// Switch back to the previous branch that does not have the field change
79+
repo.Checkout("v0.2.0");
80+
81+
// Merge the invoice date field change into the current branch
82+
repo.Merge("invoice-date-field");
83+
84+
// Delete the original branch containing the invoice date field change since the
85+
// change now exists in the "v0.2.0" branch
86+
repo.RemoveBranch("invoice-date-field");
7987
}
8088
```

docs/coverpage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![logo](assets/img/logo.svg ':size=200')
22

3-
# InRuleGitStorage<small>0.1.0</small>
3+
# InRuleGitStorage<small>0.2.0</small>
44

55
>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.
66

docs/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
5-
<title>Git Storage for InRule</title>
5+
<title>Sknet.InRuleGitStorage</title>
66
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
7-
<meta name="description" content="Description">
7+
<meta name="description" content="Sknet.InRuleGitStorage is a library for storing and managing InRule® business rules in a Git repository.">
88
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
99
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple.css">
1010

docs/installation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ InRuleGitStorage is a NuGet package that can be installed using a package instal
55
## Package Manager
66

77
```powershell
8-
PM> Install-Package Sknet.InRuleGitStorage -Version 0.1.0
8+
PM> Install-Package Sknet.InRuleGitStorage -Version 0.2.0
99
```
1010

1111
## .NET CLI
1212

1313
```batch
14-
dotnet add package Sknet.InRuleGitStorage --version 0.1.0
14+
dotnet add package Sknet.InRuleGitStorage --version 0.2.0
1515
```
1616

1717
## Package Reference
1818

1919
```xml
20-
<PackageReference Include="Sknet.InRuleGitStorage" Version="0.1.0" />
20+
<PackageReference Include="Sknet.InRuleGitStorage" Version="0.2.0" />
2121
```

docs/introduction.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,63 @@ This project allows you to store and manage your [InRule](https://www.inrule.com
1515
- Get rule application (deserialize the current branch into a `RuleApplicationDef`)
1616
- Get a list of rule applications
1717

18+
## Quickstart
19+
20+
### Basic example
21+
22+
```csharp
23+
// Create a new repository in a local directory
24+
InRuleGitRepository.Init("/path/to/local/repo");
25+
26+
// Get a new instance of your local InRule Git repository
27+
using (var repo = InRuleGitRepository.Open("/path/to/local/repo"))
28+
{
29+
// Create a new rule application and commit it to the "master" branch
30+
var ruleApp = new RuleApplicationDef("QuickstartSample");
31+
repo.Commit(ruleApp, "Add quickstart sample rule application");
32+
33+
// Get the rule application from the Git repository
34+
ruleApp = repo.GetRuleApplication("QuickstartSample");
35+
}
36+
```
37+
38+
### Remote repository example
39+
40+
```csharp
41+
// Clone the public samples repository to a local directory
42+
InRuleGitRepository.Clone(
43+
sourceUrl: "https://github.com/stevenkuhn/InRuleGitStorage-Samples.git",
44+
destinationPath: "/path/to/local/repo");
45+
46+
// Get a new instance of your local InRule Git repository
47+
using (var repo = InRuleGitRepository.Open("/path/to/local/repo"))
48+
{
49+
// Create a local branch that is tracked to the remote "v0.2.0" branch
50+
repo.CreateBranch("v0.2.0", "origin");
51+
52+
// Switch the current branch to the newly created tracked branch
53+
repo.Checkout("v0.2.0");
54+
55+
// Create a local branch from the "v0.2.0" branch
56+
repo.CreateBranch("invoice-date-field");
57+
58+
// Switch the current branch to the newly created local branch
59+
repo.Checkout("invoice-date-field");
60+
61+
// Get the InvoiceSample rule application from the repository, add an invoice date
62+
// field, and commit that change to the current branch
63+
var ruleApp = repo.GetRuleApplication("InvoiceSample");
64+
ruleApp.Entities["Invoice"].Fields.Add(new FieldDef("Date", DataType.DateTime));
65+
repo.Commit(ruleApp, "Add invoice date field");
66+
67+
// Switch back to the previous branch that does not have the field change
68+
repo.Checkout("v0.2.0");
69+
70+
// Merge the invoice date field change into the current branch
71+
repo.Merge("invoice-date-field");
72+
73+
// Delete the original branch containing the invoice date field change since the
74+
// change now exists in the "v0.2.0" branch
75+
repo.RemoveBranch("invoice-date-field");
76+
}
77+
```

0 commit comments

Comments
 (0)