forked from mc1arke/sonarqube-community-branch-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The Github Cloud API now returns an error about the input message being
malformed, seemingly due to a change in how new lines in messages are being handled. As the use of blockquotes around multi-line messages appears to continue to work, the analysis messages are being wrapped in blockquotes rather than double-quotes where they contain newline characters. This requires an interim measure of cloning the InputObject class from the nodes library to alter the String comparison and wrapping since the library is no longer maintained.
- Loading branch information
Showing
5 changed files
with
106 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/main/java/com/github/mc1arke/sonarqube/plugin/almclient/github/v4/InputObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (c) 2018-2024 American Express Travel Related Services Company, Inc, Michael Clarke | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.github.mc1arke.sonarqube.plugin.almclient.github.v4; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public final class InputObject<T> { | ||
private final Map<String, T> map; | ||
|
||
InputObject(Builder<T> builder) { | ||
this.map = builder.map; | ||
} | ||
|
||
String getMessage() { | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
stringBuilder.append("{"); | ||
for (Map.Entry<String, T> entry : map.entrySet()) { | ||
if (stringBuilder.length() != 1) stringBuilder.append(","); | ||
stringBuilder.append(formatGraphQLParameter(entry.getKey(), entry.getValue())); | ||
} | ||
stringBuilder.append("}"); | ||
return stringBuilder.toString(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getMessage(); | ||
} | ||
|
||
public Map<String, T> getMap() { | ||
return this.map; | ||
} | ||
|
||
public static class Builder<T> { | ||
|
||
private final Map<String, T> map = new HashMap<>(); | ||
|
||
public Builder<T> put(String key, T value) { | ||
this.map.put(key, value); | ||
return this; | ||
} | ||
|
||
public InputObject<T> build() { | ||
return new InputObject<>(this); | ||
} | ||
} | ||
|
||
|
||
private static <T> String formatGraphQLParameter(String key, T value) { | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
Pattern pattern = Pattern.compile("^\\$"); | ||
Matcher matcher = pattern.matcher("" + value); | ||
if (value instanceof String && ((String) value).contains("\n")) { | ||
stringBuilder.append(key).append(":\"\"\"").append(value).append("\"\"\""); | ||
} else if (value instanceof String && !matcher.find()) { | ||
stringBuilder.append(key).append(":\"").append(value).append("\""); | ||
} else if (value instanceof List) { | ||
stringBuilder.append(key).append(":").append(formatGraphQLArgumentList((List<?>)value)); | ||
} else if (value instanceof com.github.mc1arke.sonarqube.plugin.almclient.github.v4.InputObject) { | ||
stringBuilder.append(key).append(":").append(((com.github.mc1arke.sonarqube.plugin.almclient.github.v4.InputObject<?>)value).getMessage()); | ||
} else { | ||
stringBuilder.append(key).append(":").append(value); | ||
} | ||
|
||
return stringBuilder.toString(); | ||
} | ||
|
||
private static String formatGraphQLArgumentList(List<?> values) { | ||
StringBuilder stringBuilder = new StringBuilder(); | ||
stringBuilder.append("["); | ||
Pattern p = Pattern.compile("^\\$"); | ||
for (Object value: values) { | ||
if (stringBuilder.length() != 1) stringBuilder.append(","); | ||
Matcher m = p.matcher("" + value); | ||
if (value instanceof String && !m.find()) { | ||
stringBuilder.append("\"").append(value).append("\""); | ||
} else if (value instanceof com.github.mc1arke.sonarqube.plugin.almclient.github.v4.InputObject) { | ||
stringBuilder.append(((InputObject<?>) value).getMessage()); | ||
} else { | ||
stringBuilder.append(value); | ||
} | ||
} | ||
stringBuilder.append("]"); | ||
return stringBuilder.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters