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