Skip to content

Commit

Permalink
Merge pull request #11 from tukaelu/fix/default_user_segment_id
Browse files Browse the repository at this point in the history
fix(empty): change default_user_segment_id to deprecated
  • Loading branch information
tukaelu authored Aug 15, 2024
2 parents e7af7b1 + 646f5ea commit 84ff634
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ contents_dir: path/to/contents
| default_comments_disabled | true | Specify the default comments disabled |
| default_locale | true | Specify the default locale for translations |
| default_permission_group_id | true | Specify the default permission group ID |
| default_user_segment_id | true | Specify the default user segment ID |
| default_user_segment_id | false | Specify the default user segment ID |
| notify_subscribers | false | Specify whether to notify subscribers of the article |
| contents_dir | false | Specify the local directory path to manage articles |

Expand Down
4 changes: 2 additions & 2 deletions internal/cli/cmdEmpty.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type CommandEmpty struct {
Title string `name:"title" short:"t" help:"Specify the title of the article." required:""`
Locale string `name:"locale" short:"l" help:"Specify the locale to pull. If not specified, the default locale will be used."`
PermissionGroupID int `name:"permission-group-id" short:"p" help:"Specify the permission group ID. If not specified, the default value will be used."`
UserSegmentID int `name:"user-segment-id" short:"u" help:"Specify the user segment ID. If not specified, the default value will be used."`
UserSegmentID *int `name:"user-segment-id" short:"u" help:"Specify the user segment ID. If not specified, the default value will be used."`
SaveArticle bool `name:"save-article" help:"It saves the article in addition to the translation."`
WithoutSectionDir bool `name:"without-section-dir" help:"It doesn't save in a directory named after the section ID."`
client zendesk.Client `kong:"-"`
Expand All @@ -31,7 +31,7 @@ func (c *CommandEmpty) Run(g *Global) error {
if c.PermissionGroupID == 0 {
c.PermissionGroupID = g.Config.DefaultPermissionGroupID
}
if c.UserSegmentID == 0 {
if c.UserSegmentID == nil {
c.UserSegmentID = g.Config.DefailtUserSegmentID
}

Expand Down
5 changes: 1 addition & 4 deletions internal/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Config struct {
DefaultCommentsDisabled bool `yaml:"default_comments_disabled" description:"Default comments disabled" default:"false"`
DefaultLocale string `yaml:"default_locale" description:"Default locale for articles" required:"true"`
DefaultPermissionGroupID int `yaml:"default_permission_group_id" description:"Default permission group ID" required:"true"`
DefailtUserSegmentID int `yaml:"default_user_segment_id" description:"Default user segment ID" required:"true"`
DefailtUserSegmentID *int `yaml:"default_user_segment_id" description:"Default user segment ID"`
NotifySubscribers bool `yaml:"notify_subscribers" description:"Notify subscribers when creating or updating articles" default:"false"`
ContentsDir string `yaml:"contents_dir" description:"Path to the contents directory" default:"."`
}
Expand All @@ -36,9 +36,6 @@ func (c *Config) Validation() error {
if c.DefaultPermissionGroupID == 0 {
return fmt.Errorf("default_permission_group_id is required")
}
if c.DefailtUserSegmentID == 0 {
return fmt.Errorf("default_user_segment_id is required")
}
return nil
}

Expand Down
9 changes: 5 additions & 4 deletions internal/cli/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import "testing"

func TestLoadConfig(t *testing.T) {
refDefaultUserSegmentID := 456
tests := []struct {
configPath string
subdomain string
Expand All @@ -11,7 +12,7 @@ func TestLoadConfig(t *testing.T) {
defaultCommentsDisabled bool
defaultLocale string
defaultPermissionGroupID int
defaultUserSegmentID int
defaultUserSegmentID *int
notifySubscribers bool
contentsDir string
}{
Expand All @@ -23,7 +24,7 @@ func TestLoadConfig(t *testing.T) {
true,
"ja",
123,
456,
&refDefaultUserSegmentID,
false,
"example",
},
Expand All @@ -35,7 +36,7 @@ func TestLoadConfig(t *testing.T) {
false,
"ja",
123,
456,
nil,
false,
".",
},
Expand Down Expand Up @@ -68,7 +69,7 @@ func TestLoadConfig(t *testing.T) {
if g.Config.DefaultPermissionGroupID != tt.defaultPermissionGroupID {
t.Errorf("Config.DefaultPermissionGroupID failed: got %v, want %v", g.Config.DefaultPermissionGroupID, tt.defaultPermissionGroupID)
}
if g.Config.DefailtUserSegmentID != tt.defaultUserSegmentID {
if g.Config.DefailtUserSegmentID != nil && *g.Config.DefailtUserSegmentID != *tt.defaultUserSegmentID {
t.Errorf("Config.DefailtUserSegmentID failed: got %v, want %v", g.Config.DefailtUserSegmentID, tt.defaultUserSegmentID)
}
if g.Config.NotifySubscribers != tt.notifySubscribers {
Expand Down
1 change: 0 additions & 1 deletion internal/cli/testdata/config_no_required.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ email: hoge@example.com
token: foobarfoobar
default_locale: ja
default_permission_group_id: 123
default_user_segment_id: 456
4 changes: 2 additions & 2 deletions internal/converter/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func TestConvertToHTML(t *testing.T) {
// TOOD: implement this test
// TODO: implement this test
}

func TestConvertToHTML_Div(t *testing.T) {
Expand Down Expand Up @@ -98,7 +98,7 @@ func TestConvertToHTML_Headings(t *testing.T) {
}

func TestConvertToMarkdown(t *testing.T) {
// TOOD: implement this test
// TODO: implement this test
}

func TestConvertToMarkdown_PluckAttributes(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/zendesk/article.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Article struct {
Title string `json:"title" yaml:"title"`
UpdatedAt string `json:"updated_at,omitempty" yaml:"updated_at"`
Url string `json:"url,omitempty" yaml:"url"`
UserSegmentID int `json:"user_segment_id" yaml:"user_segment_id"`
UserSegmentID *int `json:"user_segment_id" yaml:"user_segment_id"`
UserSegmentIDs []int `json:"user_segment_ids,omitempty" yaml:"user_segment_ids"`
VoteCount int `json:"vote_count,omitempty" yaml:"vote_count"`
VoteSum int `json:"vote_sum,omitempty" yaml:"vote_sum"`
Expand Down
14 changes: 8 additions & 6 deletions internal/zendesk/article_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
)

func TestArticleFromFile(t *testing.T) {
var tests = []struct {
refUserSegmentID := 123
tests := []struct {
filepath string
expected Article
}{
Expand All @@ -25,7 +26,7 @@ func TestArticleFromFile(t *testing.T) {
Locale: "en_us",
PermissionGroupID: 56,
Title: "How to use zgsync",
UserSegmentID: 123,
UserSegmentID: &refUserSegmentID,
},
},
}
Expand All @@ -45,7 +46,7 @@ func TestArticleFromFile(t *testing.T) {
if article.Title != tt.expected.Title {
t.Errorf("article.Title failed: got %v, want %v", article.Title, tt.expected.Title)
}
if article.UserSegmentID != tt.expected.UserSegmentID {
if article.UserSegmentID != nil && *article.UserSegmentID != *tt.expected.UserSegmentID {
t.Errorf("article.UserSegmentId failed: got %v, want %v", article.UserSegmentID, tt.expected.UserSegmentID)
}
if len(article.UserSegmentIDs) != len(tt.expected.UserSegmentIDs) {
Expand All @@ -56,7 +57,8 @@ func TestArticleFromFile(t *testing.T) {
}

func TestArticleFromJson(t *testing.T) {
var tests = []struct {
refUserSegmentID := 12
tests := []struct {
filepath string
expected Article
}{
Expand All @@ -72,7 +74,7 @@ func TestArticleFromJson(t *testing.T) {
Position: 42,
Promoted: false,
Title: "How to use zgsync",
UserSegmentID: 12,
UserSegmentID: &refUserSegmentID,
},
},
}
Expand Down Expand Up @@ -111,7 +113,7 @@ func TestArticleFromJson(t *testing.T) {
if article.Title != tt.expected.Title {
t.Errorf("article.Title failed: got %v, want %v", article.Title, tt.expected.Title)
}
if article.UserSegmentID != tt.expected.UserSegmentID {
if *article.UserSegmentID != *tt.expected.UserSegmentID {
t.Errorf("article.UserSegmentId failed: got %v, want %v", article.UserSegmentID, tt.expected.UserSegmentID)
}
})
Expand Down

0 comments on commit 84ff634

Please sign in to comment.