|
1 | | -# Git Storage for InRule |
| 1 | +InRuleGitStorage |
| 2 | +==== |
2 | 3 |
|
3 | | -This project adds support for storing and managing InRule rule applications in a custom Git repository. |
| 4 | +[](https://www.nuget.org/packages/Sknet.InRuleGitStorage) |
4 | 5 |
|
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. |
6 | 7 |
|
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 |
8 | 22 |
|
9 | 23 | ```powershell |
10 | 24 | Install-Package Sknet.InRuleGitStorage -IncludePrerelease |
11 | 25 | ``` |
12 | 26 |
|
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 |
18 | 29 | ``` |
19 | 30 |
|
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 |
25 | 32 |
|
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 |
33 | 33 | ```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")) |
35 | 39 | { |
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"); |
37 | 46 | } |
38 | 47 | ``` |
39 | 48 |
|
40 | | -## Examples |
41 | | - |
42 | | -### Create multiple commits across different branches |
| 49 | +## Remote repository example |
43 | 50 |
|
44 | 51 | ```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"); |
50 | 56 |
|
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")) |
54 | 59 | { |
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"); |
79 | 87 | } |
80 | 88 | ``` |
0 commit comments