Skip to content

Commit 19e1a00

Browse files
committed
Rename mapping files to include index
1 parent a02a6a2 commit 19e1a00

File tree

422 files changed

+22
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

422 files changed

+22
-4
lines changed

src/test/java/org/kohsuke/github/AppTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,14 @@ public void testListIssues() throws IOException {
218218

219219
@Test
220220
public void testRateLimit() throws IOException {
221-
System.out.println(gitHub.getRateLimit());
221+
assertThat(gitHub.getRateLimit(), notNullValue());
222222
}
223223

224224
@Test
225225
public void testMyOrganizations() throws IOException {
226226
Map<String, GHOrganization> org = gitHub.getMyOrganizations();
227227
assertFalse(org.keySet().contains(null));
228-
System.out.println(org);
228+
//System.out.println(org);
229229
}
230230

231231
@Test

src/test/java/org/kohsuke/github/junit/GitHubApiWireMockRule.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.github.tomakehurst.wiremock.http.Request;
88
import com.github.tomakehurst.wiremock.http.Response;
99
import com.google.gson.*;
10+
import com.jcraft.jsch.IO;
1011

1112
import java.io.File;
1213
import java.io.IOException;
@@ -92,7 +93,7 @@ protected void before() {
9293
protected void after() {
9394
super.after();
9495
// To reformat everything
95-
// formatJsonFiles(new File("src/test/resources").toPath());
96+
//formatJsonFiles(new File("src/test/resources").toPath());
9697

9798
if (isTakeSnapshot()) {
9899
this.snapshotRecord(recordSpec()
@@ -108,7 +109,6 @@ protected void after() {
108109
private void formatJsonFiles(Path path) {
109110
// The more consistent we can make the json output the more meaningful it will be.
110111
// TODO: For understandability, rename the files to include the response order
111-
// TODO: Consider templating out Date and Last-Updated
112112
Gson g = new Gson().newBuilder().serializeNulls().disableHtmlEscaping().setPrettyPrinting()
113113
.registerTypeAdapter(Double.class, new JsonSerializer<Double>() {
114114
@Override
@@ -128,6 +128,9 @@ public JsonElement serialize(Double src, Type typeOfSrc, JsonSerializationContex
128128
String fileText = new String(Files.readAllBytes(filePath));
129129
// Can be Array or Map
130130
Object parsedObject = g.fromJson(fileText, Object.class);
131+
if (parsedObject instanceof Map && filePath.toString().contains("mappings")) {
132+
filePath = renameMappingFile(filePath, (Map<String, Object>) parsedObject);
133+
}
131134
fileText = g.toJson(parsedObject);
132135
Files.write(filePath, fileText.getBytes());
133136
}
@@ -139,4 +142,19 @@ public JsonElement serialize(Double src, Type typeOfSrc, JsonSerializationContex
139142
throw new RuntimeException("Files could not be written");
140143
}
141144
}
145+
146+
private Path renameMappingFile(Path filePath, Map<String, Object> parsedObject) throws IOException {
147+
Path targetPath = filePath;
148+
String id = (String)parsedObject.getOrDefault("id", null);
149+
Long insertionIndex = ((Double)parsedObject.getOrDefault("insertionIndex", 0.0)).longValue();
150+
if (id != null && insertionIndex > 0) {
151+
String filePathString = filePath.toString();
152+
if (filePathString.contains(id)) {
153+
targetPath = new File(filePathString.replace(id, insertionIndex.toString() + "-" + id.substring(0, 6))).toPath();
154+
Files.move(filePath, targetPath);
155+
}
156+
}
157+
158+
return targetPath;
159+
}
142160
}

src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateAndListDeployments/mappings/repos_github-api-test-org_github-api-test-31a86a0d-5120-47b8-a9bc-ec4b34a08080.json renamed to src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateAndListDeployments/mappings/repos_github-api-test-org_github-api-test-2-31a86a.json

File renamed without changes.

src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateAndListDeployments/mappings/repos_github-api-test-org_github-api-test_deployments-702b7123-86c1-41e0-bee7-f3cb89a3236d.json renamed to src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateAndListDeployments/mappings/repos_github-api-test-org_github-api-test_deployments-3-702b71.json

File renamed without changes.

src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateAndListDeployments/mappings/repos_github-api-test-org_github-api-test_deployments-b4bcdadb-a708-4509-9382-479f300eb172.json renamed to src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateAndListDeployments/mappings/repos_github-api-test-org_github-api-test_deployments-4-b4bcda.json

File renamed without changes.

src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateAndListDeployments/mappings/user-6d2dcbf4-4abf-4180-9b55-ca2931ca31c5.json renamed to src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateAndListDeployments/mappings/user-1-6d2dcb.json

File renamed without changes.

src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateIssue/mappings/repos_github-api-test-org_github-api-test-2d35cecf-0212-47d5-8dd3-15b4838d56c6.json renamed to src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateIssue/mappings/repos_github-api-test-org_github-api-test-2-2d35ce.json

File renamed without changes.

src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateIssue/mappings/repos_github-api-test-org_github-api-test_hooks-0765fda8-b2f8-4474-8936-f02c33023e52.json renamed to src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateIssue/mappings/repos_github-api-test-org_github-api-test_hooks-4-0765fd.json

File renamed without changes.

src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateIssue/mappings/repos_github-api-test-org_github-api-test_hooks-9f3310d4-dd87-4af5-8a0d-1b4dfa8eb868.json renamed to src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateIssue/mappings/repos_github-api-test-org_github-api-test_hooks-5-9f3310.json

File renamed without changes.

src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateIssue/mappings/repos_github-api-test-org_github-api-test_hooks-3dddac88-e8cb-4c36-ab50-157ef996f9b3.json renamed to src/test/resources/org/kohsuke/github/AppTest/wiremock/testCreateIssue/mappings/repos_github-api-test-org_github-api-test_hooks-7-3dddac.json

File renamed without changes.

0 commit comments

Comments
 (0)