-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathtagchecker.go
More file actions
71 lines (57 loc) · 1.53 KB
/
Copy pathtagchecker.go
File metadata and controls
71 lines (57 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
}