-
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.
- Loading branch information
1 parent
039fa74
commit 667bc9c
Showing
9 changed files
with
271 additions
and
167 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
1.0.8 | ||
1.1.0 |
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,5 +1,6 @@ | ||
repos: | ||
- yuvalpress: version-notifier | ||
- hashicorp: terraform-provider-aws | ||
- hashicorp: terraform-provider-google | ||
- kubernetes: kubectl | ||
# - yuvalpress: version-notifier | ||
- yuvalpress: test | ||
# - hashicorp: terraform-provider-aws | ||
# - hashicorp: terraform-provider-google | ||
# - kubernetes: kubectl |
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,78 @@ | ||
package anchor | ||
|
||
import ( | ||
jparser "github.com/Jeffail/gabs/v2" | ||
"log" | ||
"os" | ||
"strings" | ||
"yuvalpress/version-notifier/internal/config" | ||
"yuvalpress/version-notifier/internal/utils" | ||
) | ||
|
||
var ( | ||
// Reset color variables after call | ||
Reset = "\033[0m" | ||
|
||
// Red color for logs | ||
Red = "\033[31m" | ||
|
||
LogLevel = os.Getenv("LOG_LEVEL") | ||
) | ||
|
||
// Anchor holds the first initialized information for the service | ||
type Anchor struct { | ||
RepoList []Latest | ||
} | ||
|
||
// Latest holds all the needed information for a repo instance | ||
type Latest struct { | ||
User string | ||
Repo string | ||
Latest string | ||
URL string | ||
} | ||
|
||
func (l *Latest) init(t, username, repoName string, data *jparser.Container) { | ||
l.User = username | ||
l.Repo = repoName | ||
|
||
if t == "release" { | ||
l.Latest = utils.GetLatestTag(data.Path("tag_name").String(), LogLevel) | ||
l.URL = strings.ReplaceAll(data.Path("html_url").String(), "\"", "") | ||
} else if t == "tag" { | ||
l.Latest = utils.GetLatestTag(data.Path("name").String(), LogLevel) | ||
l.URL = strings.ReplaceAll(data.Path("zipball_url").String(), "\"", "") | ||
} | ||
|
||
} | ||
|
||
// Init method for main Anchor object | ||
func (a *Anchor) Init() bool { | ||
confData, err := config.ReadConfigFile() | ||
if err != nil { | ||
log.Fatalf("Failed during initialization process with the following error: %v", err) | ||
} | ||
|
||
for _, info := range confData.Repos { | ||
for username, repoName := range info { | ||
data, requestType, err := utils.GetVersion(username, repoName) | ||
if err != nil { | ||
log.Printf("Failed getting latest release of "+username+"/"+repoName+" with the following error: "+Red+"%v"+Reset, err) | ||
log.Println("Skipping..") | ||
continue | ||
} | ||
|
||
if requestType == "release" && data.Path("tag_name").String() == "" || requestType == "tag" && data.Path("name").String() == "" { | ||
return false | ||
} | ||
|
||
log.Println("Fetched latest asset of: " + username + "/" + repoName) | ||
|
||
latest := Latest{} | ||
latest.init(requestType, username, repoName, data) | ||
a.RepoList = append(a.RepoList, latest) | ||
} | ||
} | ||
|
||
return true | ||
} |
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,28 @@ | ||
package config | ||
|
||
import ( | ||
"gopkg.in/yaml.v3" | ||
"os" | ||
) | ||
|
||
// Conf struct holds all the repositories to configure | ||
type Conf struct { | ||
Repos []map[string]string | ||
} | ||
|
||
// ReadConfigFile reads the repositories to scrape from the configmap attached to the pod as volume | ||
func ReadConfigFile() (Conf, error) { | ||
var configData Conf | ||
conf, err := os.ReadFile("config.yaml") | ||
if err != nil { | ||
return Conf{}, err | ||
} | ||
|
||
err = yaml.Unmarshal(conf, &configData) | ||
|
||
if err != nil { | ||
return Conf{}, err | ||
} | ||
|
||
return configData, nil | ||
} |
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
Oops, something went wrong.