Skip to content

Commit

Permalink
force limit of 5 repos
Browse files Browse the repository at this point in the history
  • Loading branch information
Arturomtz8 committed Sep 12, 2023
1 parent 1bce1b8 commit 569005f
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,26 +138,30 @@ func formatReposContentAndSend(repos *github.TrendingSearchResult, chatId int) (
{{.HtmlURL}}
`

for _, repo := range repos.Items {
var report = template.Must(template.New("trendinglist").Parse(templ))
buf := &bytes.Buffer{}
if err := report.Execute(buf, repo); err != nil {
sendTextToTelegramChat(chatId, err.Error())
return "", err
for index, repo := range repos.Items {
if index <= defaulRepoLen {
var report = template.Must(template.New("trendinglist").Parse(templ))
buf := &bytes.Buffer{}
if err := report.Execute(buf, repo); err != nil {
sendTextToTelegramChat(chatId, err.Error())
return "", err
}
s := buf.String()

reposContent = append(reposContent, s)
}
s := buf.String()

reposContent = append(reposContent, s)
}

if len(reposContent) == 0 {
return "", errors.New("There are not trending repos yet for today, try again later")

} else if len(reposContent) <= defaulRepoLen {
repoLen = len(reposContent)
} else {
repoLen = defaulRepoLen
}
// else if len(reposContent) <= defaulRepoLen {
// repoLen = len(reposContent)
// } else {
// repoLen = defaulRepoLen
// }
fmt.Println("template created and proceeding to send repos to chat")
fmt.Println("Total repos that will be sent", repoLen)

Expand Down

0 comments on commit 569005f

Please sign in to comment.