-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from caarlos0/bump
improvements
- Loading branch information
Showing
10 changed files
with
220 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
language: go | ||
go: 1.8 | ||
install: | ||
- go get github.com/Masterminds/glide | ||
- glide install | ||
script: go test -cover `glide nv` | ||
install: make setup | ||
script: make ci | ||
after_success: | ||
test -n "$TRAVIS_TAG" && curl -sL https://git.io/goreleaser | bash | ||
# - go get github.com/mattn/goveralls | ||
# - goveralls -coverprofile=coverage.out -service=travis-ci -repotoken="$COVERALLS_TOKEN" | ||
- test -n "$TRAVIS_TAG" && curl -sL http://git.io/goreleaser | bash | ||
notifications: | ||
email: false |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
[[dependencies]] | ||
name = "github.com/caarlos0/spin" | ||
version = "^1.0.0" | ||
|
||
[[dependencies]] | ||
branch = "master" | ||
name = "github.com/google/go-github" | ||
|
||
[[dependencies]] | ||
name = "github.com/urfave/cli" | ||
version = "^1.19.1" | ||
|
||
[[dependencies]] | ||
branch = "master" | ||
name = "golang.org/x/oauth2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
SOURCE_FILES?=$$(go list ./... | grep -v /vendor/) | ||
TEST_PATTERN?=. | ||
TEST_OPTIONS?= | ||
|
||
setup: ## Install all the build and lint dependencies | ||
go get -u github.com/alecthomas/gometalinter | ||
go get -u github.com/golang/dep/... | ||
go get -u github.com/pierrre/gotestcover | ||
go get -u golang.org/x/tools/cmd/cover | ||
dep ensure | ||
gometalinter --install --update | ||
|
||
test: ## Run all the tests | ||
gotestcover $(TEST_OPTIONS) -covermode=count -coverprofile=coverage.out $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=30s | ||
|
||
cover: test ## RUn all the tests and opens the coverage report | ||
go tool cover -html=coverage.out | ||
|
||
fmt: ## gofmt and goimports all go files | ||
find . -name '*.go' -not -wholename './vendor/*' | while read -r file; do gofmt -w -s "$$file"; goimports -w "$$file"; done | ||
|
||
lint: ## Run all the linters | ||
gometalinter --vendor --disable-all \ | ||
--enable=deadcode \ | ||
--enable=ineffassign \ | ||
--enable=gosimple \ | ||
--enable=staticcheck \ | ||
--enable=gofmt \ | ||
--enable=goimports \ | ||
--enable=dupl \ | ||
--enable=misspell \ | ||
--enable=errcheck \ | ||
--enable=vet \ | ||
--enable=vetshadow \ | ||
--deadline=10m \ | ||
./... | ||
|
||
ci: lint test ## Run all the tests and code checks | ||
|
||
build: ## Build a beta version | ||
go build -o github-vacations ./cmd/main/main.go | ||
|
||
# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html | ||
help: | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' | ||
|
||
.DEFAULT_GOAL := build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
githubvacations "github.com/caarlos0/github-vacations" | ||
"github.com/caarlos0/spin" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
var version = "master" | ||
|
||
func main() { | ||
app := cli.NewApp() | ||
app.Name = "github-vacations" | ||
app.Usage = "Automagically ignore all notifications related to work when you are on vacations" | ||
app.Version = version | ||
app.Flags = []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "org, o", | ||
Usage: "Organization name to ignore", | ||
}, | ||
cli.StringFlag{ | ||
Name: "token, t", | ||
EnvVar: "GITHUB_TOKEN", | ||
Usage: "GitHub token", | ||
}, | ||
} | ||
app.Action = func(c *cli.Context) error { | ||
var token = c.String("token") | ||
var org = strings.ToLower(c.String("org")) | ||
if token == "" { | ||
return cli.NewExitError("missing GITHUB_TOKEN", 1) | ||
} | ||
if org == "" { | ||
return cli.NewExitError("missing organization to ignore", 1) | ||
} | ||
var spin = spin.New("%s Helping you to not work...") | ||
spin.Start() | ||
count, err := githubvacations.MarkWorkNotificationsAsRead(token, org) | ||
spin.Stop() | ||
if err != nil { | ||
var msg = "failed to mark notifications as read" | ||
if count > 0 { | ||
msg = fmt.Sprintf("%v notifications marked as read, others failed", count) | ||
} | ||
return cli.NewExitError(msg, 1) | ||
} | ||
fmt.Printf("%v notifications marked as read", count) | ||
return nil | ||
} | ||
if err := app.Run(os.Args); err != nil { | ||
panic(err) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
build: | ||
main: ./cmd/main/main.go | ||
goarch: | ||
- amd64 | ||
brew: | ||
repo: caarlos0/homebrew-tap | ||
github: | ||
owner: caarlos0 | ||
name: homebrew-tap | ||
folder: Formula |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,41 @@ | ||
package main | ||
// Package githubvacations contains functions that help you not work | ||
// when you are on vacations (or just don't want to). | ||
package githubvacations | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"context" | ||
"strings" | ||
|
||
"github.com/caarlos0/spin" | ||
"github.com/google/go-github/github" | ||
"github.com/urfave/cli" | ||
"golang.org/x/oauth2" | ||
) | ||
|
||
var version = "master" | ||
|
||
func main() { | ||
app := cli.NewApp() | ||
app.Name = "github-vacations" | ||
app.Usage = "Automagically ignore all notifications related to work when you are on vacations" | ||
app.Version = version | ||
app.Flags = []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "org, o", | ||
Usage: "Organization name to ignore", | ||
}, | ||
cli.StringFlag{ | ||
Name: "token, t", | ||
EnvVar: "GITHUB_TOKEN", | ||
Usage: "GitHub token", | ||
}, | ||
// MarkWorkNotificationsAsRead checks your notifications from work and mark | ||
// them as read | ||
func MarkWorkNotificationsAsRead(token, org string) (count int, err error) { | ||
var ctx = context.Background() | ||
var client = github.NewClient(oauth2.NewClient( | ||
ctx, | ||
oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})), | ||
) | ||
notifications, _, err := client.Activity.ListNotifications( | ||
ctx, | ||
&github.NotificationListOptions{}, | ||
) | ||
if err != nil { | ||
return | ||
} | ||
app.Action = func(c *cli.Context) error { | ||
var token = c.String("token") | ||
var org = strings.ToLower(c.String("org")) | ||
if token == "" { | ||
return cli.NewExitError("missing GITHUB_TOKEN", 1) | ||
} | ||
if org == "" { | ||
return cli.NewExitError("missing organization to ignore", 1) | ||
} | ||
var spin = spin.New("%s Helping you to not work...") | ||
spin.Start() | ||
|
||
ts := oauth2.StaticTokenSource( | ||
&oauth2.Token{AccessToken: token}, | ||
) | ||
tc := oauth2.NewClient(oauth2.NoContext, ts) | ||
client := github.NewClient(tc) | ||
notifications, _, err := client.Activity.ListNotifications( | ||
&github.NotificationListOptions{}, | ||
) | ||
if err != nil { | ||
spin.Stop() | ||
return cli.NewExitError(err.Error(), 1) | ||
} | ||
var count int | ||
for _, notification := range notifications { | ||
owner := *notification.Repository.Owner.Login | ||
if strings.ToLower(owner) == org { | ||
client.Activity.DeleteThreadSubscription(*notification.ID) | ||
client.Activity.MarkThreadRead(*notification.ID) | ||
count++ | ||
for _, notification := range notifications { | ||
var owner = *notification.Repository.Owner.Login | ||
if strings.ToLower(owner) == org { | ||
if _, err = client.Activity.DeleteThreadSubscription(ctx, *notification.ID); err != nil { | ||
return | ||
} | ||
if _, err = client.Activity.MarkThreadRead(ctx, *notification.ID); err != nil { | ||
return | ||
} | ||
count++ | ||
} | ||
spin.Stop() | ||
fmt.Println(count, "notifications marked as read") | ||
return nil | ||
} | ||
if err := app.Run(os.Args); err != nil { | ||
panic(err) | ||
} | ||
return | ||
} |