diff --git a/README.md b/README.md index 56e1453..f2344da 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/internal/cli/cmdEmpty.go b/internal/cli/cmdEmpty.go index e6e80fd..b6bc33a 100644 --- a/internal/cli/cmdEmpty.go +++ b/internal/cli/cmdEmpty.go @@ -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:"-"` @@ -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 } diff --git a/internal/cli/config.go b/internal/cli/config.go index c2dadda..d2694c7 100644 --- a/internal/cli/config.go +++ b/internal/cli/config.go @@ -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:"."` } @@ -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 } diff --git a/internal/cli/config_test.go b/internal/cli/config_test.go index 167bdac..4d69fcb 100644 --- a/internal/cli/config_test.go +++ b/internal/cli/config_test.go @@ -3,6 +3,7 @@ package cli import "testing" func TestLoadConfig(t *testing.T) { + refDefaultUserSegmentID := 456 tests := []struct { configPath string subdomain string @@ -11,7 +12,7 @@ func TestLoadConfig(t *testing.T) { defaultCommentsDisabled bool defaultLocale string defaultPermissionGroupID int - defaultUserSegmentID int + defaultUserSegmentID *int notifySubscribers bool contentsDir string }{ @@ -23,7 +24,7 @@ func TestLoadConfig(t *testing.T) { true, "ja", 123, - 456, + &refDefaultUserSegmentID, false, "example", }, @@ -35,7 +36,7 @@ func TestLoadConfig(t *testing.T) { false, "ja", 123, - 456, + nil, false, ".", }, @@ -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 { diff --git a/internal/cli/testdata/config_no_required.yaml b/internal/cli/testdata/config_no_required.yaml index e63ecb1..3eb2a74 100644 --- a/internal/cli/testdata/config_no_required.yaml +++ b/internal/cli/testdata/config_no_required.yaml @@ -3,4 +3,3 @@ email: hoge@example.com token: foobarfoobar default_locale: ja default_permission_group_id: 123 -default_user_segment_id: 456 diff --git a/internal/converter/converter_test.go b/internal/converter/converter_test.go index 0e2dbc4..9608ae1 100644 --- a/internal/converter/converter_test.go +++ b/internal/converter/converter_test.go @@ -11,7 +11,7 @@ import ( ) func TestConvertToHTML(t *testing.T) { - // TOOD: implement this test + // TODO: implement this test } func TestConvertToHTML_Div(t *testing.T) { @@ -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) { diff --git a/internal/zendesk/article.go b/internal/zendesk/article.go index 2c4d974..9b53637 100644 --- a/internal/zendesk/article.go +++ b/internal/zendesk/article.go @@ -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"` diff --git a/internal/zendesk/article_test.go b/internal/zendesk/article_test.go index 5f4df14..1b41727 100644 --- a/internal/zendesk/article_test.go +++ b/internal/zendesk/article_test.go @@ -6,7 +6,8 @@ import ( ) func TestArticleFromFile(t *testing.T) { - var tests = []struct { + refUserSegmentID := 123 + tests := []struct { filepath string expected Article }{ @@ -25,7 +26,7 @@ func TestArticleFromFile(t *testing.T) { Locale: "en_us", PermissionGroupID: 56, Title: "How to use zgsync", - UserSegmentID: 123, + UserSegmentID: &refUserSegmentID, }, }, } @@ -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) { @@ -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 }{ @@ -72,7 +74,7 @@ func TestArticleFromJson(t *testing.T) { Position: 42, Promoted: false, Title: "How to use zgsync", - UserSegmentID: 12, + UserSegmentID: &refUserSegmentID, }, }, } @@ -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) } })