Skip to content

Commit

Permalink
Merge pull request #2 from caarlos0/bump
Browse files Browse the repository at this point in the history
improvements
  • Loading branch information
caarlos0 authored Apr 17, 2017
2 parents e1727d1 + 2ad5234 commit 1d4bba6
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 114 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
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
49 changes: 49 additions & 0 deletions Gopkg.lock

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

16 changes: 16 additions & 0 deletions Gopkg.toml
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"
47 changes: 47 additions & 0 deletions Makefile
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
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# github-vacations [![Build Status](https://travis-ci.org/caarlos0/github-vacations.svg?branch=master)](https://travis-ci.org/caarlos0/github-vacations) [![Powered By: GoReleaser](https://img.shields.io/badge/powered%20by-goreleaser-green.svg?style=flat-square)](/~https://github.com/goreleaser) [![SayThanks.io](https://img.shields.io/badge/SayThanks.io-%E2%98%BC-1EAEDB.svg?style=flat-square)](https://saythanks.io/to/caarlos0)
# github-vacations

[![Release](https://img.shields.io/github/release/caarlos0/github-vacations.svg?style=flat-square)](/~https://github.com/caarlos0/github-vacations/releases/latest)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Travis](https://img.shields.io/travis/caarlos0/github-vacations.svg?style=flat-square)](https://travis-ci.org/caarlos0/github-vacations)
[![Coverage Status](https://img.shields.io/coveralls/caarlos0/github-vacations/master.svg?style=flat-square)](https://coveralls.io/github/caarlos0/github-vacations?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/caarlos0/github-vacations?style=flat-square)](https://goreportcard.com/report/github.com/caarlos0/github-vacations)
[![Godoc](https://godoc.org/github.com/caarlos0/github-vacations?status.svg&style=flat-square)](http://godoc.org/github.com/caarlos0/github-vacations)
[![SayThanks.io](https://img.shields.io/badge/SayThanks.io-%E2%98%BC-1EAEDB.svg?style=flat-square)](https://saythanks.io/to/caarlos0)
[![Powered By: GoReleaser](https://img.shields.io/badge/powered%20by-goreleaser-green.svg?style=flat-square)](/~https://github.com/goreleaser)


Automagically ignore all notifications related to work when you are on vacations

Expand Down
57 changes: 57 additions & 0 deletions cmd/main/main.go
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)
}
}
38 changes: 0 additions & 38 deletions glide.lock

This file was deleted.

10 changes: 0 additions & 10 deletions glide.yaml

This file was deleted.

8 changes: 7 additions & 1 deletion goreleaser.yml
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
87 changes: 28 additions & 59 deletions main.go
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
}

0 comments on commit 1d4bba6

Please sign in to comment.