url in discord message
This commit is contained in:
@@ -22,8 +22,8 @@ type GiteaFetcher struct {
|
|||||||
Cache *Cache
|
Cache *Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f GiteaFetcher) Fetch() []string {
|
func (f GiteaFetcher) Fetch() []Entry {
|
||||||
var messages []string
|
var messages []Entry
|
||||||
|
|
||||||
for _, repo := range f.Repos {
|
for _, repo := range f.Repos {
|
||||||
if repo == "" {
|
if repo == "" {
|
||||||
@@ -48,7 +48,10 @@ func (f GiteaFetcher) Fetch() []string {
|
|||||||
commit := r[0]
|
commit := r[0]
|
||||||
|
|
||||||
if f.Cache.TryUpdate("gitea_"+url.QueryEscape(giteaURL), commit.Sha) {
|
if f.Cache.TryUpdate("gitea_"+url.QueryEscape(giteaURL), commit.Sha) {
|
||||||
messages = append(messages, fmt.Sprintf("📝 [Gitea] - (%s) %s - %s", repo, commit.Commit.Message, commit.HTMLURL))
|
messages = append(messages, Entry{
|
||||||
|
Title: fmt.Sprintf("📝 [Gitea] - (%s) %s", repo, commit.Commit.Message),
|
||||||
|
URL: commit.HTMLURL,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return messages
|
return messages
|
||||||
|
|||||||
@@ -5,9 +5,15 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Entry represents a single fetched item.
|
||||||
|
type Entry struct {
|
||||||
|
Title string
|
||||||
|
URL string
|
||||||
|
}
|
||||||
|
|
||||||
// Fetcher is the interface for a fetcher.
|
// Fetcher is the interface for a fetcher.
|
||||||
type Fetcher interface {
|
type Fetcher interface {
|
||||||
Fetch() []string
|
Fetch() []Entry
|
||||||
}
|
}
|
||||||
|
|
||||||
func getJSON(req *http.Request, target interface{}) error {
|
func getJSON(req *http.Request, target interface{}) error {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ type RedmineFetcher struct {
|
|||||||
Cache *Cache
|
Cache *Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f RedmineFetcher) Fetch() []string {
|
func (f RedmineFetcher) Fetch() []Entry {
|
||||||
redmineURL := fmt.Sprintf("%s/issues.json", f.BaseURL)
|
redmineURL := fmt.Sprintf("%s/issues.json", f.BaseURL)
|
||||||
req, _ := http.NewRequest("GET", redmineURL, nil)
|
req, _ := http.NewRequest("GET", redmineURL, nil)
|
||||||
req.Header.Set("X-Redmine-API-Key", f.Key)
|
req.Header.Set("X-Redmine-API-Key", f.Key)
|
||||||
@@ -27,17 +27,20 @@ func (f RedmineFetcher) Fetch() []string {
|
|||||||
var r RedmineResponse
|
var r RedmineResponse
|
||||||
|
|
||||||
if err := getJSON(req, &r); err != nil {
|
if err := getJSON(req, &r); err != nil {
|
||||||
return []string{}
|
return []Entry{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(r.Issues) == 0 {
|
if len(r.Issues) == 0 {
|
||||||
return []string{}
|
return []Entry{}
|
||||||
}
|
}
|
||||||
|
|
||||||
i := r.Issues[0]
|
i := r.Issues[0]
|
||||||
if f.Cache.TryUpdate("redmine", i.UpdatedOn) {
|
if f.Cache.TryUpdate("redmine", i.UpdatedOn) {
|
||||||
url := fmt.Sprintf("%s/issues/%d", f.BaseURL, i.ID)
|
url := fmt.Sprintf("%s/issues/%d", f.BaseURL, i.ID)
|
||||||
return []string{fmt.Sprintf("🎫 [Redmine] - #%d %s - %s", i.ID, i.Subject, url)}
|
return []Entry{{
|
||||||
|
Title: fmt.Sprintf("🎫 [Redmine] - #%d %s", i.ID, i.Subject),
|
||||||
|
URL: url,
|
||||||
|
}}
|
||||||
}
|
}
|
||||||
return []string{}
|
return []Entry{}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ type WikiFetcher struct {
|
|||||||
Cache *Cache
|
Cache *Cache
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f WikiFetcher) Fetch() []string {
|
func (f WikiFetcher) Fetch() []Entry {
|
||||||
q := `{"query":"{ pages { list(orderBy: UPDATED, orderByDirection: DESC, limit: 1){ path, updatedAt, title }}}"}`
|
q := `{"query":"{ pages { list(orderBy: UPDATED, orderByDirection: DESC, limit: 1){ path, updatedAt, title }}}"}`
|
||||||
wikiURL := fmt.Sprintf("%s/graphql", f.BaseURL)
|
wikiURL := fmt.Sprintf("%s/graphql", f.BaseURL)
|
||||||
req, _ := http.NewRequest("POST", wikiURL, bytes.NewBuffer([]byte(q)))
|
req, _ := http.NewRequest("POST", wikiURL, bytes.NewBuffer([]byte(q)))
|
||||||
@@ -34,16 +34,19 @@ func (f WikiFetcher) Fetch() []string {
|
|||||||
var r WikiResponse
|
var r WikiResponse
|
||||||
|
|
||||||
if err := getJSON(req, &r); err != nil {
|
if err := getJSON(req, &r); err != nil {
|
||||||
return []string{}
|
return []Entry{}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(r.Data.Pages.List) == 0 {
|
if len(r.Data.Pages.List) == 0 {
|
||||||
return []string{}
|
return []Entry{}
|
||||||
}
|
}
|
||||||
u := r.Data.Pages.List[0]
|
u := r.Data.Pages.List[0]
|
||||||
if f.Cache.TryUpdate("wiki", u.UpdatedAt) {
|
if f.Cache.TryUpdate("wiki", u.UpdatedAt) {
|
||||||
url := fmt.Sprintf("%s/%s", f.BaseURL, u.Path)
|
url := fmt.Sprintf("%s/%s", f.BaseURL, u.Path)
|
||||||
return []string{fmt.Sprintf("📖 [WikiJS] - %s - %s", u.Title, url)}
|
return []Entry{{
|
||||||
|
Title: fmt.Sprintf("📖 [WikiJS] - %s", u.Title),
|
||||||
|
URL: url,
|
||||||
|
}}
|
||||||
}
|
}
|
||||||
return []string{}
|
return []Entry{}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package lib
|
package lib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -70,8 +71,10 @@ func getDiscordSender(config Config) DiscordSender {
|
|||||||
func getMessages(fetchers []Fetcher) []string {
|
func getMessages(fetchers []Fetcher) []string {
|
||||||
messages := []string{}
|
messages := []string{}
|
||||||
for _, fetcher := range fetchers {
|
for _, fetcher := range fetchers {
|
||||||
fetcher_messages := fetcher.Fetch()
|
entries := fetcher.Fetch()
|
||||||
messages = append(messages, fetcher_messages...)
|
for _, entry := range entries {
|
||||||
|
messages = append(messages, fmt.Sprintf("[%s](%s)", entry.Title, entry.URL))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return messages
|
return messages
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user