Skip to content

Commit

Permalink
Handle conversion of existing data format
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuixz committed Aug 19, 2024
1 parent f1ab935 commit e6880af
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions pkg/slack/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"regexp"
"strings"

"github.com/oursky/github-actions-manager/pkg/github/jobs"
"github.com/oursky/github-actions-manager/pkg/kv"
Expand All @@ -27,8 +28,8 @@ type App struct {
}

type ChannelInfo struct {
ChannelID string `json:"channelID"`
Filter *MessageFilter `json:"filter"`
ChannelID string `json:"channelID"`
Filter MessageFilter `json:"filter"`
}

func (f ChannelInfo) String() string {
Expand Down Expand Up @@ -74,7 +75,31 @@ func (a *App) GetChannels(ctx context.Context, repo string) ([]ChannelInfo, erro
err = json.Unmarshal([]byte(data), &channelInfos)

if err != nil {
return nil, err
// Maybe it's using the old format? Handle this case
channelInfoStrings := strings.Split(data, ";")
var channelInfos []ChannelInfo

for _, channelString := range channelInfoStrings {
channelID, conclusionsString, _ := strings.Cut(channelString, ":")
var conclusions []string
for _, conclusion := range strings.Split(conclusionsString, ",") {
if len(conclusion) > 0 {
conclusions = append(conclusions, conclusion)
}
}
conclusionRule, err := NewFilterRule("conclusions", []string{}, conclusions)
if err != nil {
return nil, err
}

filter := NewFilter([]MessageFilterRule{*conclusionRule})
channelInfos = append(channelInfos, ChannelInfo{
ChannelID: channelID,
Filter: filter,
})
}

return channelInfos, nil
}
return channelInfos, nil
}
Expand Down

0 comments on commit e6880af

Please sign in to comment.