Repository: aklajnert/changelogd

Issue:
Trim whitespace before/after comma in multiple: true fields
* changelogd version: 0.1.5
* Python version: 3.10.6
* Operating System: Mac OS

### Description

When I add multiple entries to an entry for a field with `multiple: true`, if I put a space after the comma, the value for the second entry (and subsequent entries) end up being single quoted with a leading space in the entry.yaml file. Since this happens while producing the entry.yaml file, trimming the whitespace in the entry.md template doesn't help. So I'd need a config option or just have it trim the whitespace before/after the comma separated values by default. 

### What I Did

```
# entry
changelogd entry

Select message type [1]: 1
Merge Request (number only) (required): 1
Messages (separate multiple values with comma): string1, string2
Created changelog entry at /pathToRepo/changelog.d/other.56871af2.entry.yaml

# entry.yaml output example
merge_request: '1'
messages:
- string1
- ' string2'
timestamp: 1663063391
type: other
```

Comments:

Patch:
diff --git a/changelog.d/minor.a6ea1885.entry.yaml b/changelog.d/minor.a6ea1885.entry.yaml
new file mode 100644
index 0000000..7734ed4
--- /dev/null
+++ b/changelog.d/minor.a6ea1885.entry.yaml
@@ -0,0 +1,5 @@
+message: Trim whitespace from multi-value fields.
+pr_ids:
+- '26'
+timestamp: 1665243991
+type: minor
diff --git a/changelogd/changelogd.py b/changelogd/changelogd.py
index 74d7b2f..273d1b4 100644
--- a/changelogd/changelogd.py
+++ b/changelogd/changelogd.py
@@ -1,9 +1,11 @@
 # -*- coding: utf-8 -*-
 """Main module."""
+import csv
 import datetime
 import getpass
 import glob
 import hashlib
+import io
 import json
 import logging
 import os
@@ -60,7 +62,9 @@ class EntryField:
             if value is None and not self.required:
                 break
         if value is not None and self.multiple:
-            value = value.split(",")
+            csv_string = io.StringIO(value)
+            reader = csv.reader(csv_string, delimiter=",")
+            value = [value.strip() for value in next(reader)]
         return value
 
 


Test patch:
diff --git a/tests/test_entry.py b/tests/test_entry.py
index 11791a0..4dbe575 100644
--- a/tests/test_entry.py
+++ b/tests/test_entry.py
@@ -111,6 +111,34 @@ def test_non_interactive_data(setup_env, type_input):
     }
 
 
+def test_multi_value_string(setup_env):
+    runner = CliRunner()
+    runner.invoke(commands.init)
+
+    entry = runner.invoke(
+        commands.entry,
+        ["--type", "1", "--message", "test message"],
+        input='a, b,"c,d", e,f',
+    )
+    assert entry.exit_code == 0
+
+    entries = glob.glob(str(setup_env / "changelog.d" / "*entry.yaml"))
+    assert len(entries) == 1
+
+    with open(entries[0]) as entry_fh:
+        entry_content = yaml.load(entry_fh)
+
+    assert entry_content.pop("timestamp")
+    assert entry_content == {
+        "git_email": "user@example.com",
+        "git_user": "Some User",
+        "issue_id": ["a", "b", "c,d", "e", "f"],
+        "message": "test message",
+        "os_user": "test-user",
+        "type": "feature",
+    }
+
+
 def test_entry_missing_message_types(setup_env, caplog):
     runner = CliRunner()
     runner.invoke(commands.init)