Skip to content

Commit

Permalink
Automatic ticket creation (improvements and Github connector).
Browse files Browse the repository at this point in the history
  • Loading branch information
vertigo17 committed Sep 3, 2024
1 parent 5d6468f commit 7f49490
Show file tree
Hide file tree
Showing 16 changed files with 610 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ public Application(String application) {
public static final String TYPE_FAT = "FAT";
public static final String TYPE_NONE = "NONE";

public static final String BUGTRACKER_REDIRECT = "REDIRECT";
public static final String BUGTRACKER_NONE = "NONE";
public static final String BUGTRACKER_JIRA = "JIRA";
public static final String BUGTRACKER_GITHUB = "GITHUB";

public boolean hasSameKey(Application obj) {
if (obj == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ public class Parameter {
public static final String VALUE_cerberus_jiracloud_apiuser = "cerberus_jiracloud_apiuser";
public static final String VALUE_cerberus_jiracloud_apiuser_apitoken = "cerberus_jiracloud_apiuser_apitoken";
public static final String VALUE_cerberus_autobugcreation_enable = "cerberus_autobugcreation_enable";
public static final String VALUE_cerberus_github_apitoken = "cerberus_github_apitoken";

public static final String SECUREDPARAMINSQLCLAUSE = "(\"cerberus_accountcreation_defaultpassword\",\"cerberus_proxyauthentification_password\",\"cerberus_jenkinsadmin_password\","
+ "\"cerberus_smtp_password\",\"cerberus_executeCerberusCommand_password\",\"cerberus_xraycloud_clientsecret\",\"cerberus_xraycloud_clientid\",\"cerberus_xraydc_token\",\"cerberus_jiracloud_apiuser_apitoken\")";
+ "\"cerberus_smtp_password\",\"cerberus_executeCerberusCommand_password\",\"cerberus_xraycloud_clientsecret\",\"cerberus_xraycloud_clientid\",\"cerberus_xraydc_token\","
+ "\"cerberus_jiracloud_apiuser_apitoken\",\"cerberus_github_apitoken\")";

public static final Integer CACHE_DURATION = 60;
public static final Integer SHORT_CACHE_DURATION = 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
import java.util.List;
import org.cerberus.core.engine.entity.Identifier;
import org.cerberus.core.engine.execution.IIdentifierService;
import org.cerberus.core.service.jira.IJiraService;
import org.cerberus.core.service.bug.IBugService;
import org.cerberus.core.service.robotextension.impl.SikuliService;
import org.cerberus.core.service.xray.IXRayService;
import org.cerberus.core.service.robotproxy.IRobotProxyService;
Expand Down Expand Up @@ -157,7 +157,7 @@ public class ExecutionRunService implements IExecutionRunService {
private IRobotProxyService executorService;
private IEventService eventService;
private IXRayService xRayService;
private IJiraService jiraService;
private IBugService bugService;
private IIdentifierService identifierService;

@Override
Expand Down Expand Up @@ -911,7 +911,7 @@ startStep, startStep, startStep, startStep, new BigDecimal("0"), null, stepMess,
// JIRA Issue creation Connector is triggered at the end of every execution..
// TODO Add conditions in order to create it only when testcase is stable enought.
if (!willBeRetried) {
jiraService.createIssue(execution);
bugService.createIssue(execution);
}

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Cerberus Copyright (C) 2013 - 2017 cerberustesting
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This file is part of Cerberus.
*
* Cerberus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cerberus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cerberus. If not, see <http://www.gnu.org/licenses/>.
*/
package org.cerberus.core.service.bug;

import org.cerberus.core.crud.entity.TestCaseExecution;
import org.json.JSONArray;

/**
*
* @author vertigo17
*/
public interface IBugService {

/**
*
* @param execution
*/
public void createIssue(TestCaseExecution execution);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Cerberus Copyright (C) 2013 - 2017 cerberustesting
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This file is part of Cerberus.
*
* Cerberus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cerberus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cerberus. If not, see <http://www.gnu.org/licenses/>.
*/
package org.cerberus.core.service.bug.github;

import org.cerberus.core.crud.entity.TestCaseExecution;
import org.json.JSONObject;

/**
*
* @author vertigo17
*/
public interface IGithubGenerationService {

/**
*
* @param issueTypeName
* @param execution
* @return
* @throws Exception
*/
public JSONObject generateGithubIssue(TestCaseExecution execution, String issueTypeName) throws Exception;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Cerberus Copyright (C) 2013 - 2017 cerberustesting
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This file is part of Cerberus.
*
* Cerberus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cerberus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cerberus. If not, see <http://www.gnu.org/licenses/>.
*/
package org.cerberus.core.service.bug.github;

import org.cerberus.core.crud.entity.TestCaseExecution;

/**
*
* @author vertigo17
*/
public interface IGithubService {

/**
*
* @param execution
* @param repoName
* @param labelType
*/
public void createGithubIssue(TestCaseExecution execution, String repoName, String labelType);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* Cerberus Copyright (C) 2013 - 2017 cerberustesting
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This file is part of Cerberus.
*
* Cerberus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cerberus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cerberus. If not, see <http://www.gnu.org/licenses/>.
*/
package org.cerberus.core.service.bug.github.impl;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.cerberus.core.crud.entity.TestCaseExecution;
import org.cerberus.core.crud.service.IParameterService;
import org.cerberus.core.crud.service.ITagService;
import org.cerberus.core.util.StringUtil;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.json.JSONArray;
import org.json.JSONException;
import org.cerberus.core.service.bug.github.IGithubGenerationService;

/**
*
* @author vertigo17
*/
@Service
public class GithubGenerationService implements IGithubGenerationService {

private static final org.apache.logging.log4j.Logger LOG = org.apache.logging.log4j.LogManager.getLogger(GithubGenerationService.class);

@Autowired
private IParameterService parameterService;
@Autowired
private ITagService tagService;

@Override
public JSONObject generateGithubIssue(TestCaseExecution execution, String LabelName) {
JSONObject issueObject = new JSONObject();

try {
String cerberusUrl = parameterService.getParameterStringByKey("cerberus_gui_url", "", "");
if (StringUtil.isEmptyOrNull(cerberusUrl)) {
cerberusUrl = parameterService.getParameterStringByKey("cerberus_url", "", "");
}
cerberusUrl = StringUtil.addSuffixIfNotAlready(cerberusUrl, "/");

String cerberusUrlExe = cerberusUrl + "TestCaseExecution.jsp?executionId=" + String.valueOf(execution.getId());
String cerberusUrlTag = cerberusUrl + "ReportingExecutionByTag.jsp?Tag=" + URLEncoder.encode(execution.getTag(), "UTF-8");
String cerberusUrlExeHisto = cerberusUrl + "ReportingExecutionOverTime.jsp?tests=" + URLEncoder.encode(execution.getTest(), "UTF-8") + "&testcases=" + URLEncoder.encode(execution.getTestCase(), "UTF-8");

issueObject.put("title", "TestCase Execution " + execution.getId() + " failed - " + execution.getTest() + " " + execution.getTestCase());

String body = "Test Case: **" + execution.getTest() + "** - **" + execution.getTestCase() + "** - " + execution.getDescription() + " \n\n";
body += "Executed on " + execution.getEnvironment() + " - " + execution.getCountry() + "\n";
body += "On " + convertToDate(execution.getEnd()) + "\n\n";
body += "Ended with status " + execution.getControlStatus() + "\n **" + execution.getControlMessage() + "**\n\n";
body += "Please check the detailed execution [" + execution.getId() + "](" + cerberusUrlExe + ") \n";
body += "You can also access [latest executions](" + cerberusUrlExeHisto + ") perfomed on that testcase.\n\n";
body += "Execution was triggered from campaign execution [" + execution.getTag() + "](" + cerberusUrlTag + ")";
issueObject.put("body", body);

if (StringUtil.isNotEmptyOrNull(LabelName)) {
JSONArray labels = new JSONArray();
labels.put(LabelName);
issueObject.put("labels", labels);
}

LOG.debug(issueObject.toString(1));

} catch (JSONException ex) {
LOG.debug(ex, ex);
} catch (UnsupportedEncodingException ex) {
LOG.error(ex, ex);
}
return issueObject;

}

private String convertToDate(long cerberusDate) {

SimpleDateFormat formater; // Define the MySQL Format.
formater = new SimpleDateFormat("yyyy-MM-dd' at 'HH:mm:ss");

return formater.format(cerberusDate);

}

private String convertToDate(Timestamp cerberusDate) {

SimpleDateFormat formater; // Define the MySQL Format.
formater = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");

return formater.format(cerberusDate);

}
}
Loading

0 comments on commit 7f49490

Please sign in to comment.