项目作者: snwfdhmp

项目描述 :
Keep your projects going forward by applying strict no-regression rules on your repo.
高级语言: Go
项目地址: git://github.com/snwfdhmp/taskr.git
创建时间: 2018-02-12T02:59:38Z
项目社区:https://github.com/snwfdhmp/taskr

开源协议:Apache License 2.0

下载


taskr ⏩ go forward

Taskr keeps you going forward by applying strict no-regression rules on your repo.

  1. $ git commit -m "update api /home and /welcome"
  2. taskr: regression: task 'welcomeSayHello' has returned error, did not on previous commit.
  3. taskr: abort commit.

It helps your team know exactly what has to be done, and how it will be rewarded.

  1. $ git commit -m "fixed linting issues"
  2. taskr: this commit don't introduce any regression.
  3. taskr: task lint done, reward: 5.
  4. [master f263b5e] fixed linting issues
  5. 3 files changed, 12 insertions(+), 1 deletion(-)

Summary

Installation

Taskr is compatible with windows, macOS, and linux.

Install with brew

Brew installation is available and maybe the most simple :

  1. $ brew tap snwfdhmp/homebrew-tap
  2. $ brew install taskr

Install from binaries

Latest release can be found here for Windows, macOS, and linux.

Install with go

Requirements

  • go (easy install)

After you have go installed, make sure the go binary directory is in your $PATH. Go binary directory is located at $(go env GOPATH)/bin

If for any reason, you can’t add GOPATH/bin to your $PATH, replace every call to taskr by $(go env GOPATH)/bin/taskr

Download

  1. go get -u github.com/snwfdhmp/taskr/...

Install

  1. go install github.com/snwfdhmp/taskr

Now, in any git repo, run:

  1. taskr init

Getting started

Let’s create a new git repository.

  1. $ mkdir myRepo
  2. $ cd myRepo
  3. $ git init
  4. Initialized empty Git repository in /Users/snwfdhmp/myRepo/.git/

Now init taskr in this repository. This works the same way in an existing repository.

  1. $ taskr init
  2. taskr inited successfully.

Now let’s see the taskr.yaml file the previous just created.

  1. - name: compile
  2. test: go build main.go
  3. reward: 0
  4. - name: lint
  5. test: golint -set_exit_status
  6. reward: 0

By default, taskr will create an example taskr.yaml file for golang.
Each test is defined by its name, a command to run to determine if the test is pass or fail (based on exit status: 0 = pass, any other = fail), and a reward for the developer if the task is completed (will be used in upcoming versions).

Let’s add a bunch of code in a main.go.

  1. package main
  2. import (
  3. "fmt"
  4. )
  5. func SayHello() {
  6. fmt.Println("Hello world !")
  7. }
  8. func main() {
  9. SayHello()
  10. return
  11. }

Now commit our changes.

  1. $ git add .taskr taskr.yaml
  2. $ git add main.go
  3. $ git commit -m "taskr init"
  4. taskr: task 'compile' completed.
  5. [master (root-commit) 1eb4392] taskr init
  6. 3 files changed, 20 insertions(+)
  7. create mode 100644 .taskr/history.yaml
  8. create mode 100644 main.go
  9. create mode 100644 taskr.yaml

We can see that the task ‘compile’ has been completed with this commit.

Go forward

Taskr is built to keep going forward. Regressions are automatically blocked and taskr will abort any commit introducing one.

For example, let’s add a mistake in our previous code :

  1. package main
  2. import (
  3. "fmt"
  4. )
  5. func SayHello() {
  6. fmt.Println("Hello world !")
  7. }
  8. func main() {
  9. SayHe110[] //<- this won't compile
  10. return
  11. }

Remember we previously completed the task ‘compile’.

Let’s try to commit this thing.

  1. $ git add main.go
  2. $ git commit -m "update main.go"
  3. taskr: regression: task 'compile' has returned error, did not on previous commit.
  4. taskr: abort commit.

Taskr isn’t accepting our commit because the task ‘compile’ now fails.
We have to get the test of compile (it was go build main.go) to pass again.

Complete tasks

To complete tasks, you have to pass their tests successfully (exit status 0).

For example, remember the default task ‘lint’:

  1. - name: lint
  2. test: golint -set_exit_status
  3. reward: 0

We have to get golint -set_exit_status to exit with status code 0.

Let’s try

  1. $ golint -set_exit_status
  2. main.go:7:1: exported function SayHello should have comment or be unexported
  3. Found 1 lint suggestions; failing.

What we have to do is fix this issue.

Let’s change our main.go

  1. ...
  2. //SayHello prints "Hello world !" to the user
  3. func SayHello() {
  4. fmt.Println("Hello world !")
  5. }
  6. ...

Now retry the go linter.

  1. $ golint -set_exit_status

Great ! Let’s commit those changes.

  1. $ git add main.go
  2. $ git commit -m "commented func for linting"
  3. taskr: task 'lint' completed.
  4. [master f265f60] commented func for linting
  5. 2 files changed, 1 insertion(+)
  6. create mode 100755 main

Now you know how to complete tasks with taskr.

Golang package

Taskr is built upon the golang package taskr. It can be used by importing github.com/snwfdhmp/taskr/pkg

  1. import (
  2. "github.com/snwfdhmp/taskr/pkg"
  3. )

The package name is taskr.

Then, for example

  1. history, err := taskr.OpenHistory() //error handling is omitted for readability purposes
  2. tasks, err := taskr.ParseTasks()
  3. report, err := history.Run(tasks...)
  4. for _, t := range report.Tests {
  5. fmt.Println("Test", t.Name, "completed. Congratulations")
  6. }

Documentation

The package documentation can be found here on godoc.

Author

snwfdhmp
Talk to me on LinkedIn