Skip to content

Commit

Permalink
added instructions and blob existing rule
Browse files Browse the repository at this point in the history
  • Loading branch information
rcraggs committed Jul 6, 2018
1 parent 605f109 commit eb0f90e
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 94 deletions.
50 changes: 0 additions & 50 deletions .idea/misc.xml

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

26 changes: 14 additions & 12 deletions .idea/modules/gitruler.iml

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

70 changes: 70 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

# GitRuler

## Installation and Running

1. Download the jar from Releases
2. Create a file listing the rules to check against a git repository (see below). By default it will look for `gitrules.json` in the repository directory
3. cd into a repository root and run
```bash

java -jar <path-to-jar>

```

You can also specific an alternative repository path or config file using the `-r` and `-c` options:

```bash

java -jar <path-to-jar> -c ~/myotherrules.json -r ~/another/repository/.git # (not that the .git is optional)

```

## Screenshot

![Example Screenshot](docs/images/example-screenshot.png)

## Rules file

The rules that test the repo are in the format of a json array:

```json
[
{ "rule": "head-exists", "stop-on-fail":true},
{ "rule": "file-exists-in-head", "path": "file1.txt"},
{ "rule": "file-exists-in-head", "path": "folder/file1.txt"},
{ "rule": "file-not-exist-in-head", "path": "folder/not-here.txt"},
{ "rule": "blob-exists-in-location-in-head", "path": "folder/file2.txt", "hash": "907b308167f0880fb2a5c0e1614bb0c7620f9dc3"}
]
```

### Rules

- `head-exists`: Checks that a repository with at least one commit exists.
- `file-exists-in-head`: Checks that there is a file at the given `path` in the final commit (head).
- `file-not-exist-in-head`: Checks that there is not a file at a given `path` in the final commit.
- `blob-exists-in-location-in-head`: Checks that a file with a given `hash` exists at a certain `path` in the last commit. This can be used to test that someone moved a file using git rather than just created a new file with the same name.

### Rules to be created

The following rules are planned to be implemented:

- Checking the number of commits that have been made to a given file.
- Allow checking a file exists or not within a given commit based on commit message.
- Check whether a file was added, modified or deleted within a given commit based on commit message.
- Check whether a branch exists or not.
- Check whether a remote exists or not.

### Common rule instructions

There are some parameters that you can set for all rules.

#### Already Implemented

- `stop-on-fail`: Will stop running rules if this one fails.

#### To Be Implemented

- `success-message`: optional additional message when a rule passes
- `failure-message`: optional additional message when a rule fails
- `alternative-description`: Override the default description of this rule
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.rcraggs'
version '1.0-SNAPSHOT'
version '0.1'

apply plugin: 'java'

Expand Down Expand Up @@ -33,4 +33,7 @@ dependencies {
compile 'org.json:json:20180130'
compile 'commons-io:commons-io:2.6'
compile group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '5.0.1.201806211838-r'

// https://mvnrepository.com/artifact/org.slf4j/slf4j-nop
testCompile group: 'org.slf4j', name: 'slf4j-nop', version: '1.7.25'
}
Binary file added docs/images/example-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion examples/simple/gitrules.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[
{ "rule": "head-exists", "stop-on-fail":true},
{ "rule": "file-exists-in-head", "path": "file1.txt"},
{ "rule": "file-exists-in-head", "path": "folder/file1.txt"}
{ "rule": "file-exists-in-head", "path": "folder/file1.txt"},
{ "rule": "file-not-exist-in-head", "path": "folder/not-here.txt"},
{ "rule": "blob-exists-in-location-in-head", "path": "folder/file2.txt", "hash": "907b308167f0880fb2a5c0e1614bb0c7620f9dc3"}
]
46 changes: 21 additions & 25 deletions src/main/java/gitruler/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,13 @@
@CommandLine.Command(name = "testrepo", mixinStandardHelpOptions = true, version = "Gitruler 1.0")
public class Command implements Runnable {

public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_BLACK = "\u001B[30m";
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_YELLOW = "\u001B[33m";
public static final String ANSI_BLUE = "\u001B[34m";
public static final String ANSI_PURPLE = "\u001B[35m";
public static final String ANSI_CYAN = "\u001B[36m";
public static final String ANSI_WHITE = "\u001B[37m";

public static final String ANSI_BLACK_BACKGROUND = "\u001B[40m";
public static final String ANSI_RED_BACKGROUND = "\u001B[41m";
public static final String ANSI_GREEN_BACKGROUND = "\u001B[42m";
public static final String ANSI_YELLOW_BACKGROUND = "\u001B[43m";
public static final String ANSI_BLUE_BACKGROUND = "\u001B[44m";
public static final String ANSI_PURPLE_BACKGROUND = "\u001B[45m";
public static final String ANSI_CYAN_BACKGROUND = "\u001B[46m";
public static final String ANSI_WHITE_BACKGROUND = "\u001B[47m";

static final String CORRECT_TICK = ANSI_GREEN + "[\u2713]" + ANSI_RESET;
static final String WRONG_CROSS = ANSI_RED + "[\u2718]" + ANSI_RESET;
private static final String ANSI_RESET = "\u001B[0m";
private static final String ANSI_RED = "\u001B[31m";
private static final String ANSI_GREEN = "\u001B[32m";
private static final String ANSI_CYAN = "\u001B[36m";

private static final String CORRECT_TICK = ANSI_GREEN + "[\u2713]" + ANSI_RESET;
private static final String WRONG_CROSS = ANSI_RED + "[\u2718]" + ANSI_RESET;


private static final String DEFAULT_CONFIG_FILENAME = "gitrules.json";
Expand All @@ -46,14 +32,21 @@ public class Command implements Runnable {

public void run() {



// Read the config
if (repositoryPath == null){
repositoryPath = System.getProperty("user.dir");
}

// Read the config
if (configFilePath == null){
configFilePath = System.getProperty("user.dir") + File.separator + Command.DEFAULT_CONFIG_FILENAME;

String repoRoot = repositoryPath;
if (repoRoot.endsWith(".git")){
repoRoot = repoRoot.substring(0, repoRoot.length() - 4);
}
configFilePath = repoRoot + File.separator + Command.DEFAULT_CONFIG_FILENAME;
}

try {
Expand All @@ -78,13 +71,16 @@ public void run() {
resultString += " " + r.getTitle() + " " + result.getMessage();

System.out.println(resultString);

if (!result.hasPassed() && r.stopOnFail()){
System.out.println(ANSI_CYAN + "Exiting because a critical rule didn't pass" + ANSI_RESET);
System.exit(0);
}
}
}




public static void main(String[] args) {
System.setProperty("picocli.trace", "OFF");
CommandLine.run(new Command(), System.out, args);
}
}
Loading

0 comments on commit eb0f90e

Please sign in to comment.