Skip to content

Commit 138665e

Browse files
committed
Changing rule format in PyLint to CODE(codeName)
1 parent dc9f98d commit 138665e

File tree

3 files changed

+44
-36
lines changed

3 files changed

+44
-36
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ repositories {
6363
}
6464

6565
dependencies {
66-
compile 'se.bjurr.violations:violation-comments-lib:1.14'
66+
compile 'se.bjurr.violations:violation-comments-lib:1.15'
6767
compile 'com.jayway.jsonpath:json-path:2.0.0'
6868

6969
testCompile 'junit:junit:4.12'

src/main/java/se/bjurr/violations/comments/bitbucketserver/lib/client/BitbucketServerClient.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public static void setBitbucketServerInvoker(BitbucketServerInvoker bitbucketSer
1717
}
1818

1919
private final String bitbucketServerBaseUrl;
20+
2021
private final String bitbucketServerPassword;
2122
private final String bitbucketServerProject;
2223
private final Integer bitbucketServerPullRequestId;
@@ -37,14 +38,29 @@ public BitbucketServerClient(String bitbucketServerBaseUrl, String bitbucketServ
3738
this.bitbucketServerUser = bitbucketServerUser;
3839
}
3940

41+
private String getBitbucketServerPulLRequestBase() {
42+
return bitbucketServerBaseUrl + "/rest/api/1.0/projects/" + bitbucketServerProject + "/repos/" + bitbucketServerRepo
43+
+ "/pull-requests/" + bitbucketServerPullRequestId;
44+
}
45+
46+
private <T> T invokeAndParse(String url, String jsonPath) {
47+
String json = bitbucketServerInvoker.invokeUrl(url, BitbucketServerInvoker.Method.GET, null, bitbucketServerUser,
48+
bitbucketServerPassword);
49+
try {
50+
return JsonPath.read(json, jsonPath);
51+
} catch (Exception e) {
52+
throw e;
53+
}
54+
}
55+
4056
public List<String> pullRequestChanges() {
4157
return invokeAndParse(getBitbucketServerPulLRequestBase() + "/changes?limit=999999", "$..path.toString");
4258
}
4359

4460
public void pullRequestComment(String message) {
4561
String postContent = "{ \"text\": \"" + safeJson(message) + "\"}";
4662
bitbucketServerInvoker.invokeUrl(getBitbucketServerPulLRequestBase() + "/comments",
47-
BitbucketServerInvoker.Method.POST, postContent, this.bitbucketServerUser, this.bitbucketServerPassword);
63+
BitbucketServerInvoker.Method.POST, postContent, bitbucketServerUser, bitbucketServerPassword);
4864
}
4965

5066
public void pullRequestComment(String changedFile, int line, String message) {
@@ -54,38 +70,24 @@ public void pullRequestComment(String changedFile, int line, String message) {
5470
String postContent = "{ \"text\": \"" + safeJson(message) + "\", \"anchor\": { \"line\": " + line
5571
+ ", \"lineType\": \"ADDED\", \"fileType\": \"TO\", \"path\": \"" + changedFile + "\" }}";
5672
bitbucketServerInvoker.invokeUrl(getBitbucketServerPulLRequestBase() + "/comments",
57-
BitbucketServerInvoker.Method.POST, postContent, this.bitbucketServerUser, this.bitbucketServerPassword);
73+
BitbucketServerInvoker.Method.POST, postContent, bitbucketServerUser, bitbucketServerPassword);
5874
}
5975

6076
public List<BitbucketServerComment> pullRequestComments(String changedFile) {
61-
List<LinkedHashMap<?, ?>> parsed = invokeAndParse(getBitbucketServerPulLRequestBase() + "/comments?path="
62-
+ changedFile + "&limit=999999", "$.values[*]");
77+
List<LinkedHashMap<?, ?>> parsed = invokeAndParse(
78+
getBitbucketServerPulLRequestBase() + "/comments?path=" + changedFile + "&limit=999999", "$.values[*]");
6379
return toBitbucketServerComments(parsed);
6480
}
6581

6682
public void pullRequestRemoveComment(Integer commentId, Integer commentVersion) {
67-
bitbucketServerInvoker.invokeUrl(getBitbucketServerPulLRequestBase() + "/comments/" + commentId + "?version="
68-
+ commentVersion, BitbucketServerInvoker.Method.DELETE, null, this.bitbucketServerUser,
69-
this.bitbucketServerPassword);
83+
bitbucketServerInvoker.invokeUrl(
84+
getBitbucketServerPulLRequestBase() + "/comments/" + commentId + "?version=" + commentVersion,
85+
BitbucketServerInvoker.Method.DELETE, null, bitbucketServerUser, bitbucketServerPassword);
7086
}
7187

72-
private String getBitbucketServerPulLRequestBase() {
73-
return this.bitbucketServerBaseUrl + "/rest/api/1.0/projects/" + this.bitbucketServerProject + "/repos/"
74-
+ this.bitbucketServerRepo + "/pull-requests/" + this.bitbucketServerPullRequestId;
75-
}
76-
77-
private <T> T invokeAndParse(String url, String jsonPath) {
78-
String json = bitbucketServerInvoker.invokeUrl(url, BitbucketServerInvoker.Method.GET, null,
79-
this.bitbucketServerUser, this.bitbucketServerPassword);
80-
try {
81-
return JsonPath.read(json, jsonPath);
82-
} catch (Exception e) {
83-
throw e;
84-
}
85-
}
86-
87-
private String safeJson(String message) {
88-
return message.replaceAll("\"", "").replaceAll("\n", "\\\\n");
88+
@VisibleForTesting
89+
String safeJson(String message) {
90+
return message.replaceAll("\\\\", "\\\\\\\\").replaceAll("\"", "").replaceAll("\n", "\\\\n");
8991
}
9092

9193
private List<BitbucketServerComment> toBitbucketServerComments(List<LinkedHashMap<?, ?>> parsed) {

src/test/java/se/bjurr/violations/comments/bitbucketserver/lib/client/BitbucketServerClientTest.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,44 +13,50 @@
1313

1414
public class BitbucketServerClientTest {
1515
private String mockedJson = null;
16-
private final BitbucketServerClient sut = new BitbucketServerClient("bitbucketServerBaseUrl",
17-
"bitbucketServerProject", "bitbucketServerRepo", 1, "bitbucketServerUser", "bitbucketServerPassword");
16+
private final BitbucketServerClient sut = new BitbucketServerClient("bitbucketServerBaseUrl", "bitbucketServerProject",
17+
"bitbucketServerRepo", 1, "bitbucketServerUser", "bitbucketServerPassword");
1818

1919
@Before
2020
public void before() {
2121
BitbucketServerClient.setBitbucketServerInvoker(new BitbucketServerInvoker() {
2222
@Override
2323
public String invokeUrl(String url, Method method, String postContent, String bitbucketServerUser,
2424
String bitbucketServerPassword) {
25-
return BitbucketServerClientTest.this.mockedJson;
25+
return mockedJson;
2626
}
2727
});
2828
}
2929

30+
private void mockJson(String resourceName) {
31+
try {
32+
mockedJson = Resources.toString(Resources.getResource(resourceName), Charsets.UTF_8);
33+
} catch (IOException e) {
34+
e.printStackTrace();
35+
}
36+
}
37+
3038
@Test
3139
public void testPullRequestChanges() {
3240
mockJson("pull-request-changes.json");
33-
List<String> actual = this.sut.pullRequestChanges();
41+
List<String> actual = sut.pullRequestChanges();
3442
assertThat(actual).isNotEmpty();
3543
assertThat(actual.get(0)).isEqualTo("basic_branching/file.txt");
3644
}
3745

3846
@Test
3947
public void testPullRequestCommentsOnFile() {
4048
mockJson("pull-request-comments.json");
41-
List<BitbucketServerComment> actual = this.sut.pullRequestComments("any/file.txt");
49+
List<BitbucketServerComment> actual = sut.pullRequestComments("any/file.txt");
4250
assertThat(actual).isNotEmpty();
4351
assertThat(actual.get(0).getId()).isEqualTo(2);
4452
assertThat(actual.get(0).getText()).isEqualTo("in diff comment");
4553
assertThat(actual.get(0).getVersion()).isEqualTo(0);
4654
}
4755

48-
private void mockJson(String resourceName) {
49-
try {
50-
this.mockedJson = Resources.toString(Resources.getResource(resourceName), Charsets.UTF_8);
51-
} catch (IOException e) {
52-
e.printStackTrace();
53-
}
56+
@Test
57+
public void testSaveJson() {
58+
assertThat(sut.safeJson("...ring: '\\s'. \nStr\"i\"ng ..."))//
59+
.isEqualTo("...ring: '\\\\s'. \\nString ...");
5460
}
5561

5662
}

0 commit comments

Comments
 (0)