Skip to content

Commit

Permalink
Fix bugs with new API adaptation, clean up some UX language on Discover
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneharter committed Dec 23, 2024
1 parent 8f8048e commit f36830e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
14 changes: 7 additions & 7 deletions cmd/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ type ExistingMonitors struct {
func (em ExistingMonitors) HasMonitorByName(name string) bool {
for _, value := range em.Monitors {
if em.CurrentCode != "" {
if value.Code == em.CurrentCode {
if value.Attributes.Code == em.CurrentCode {
continue
}
} else {
if value.Key == em.CurrentKey {
if value.Attributes.Key == em.CurrentKey {
continue
}
}
Expand All @@ -55,11 +55,11 @@ func (em ExistingMonitors) HasMonitorByName(name string) bool {
func (em ExistingMonitors) GetNameForCurrent() (string, error) {
for _, value := range em.Monitors {
if em.CurrentCode != "" {
if value.Code == em.CurrentCode {
if value.Attributes.Code == em.CurrentCode {
return value.Name, nil
}
} else {
if value.Key == em.CurrentKey {
if value.Attributes.Key == em.CurrentKey {
return value.Name, nil
}
}
Expand Down Expand Up @@ -503,7 +503,7 @@ func initialNameInputModel(defaultName string) nameInputModel {
// Setup list items
items := []list.Item{
item{title: UseDefaultName, desc: defaultName},
item{title: EnterCustomName, desc: "A unique name is required"},
item{title: EnterCustomName, desc: "Add a friendly, unique name for this job"},
item{title: SkipJob, desc: "Do not monitor this cron job"},
}

Expand Down Expand Up @@ -608,8 +608,8 @@ func (m nameInputModel) View() string {
}

const (
UseDefaultName = "Monitor this job - Use default name"
EnterCustomName = "Monitor this job - Enter custom name"
UseDefaultName = "Monitor this job - Use this name:"
EnterCustomName = "Monitor this job - Change the name"
SkipJob = "Skip this job"
)

Expand Down
16 changes: 13 additions & 3 deletions lib/cronitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const (
)

type Monitor struct {
Attributes struct {
GroupName string `json:"group_name"`
Key string `json:"key"`
Code string `json:"code"`
} `json:"attributes,omitempty"`
Name string `json:"name,omitempty"`
DefaultName string `json:"defaultName"`
Key string `json:"key"`
Expand All @@ -63,7 +68,12 @@ type MonitorSummary struct {
Name string `json:"name,omitempty"`
DefaultName string `json:"defaultName"`
Key string `json:"key"`
Code string `json:"code,omitempty"`
Code string `json:"attributes.code,omitempty"`
Attributes struct {
GroupName string `json:"group_name"`
Key string `json:"key"`
Code string `json:"code"`
} `json:"attributes,omitempty"`
}

type CronitorApi struct {
Expand Down Expand Up @@ -129,8 +139,8 @@ func (api CronitorApi) PutMonitors(monitors map[string]*Monitor) (map[string]*Mo
}

for _, value := range responseMonitors {
if _, ok := monitors[value.Key]; ok {
monitors[value.Key].Code = value.Code
if _, ok := monitors[value.Attributes.Key]; ok {
monitors[value.Attributes.Key].Attributes = value.Attributes
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/crontab.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (l Line) Write() string {
lineParts = append(lineParts, "--no-stdout")
}
lineParts = append(lineParts, "exec")
lineParts = append(lineParts, l.Mon.Code)
lineParts = append(lineParts, l.Mon.Attributes.Code)

if len(l.CommandToRun) > 0 {
if l.CommandIsComplex() {
Expand Down

0 comments on commit f36830e

Please sign in to comment.