Skip to content

Commit 6bd208e

Browse files
committed
fix: no double quote and header for YAML
1 parent 8846e3d commit 6bd208e

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

app/src/main/java/com/github/codingpot/github_org_member_manage_action/config/ConfigManager.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
5+
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
56
import com.github.codingpot.github_org_member_manage_action.context.Context;
67
import java.io.File;
78
import java.io.IOException;
@@ -32,7 +33,11 @@ public void write(ConfigData data) throws IOException {
3233
return;
3334
}
3435
var filepath = this.context.getMembersFilePath();
35-
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
36+
ObjectMapper mapper =
37+
new ObjectMapper(
38+
new YAMLFactory()
39+
.enable(YAMLGenerator.Feature.MINIMIZE_QUOTES)
40+
.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER));
3641
mapper.writeValue(new File(filepath), data);
3742
}
3843
}

app/src/test/java/com/github/codingpot/github_org_member_manage_action/ConfigManagerTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.codingpot.github_org_member_manage_action;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
45

56
import com.github.codingpot.github_org_member_manage_action.config.ConfigData;
67
import com.github.codingpot.github_org_member_manage_action.config.ConfigManager;
@@ -25,7 +26,7 @@ void setUp() throws IOException {
2526
configManager =
2627
new ConfigManager(
2728
new Context(
28-
path.toUri().getPath(), "FAKE_GITHUB_TOKEN", true, AppMode.SYNC));
29+
path.toUri().getPath(), "FAKE_GITHUB_TOKEN", false, AppMode.SYNC));
2930

3031
String yaml =
3132
"org_name: orgName"
@@ -61,4 +62,21 @@ void readFromLocal() throws IOException {
6162
.build(),
6263
configData);
6364
}
65+
66+
@Test
67+
void testYamlWriteDoesNotContainsUnnecessaryThings() throws IOException {
68+
configManager.write(
69+
ConfigData.builder()
70+
.orgName("orgName")
71+
.admins(Set.of("admin1"))
72+
.members(Set.of("member1"))
73+
.build());
74+
final String s = Files.readString(path);
75+
76+
// should not double quote.
77+
assertFalse(s.contains("\""));
78+
79+
// should not add a start header.
80+
assertFalse(s.contains("---"));
81+
}
6482
}

0 commit comments

Comments
 (0)