Skip to content

Commit

Permalink
Display error message on server side bug creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
vertigo17 committed Jan 15, 2025
1 parent 2e086d7 commit cdf6f7a
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public void purgeCacheEntry(String parameter) {
if (parameter == null || key.contains(parameter)) {
cacheEntry.remove(key);
LOG.debug("Purged Parameter " + key + " from cache entries.");

}
}
} catch (ConcurrentModificationException e) {
Expand Down Expand Up @@ -135,14 +134,14 @@ public Parameter findParameterByKey(String key, String system) throws CerberusEx
LOG.debug("Trying to retrieve parameter (default value) : " + key + " - []");
myParameter = parameterDao.findParameterByKey("", key);
if (myParameter != null) {
LOG.debug("Insert parameter to cache.");
LOG.debug("Insert parameter '" + cacheKey + "' to cache.");
myParameter.setCacheEntryCreation(currentTime);
cacheEntry.put(cacheKey, myParameter);
}
return myParameter;
}
if (myParameter != null) {
LOG.debug("Insert parameter to cache.");
LOG.debug("Insert parameter '" + cacheKey + "' to cache.");
myParameter.setCacheEntryCreation(currentTime);
cacheEntry.put(cacheKey, myParameter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,52 +171,68 @@ public boolean isTrusted(X509Certificate[] chain, String authType) throws Certif
String bearerAuth = parameterService.getParameterStringByKey(Parameter.VALUE_cerberus_github_apitoken, "", "");
post.setHeader("Authorization", "Bearer " + bearerAuth);

try {

LOG.debug("Calling {} with Authent {}", githubUrl, bearerAuth);
HttpResponse response = httpclient.execute(post);

int rc = response.getStatusLine().getStatusCode();
if (rc >= 200 && rc < 300) {
LOG.debug("Github Issue Creation request http return code : " + rc);
String responseString = EntityUtils.toString(response.getEntity());
LOG.debug("Response : {}", responseString);
JSONObject githubResponse = new JSONObject(responseString);
String newGithubBugURL = "";
int githubIssueKey = 0;
if (githubResponse.has("number")) {
githubIssueKey = githubResponse.getInt("number");
if (githubResponse.has("html_url")) {
URL ghURL = new URL(githubResponse.getString("html_url"));
newGithubBugURL = ghURL.toString();
if (StringUtil.isEmptyOrNull(bearerAuth)) {
newBugCreated.put("message", "Mandatory parameter value not defined for parameter : '" + Parameter.VALUE_cerberus_github_apitoken + "'");
newBugCreated.put("statusCode", 500);
} else {

try {

LOG.debug("Calling {} with Authent {}", githubUrl, bearerAuth);
HttpResponse response = httpclient.execute(post);

int rc = response.getStatusLine().getStatusCode();
if (rc >= 200 && rc < 300) {
LOG.debug("Github Issue Creation request http return code : " + rc);
String responseString = EntityUtils.toString(response.getEntity());
LOG.debug("Response : {}", responseString);
JSONObject githubResponse = new JSONObject(responseString);
String newGithubBugURL = "";
int githubIssueKey = 0;
if (githubResponse.has("number")) {
githubIssueKey = githubResponse.getInt("number");
if (githubResponse.has("html_url")) {
URL ghURL = new URL(githubResponse.getString("html_url"));
newGithubBugURL = ghURL.toString();
}
// Update here the test case with new issue.
newBugCreated.put("bug", testCaseService.addNewBugEntry(tc, execution.getTest(), execution.getTestCase(), String.valueOf(githubIssueKey), newGithubBugURL, "Created from Execution " + execution.getId()));
newBugCreated.put("message", "Bug '" + String.valueOf(githubIssueKey) + "' successfully created on Test case : '" + execution.getTest() + "' - '" + execution.getTestCase() + "' from execution : " + execution.getId());
newBugCreated.put("statusCode", 200);
LOG.debug("Setting new GITHUB Issue '{}' to test case '{} - {}'", githubResponse.getInt("number"), execution.getTest() + execution.getTestCase());
} else {
LOG.warn("Github Issue creation request http return code : {} is missing 'number' entry.", rc);
String message = "Github Issue creation request to '" + githubUrl + "' failed with http return code : " + rc + ". and no 'number' entry. " + responseString;
logEventService.createForPrivateCalls("GITHUB", "APICALL", LogEvent.STATUS_WARN, message);
LOG.warn("Message sent to " + githubUrl + " :");
LOG.warn(githubRequest.toString(1));
LOG.warn("Response : {}", responseString);
newBugCreated.put("message", message);
newBugCreated.put("statusCode", 500);
}
// Update here the test case with new issue.
newBugCreated = testCaseService.addNewBugEntry(tc, execution.getTest(), execution.getTestCase(), String.valueOf(githubIssueKey), newGithubBugURL, "Created from Execution " + execution.getId());
LOG.debug("Setting new GITHUB Issue '{}' to test case '{} - {}'", githubResponse.getInt("number"), execution.getTest() + execution.getTestCase());
} else {
LOG.warn("Github Issue creation request http return code : {} is missing 'number' entry.", rc);
String message = "Github Issue creation request to '" + githubUrl + "' failed with http return code : " + rc + ". and no 'number' entry. " + responseString;
LOG.warn("Github Issue creation request http return code : " + rc);
String responseString = EntityUtils.toString(response.getEntity());
String message = "Github Issue creation request to '" + githubUrl + "' failed with http return code : " + rc + ". " + responseString;
logEventService.createForPrivateCalls("GITHUB", "APICALL", LogEvent.STATUS_WARN, message);
LOG.warn("Message sent to " + githubUrl + " :");
LOG.warn(githubRequest.toString(1));
LOG.warn("Response : {}", responseString);
newBugCreated.put("message", message);
newBugCreated.put("statusCode", 500);
}
} else {
LOG.warn("Github Issue creation request http return code : " + rc);
String responseString = EntityUtils.toString(response.getEntity());
String message = "Github Issue creation request to '" + githubUrl + "' failed with http return code : " + rc + ". " + responseString;
logEventService.createForPrivateCalls("GITHUB", "APICALL", LogEvent.STATUS_WARN, message);
LOG.warn("Message sent to " + githubUrl + " :");
LOG.warn(githubRequest.toString(1));
LOG.warn("Response : {}", responseString);
}

} catch (IOException e) {
LOG.warn("Github Issue creation request Exception : " + e, e);
logEventService.createForPrivateCalls("GITHUB", "APICALL", LogEvent.STATUS_WARN, "GITHUB Issue creation request to '" + githubUrl + "' failed : " + e.toString() + ".");
} catch (IOException e) {
LOG.warn("Github Issue creation request Exception : " + e, e);
logEventService.createForPrivateCalls("GITHUB", "APICALL", LogEvent.STATUS_WARN, "GITHUB Issue creation request to '" + githubUrl + "' failed : " + e.toString() + ".");
newBugCreated.put("message", "GITHUB Issue creation request Exception : " + e.toString());
newBugCreated.put("statusCode", 500);
}
}

} catch (Exception ex) {
newBugCreated.put("message", ex.toString());
newBugCreated.put("statusCode", 500);
LOG.error(ex, ex);
}
return newBugCreated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public JSONObject createBug(TestCaseExecution execution, boolean forceCreation)
if (!parameterService.getParameterBooleanByKey(Parameter.VALUE_cerberus_autobugcreation_enable, execution.getSystem(), false)) {
LOG.debug("Not creating bug due to parameter.");
newBugCreated.put("message", "Not creating bug due to parameter : " + Parameter.VALUE_cerberus_autobugcreation_enable);
newBugCreated.put("statusCode", 400);
return newBugCreated;
}
LOG.debug("Trying to create bug.");
Expand All @@ -97,16 +98,17 @@ public JSONObject createBug(TestCaseExecution execution, boolean forceCreation)
} catch (CerberusException ex) {
LOG.warn(ex, ex);
newBugCreated.put("message", ex.toString());
newBugCreated.put("statusCode", 500);
}

if (currentAppli != null) {
switch (currentAppli.getBugTrackerConnector()) {
case Application.BUGTRACKER_JIRA:
newBugCreated.put("bug", jiraService.createJiraIssue(tc, execution, currentAppli.getBugTrackerParam1(), currentAppli.getBugTrackerParam2()));
newBugCreated = jiraService.createJiraIssue(tc, execution, currentAppli.getBugTrackerParam1(), currentAppli.getBugTrackerParam2());

break;
case Application.BUGTRACKER_GITHUB:
newBugCreated.put("bug", githubService.createGithubIssue(tc, execution, currentAppli.getBugTrackerParam1(), currentAppli.getBugTrackerParam2()));
newBugCreated = githubService.createGithubIssue(tc, execution, currentAppli.getBugTrackerParam1(), currentAppli.getBugTrackerParam2());

break;
default:
Expand All @@ -115,11 +117,13 @@ public JSONObject createBug(TestCaseExecution execution, boolean forceCreation)
}
} else {
LOG.debug("Not opening Issue because issue is already open");
newBugCreated.put("message", "Not opening Issue because issue is already open");
newBugCreated.put("message", "Issue not created because an issue is already open on the same testcase");
newBugCreated.put("statusCode", 400);
execution.addExecutionLog(ExecutionLog.STATUS_INFO, "Bug creation - There is already an open bug reported.");
}
} catch (CerberusException ex) {
newBugCreated.put("message", ex.toString());
newBugCreated.put("statusCode", 500);
LOG.warn(ex, ex);
}
}
Expand Down
Loading

0 comments on commit cdf6f7a

Please sign in to comment.