glance/internal/widget/repository-overview.go

53 lines
1.2 KiB
Go
Raw Normal View History

2024-05-10 13:05:42 +03:00
package widget
import (
"context"
"html/template"
"time"
"github.com/glanceapp/glance/internal/assets"
"github.com/glanceapp/glance/internal/feed"
)
2024-05-12 05:35:25 +03:00
type Repository struct {
2024-05-10 13:05:42 +03:00
widgetBase `yaml:",inline"`
RequestedRepository string `yaml:"repository"`
Token OptionalEnvString `yaml:"token"`
PullRequestsLimit int `yaml:"pull-requests-limit"`
IssuesLimit int `yaml:"issues-limit"`
RepositoryDetails feed.RepositoryDetails
}
2024-05-12 05:35:25 +03:00
func (widget *Repository) Initialize() error {
2024-05-10 13:05:42 +03:00
widget.withTitle("Repository").withCacheDuration(1 * time.Hour)
if widget.PullRequestsLimit == 0 || widget.PullRequestsLimit < -1 {
widget.PullRequestsLimit = 3
}
if widget.IssuesLimit == 0 || widget.IssuesLimit < -1 {
widget.IssuesLimit = 3
}
return nil
}
2024-05-12 05:35:25 +03:00
func (widget *Repository) Update(ctx context.Context) {
2024-05-10 13:05:42 +03:00
details, err := feed.FetchRepositoryDetailsFromGithub(
widget.RequestedRepository,
string(widget.Token),
widget.PullRequestsLimit,
widget.IssuesLimit,
)
if !widget.canContinueUpdateAfterHandlingErr(err) {
return
}
widget.RepositoryDetails = details
}
2024-05-12 05:35:25 +03:00
func (widget *Repository) Render() template.HTML {
return widget.render(widget, assets.RepositoryTemplate)
2024-05-10 13:05:42 +03:00
}