Skip to content

#add tagnotify #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ To watch repositories simply add them to the list of arguments `-r=kubernetes/ku
```
docker run --rm -e GITHUB_TOKEN=XXX -e SLACK_HOOK=https://hooks.slack.com/... justwatch/github-releases-notifier -r=kubernetes/kubernetes
```
If you need to follow by tag you can use
```
docker run --rm -e TAG_CHECKER=true -e GITHUB_TOKEN=XXX -e SLACK_HOOK=https://hooks.slack.com/... justwatch/github-releases-notifier -r=kubernetes/kubernetes
```

#### docker-compose

Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Config struct {
LogLevel string `arg:"env:LOG_LEVEL"`
Repositories []string `arg:"-r,separate"`
SlackHook string `arg:"env:SLACK_HOOK"`
IsTagChecker bool `arg:"env:TAG_CHECKER"`
}

// Token returns an oauth2 token or an error.
Expand Down Expand Up @@ -63,7 +64,7 @@ func main() {
}

releases := make(chan Repository)
go checker.Run(c.Interval, c.Repositories, releases)
go checker.Run(c.Interval, c.Repositories, releases, c.IsTagChecker)

slack := SlackSender{Hook: c.SlackHook}

Expand Down
50 changes: 50 additions & 0 deletions redis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"fmt"
"github.com/go-redis/redis"
"os"
)

//Client redis Client
var Client *redis.Client

//SetKey set key in redis
func SetKey(key string, value string) {
var err error

if GetValue(key) != "" {
Client.Del(key)
}

err = Client.Set(key, value, 0).Err()
check(err)
}

//GetValue get value from redis
func GetValue(key string) string {
return Client.Get(key).Val()
}

//СonnectToRedis connect to redis
func СonnectToRedis() redis.Client {
var host = os.Getenv("REDIS_HOST")
var port = os.Getenv("REDIS_PORT")

Client = redis.NewClient(&redis.Options{
Addr: host + ":" + port,
Password: "",
DB: 11,
})

pong, err := Client.Ping().Result()
fmt.Println(pong, err)

return *Client
}

func check(e error) {
if e != nil {
fmt.Println(e)
}
}
10 changes: 9 additions & 1 deletion releasechecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Checker struct {
}

// Run the queries and comparisons for the given repositories in a given interval.
func (c *Checker) Run(interval time.Duration, repositories []string, releases chan<- Repository) {
func (c *Checker) Run(interval time.Duration, repositories []string, releases chan<- Repository, tag bool) {
if c.releases == nil {
c.releases = make(map[string]Repository)
}
Expand All @@ -31,6 +31,14 @@ func (c *Checker) Run(interval time.Duration, repositories []string, releases ch
owner, name := s[0], s[1]

nextRepo, err := c.query(owner, name)
if true == tag {
nextRepo, err = APIV3tagChecker(owner, name)
if nextRepo != (Repository{}) {
releases <- nextRepo
c.releases[repoName] = nextRepo
}
}

if err != nil {
level.Warn(c.logger).Log(
"msg", "failed to query the repository's releases",
Expand Down
71 changes: 71 additions & 0 deletions tagchecker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package main

import (
"context"
"fmt"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
"net/url"
"os"
"time"
)

//APIV3tagChecker Function for working with github api v3 and check if new tags are published
func APIV3tagChecker(owner, name string) (Repository, error) {
СonnectToRedis()
githubToken, ok := os.LookupEnv("GITHUB_TOKEN")

if !ok {
fmt.Errorf("GITHUB_TOKEN environment variable not set")
}

ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: githubToken},
)

tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)

opt := &github.ListOptions{}

repo, _, err := client.Repositories.Get(ctx, owner, name)
tags, _, err := client.Repositories.ListTags(ctx, owner, name, opt)

if err != nil {
return Repository{}, fmt.Errorf("cant find repo")
}

var LastTag github.RepositoryTag
for _, tag := range tags {
LastTag = *tag
break
}

repourl, err := url.ParseRequestURI(repo.GetURL())
if err != nil {
return Repository{}, fmt.Errorf("cant convert url")
}

if GetValue(name) == LastTag.GetName() {
return Repository{}, nil
}

SetKey(name, LastTag.GetName())

return Repository{
ID: string(repo.GetID()),
Name: string(repo.GetName()),
Owner: owner,
Description: string(repo.GetDescription()),
URL: *repourl,

Release: Release{
ID: "1",
Name: LastTag.GetName(),
Description: "It is Tag",
URL: *repourl,
PublishedAt: time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC),
},
}, nil
}
2 changes: 2 additions & 0 deletions vendor/github.com/go-redis/redis/.gitignore

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

21 changes: 21 additions & 0 deletions vendor/github.com/go-redis/redis/.travis.yml

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

25 changes: 25 additions & 0 deletions vendor/github.com/go-redis/redis/LICENSE

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

19 changes: 19 additions & 0 deletions vendor/github.com/go-redis/redis/Makefile

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

142 changes: 142 additions & 0 deletions vendor/github.com/go-redis/redis/README.md

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

Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy