-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use stream to look for error message prefixes #331
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import com.google.common.collect.Multimap; | ||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import org.kohsuke.github.*; | ||
import org.slf4j.Logger; | ||
|
@@ -21,6 +22,7 @@ | |
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Arrays; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
|
@@ -110,18 +112,18 @@ public int createPullReq(GHRepository origRepo, String branch, | |
log.warn("Handling error with pull request creation... {}", e.getMessage()); | ||
JsonElement root = JsonParser.parseString(e.getMessage()); | ||
JsonArray errorJson = root.getAsJsonObject().get("errors").getAsJsonArray(); | ||
String error = ""; | ||
if (errorJson.get(0).getAsJsonObject().has("message")) { | ||
error = errorJson.get(0).getAsJsonObject().get("message").getAsString(); | ||
} else { | ||
// This case usually happens when the PR head has invalid data. Deleting the forked repo resolves it. | ||
error = PR_INVALID_CODE; | ||
String error = PR_INVALID_CODE; | ||
JsonObject errorMessage = errorJson.get(0).getAsJsonObject(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there ever more than 1 error in this array? Any reason not to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about that. This piece of code has been there for a while. |
||
if (errorMessage.has("message")) { | ||
error = errorMessage.get("message").getAsString(); | ||
} | ||
log.info("error: {}", error); | ||
String finalError = error; | ||
List<String> errorPrefixes = Arrays.asList(PR_INVALID_CODE, "No commits between"); | ||
if (error.startsWith("A pull request already exists")) { | ||
Comment on lines
+121
to
123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why you need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I tried using the variable |
||
log.info("NOTE: {} New commits may have been added to the pull request.", error); | ||
return 0; | ||
} else if (error.startsWith("No commits between") || error.startsWith(PR_INVALID_CODE)) { | ||
} else if (errorPrefixes.stream().anyMatch(prefix -> finalError.startsWith(prefix))) { | ||
log.warn("NOTE: {} Pull request was not created.", error); | ||
return 1; | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong lexicographical order for 'java.util.Arrays' import. Should be before 'org.slf4j.LoggerFactory'.