This repository has been archived by the owner on Dec 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
travis_ci_widget.go
74 lines (59 loc) · 1.58 KB
/
travis_ci_widget.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package internal
import (
"strconv"
"github.com/Phantas0s/devdash/internal/platform"
"github.com/pkg/errors"
)
const (
travisCITableBuilds = "travis.table_builds"
)
type travisCIWidget struct {
tui *Tui
client *platform.TravisCI
}
// NewTravisCIWidget with all information necessary to connect to the Github API.
func NewTravisCIWidget(token string) *travisCIWidget {
c := platform.NewTravisCI(token)
return &travisCIWidget{
client: c,
}
}
func (tc travisCIWidget) CreateWidgets(widget Widget, tui *Tui) (f func() error, err error) {
tc.tui = tui
switch widget.Name {
case travisCITableBuilds:
f, err = tc.tableBuilds(widget)
default:
return nil, errors.Errorf("can't find the widget %s for service travis ci", widget.Name)
}
return
}
func (tc travisCIWidget) tableBuilds(widget Widget) (f func() error, err error) {
title := " Travis CI builds "
if _, ok := widget.Options[optionTitle]; ok {
title = widget.Options[optionTitle]
}
repo := ""
if _, ok := widget.Options[optionRepository]; ok {
repo = widget.Options[optionRepository]
}
owner := ""
if _, ok := widget.Options[optionOwner]; ok {
owner = widget.Options[optionOwner]
}
var limit int64 = 5
if _, ok := widget.Options[optionRowLimit]; ok {
limit, err = strconv.ParseInt(widget.Options[optionRowLimit], 10, 0)
if err != nil {
return nil, errors.Wrapf(err, "%s must be a number", widget.Options[optionRowLimit])
}
}
builds, err := tc.client.Builds(repo, owner, limit)
if err != nil {
return nil, err
}
f = func() error {
return tc.tui.AddTable(builds, title, widget.Options)
}
return
}