@@ -17,6 +17,8 @@ type SettingsService struct {
1717// NewSettingsService creates a new SettingsService instance.
1818func NewSettingsService (settings * Settings ) * SettingsService {
1919 settings .checkSettings ()
20+ settings .setMaxAge ()
21+ settings .setLabelSlice ()
2022
2123 return & SettingsService {
2224 settings : settings ,
@@ -31,14 +33,16 @@ type Settings struct {
3133 DBFile string
3234 // labels to look for
3335 // ex: "\"help-wanted\", \"help wanted\",\"junior friendly\",\"good first issue\""
34- Labels string
36+ ConfiguredLabels string
3537 // optional
3638 MatrixRoomID string
3739 MatrixUsername string
3840 MatrixPassword string
3941 MatrixServer string
4042
41- maxAge string
43+ // computed
44+ MaxAge string
45+ Labels []string
4246}
4347
4448// GetSettings : Get all the settings.
@@ -52,7 +56,7 @@ func (ss *SettingsService) Print() {
5256 log .Info (" Github token: **" )
5357 log .Infof (" Interval: %d hours" , ss .GetSettings ().Interval )
5458 log .Infof (" Database file: %s" , ss .GetSettings ().DBFile )
55- log .Infof (" Labels: %s" , ss .GetSettings ().Labels )
59+ log .Infof (" Labels: %s" , ss .GetSettings ().ConfiguredLabels )
5660 log .Infof (" Matrix room ID: %s" , ss .GetSettings ().MatrixRoomID )
5761 log .Infof (" Matrix username: %s" , ss .GetSettings ().MatrixUsername )
5862 log .Info (" Matrix password: ***" )
@@ -68,27 +72,24 @@ func (s *Settings) IsMatrixConfigured() bool {
6872}
6973
7074// GetLabelSlice gets label slice from settings.
71- func (s * Settings ) GetLabelSlice () [] string {
75+ func (s * Settings ) setLabelSlice () {
7276 // Regex to extract labels inside double quotes
7377 re := regexp .MustCompile (`"([^"]+)"` )
74- matches := re .FindAllStringSubmatch (s .Labels , - 1 )
78+ matches := re .FindAllStringSubmatch (s .ConfiguredLabels , - 1 )
7579
76- var labels = make ([]string , len (matches ))
77- for _ , match := range matches {
78- labels = append (labels , match [1 ])
80+ if matches == nil {
81+ log .Fatal ("Invalid labels, format should be \" label1\" , \" label2\" , ..." )
7982 }
8083
81- return labels
84+ s .Labels = make ([]string , len (matches ))
85+ for i , match := range matches {
86+ s .Labels [i ] = match [1 ]
87+ }
8288}
8389
8490// GetMaxAge gets the max time before which data is not fresh anymore.
85- func (ss * SettingsService ) GetMaxAge () string {
86- s := ss .GetSettings ()
87- if s .maxAge == "" {
88- s .maxAge = strconv .Itoa (hoursInSeconds * s .Interval )
89- }
90-
91- return s .maxAge
91+ func (s * Settings ) setMaxAge () {
92+ s .MaxAge = strconv .Itoa (hoursInSeconds * s .Interval )
9293}
9394
9495func (s * Settings ) checkSettings () {
@@ -108,11 +109,7 @@ func (s *Settings) checkSettings() {
108109 log .Warn ("Matrix notif not fully configured" )
109110 }
110111
111- if s .Labels == "" {
112+ if s .ConfiguredLabels == "" {
112113 log .Fatal ("Missing labels" )
113114 }
114-
115- if s .GetLabelSlice () == nil {
116- log .Fatal ("Invalid labels, format should be \" label1\" , \" label2\" , ..." )
117- }
118115}
0 commit comments