Skip to content

Commit 9379ba1

Browse files
committed
Added Gitlab connector for bug creation fixed #2587
1 parent f5a4575 commit 9379ba1

File tree

16 files changed

+496
-19
lines changed

16 files changed

+496
-19
lines changed

source/src/main/java/org/cerberus/core/crud/entity/Application.java

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public Application(String application) {
8888
public static final String BUGTRACKER_NONE = "NONE";
8989
public static final String BUGTRACKER_JIRA = "JIRA";
9090
public static final String BUGTRACKER_GITHUB = "GITHUB";
91+
public static final String BUGTRACKER_GITLAB = "GITLAB";
9192
public static final String BUGTRACKER_AZUREDEVOPS = "AZUREDEVOPS";
9293

9394
public boolean hasSameKey(Application obj) {

source/src/main/java/org/cerberus/core/crud/entity/Parameter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ public class Parameter {
9696
public static final String VALUE_cerberus_autobugcreation_enable = "cerberus_autobugcreation_enable";
9797
public static final String VALUE_cerberus_github_apitoken = "cerberus_github_apitoken";
9898
public static final String VALUE_cerberus_azuredevops_accesstoken = "cerberus_azuredevops_accesstoken";
99+
public static final String VALUE_cerberus_gitlab_apitoken = "cerberus_gitlab_apitoken";
99100

100101
public static final String SECUREDPARAMINSQLCLAUSE = "(\"cerberus_accountcreation_defaultpassword\",\"cerberus_proxyauthentification_password\",\"cerberus_jenkinsadmin_password\","
101102
+ "\"cerberus_smtp_password\",\"cerberus_executeCerberusCommand_password\",\"cerberus_xraycloud_clientsecret\",\"cerberus_xraycloud_clientid\",\"cerberus_xraydc_token\","
102-
+ "\"cerberus_jiracloud_apiuser_apitoken\",\"cerberus_github_apitoken\",\"cerberus_azuredevops_accesstoken\")";
103+
+ "\"cerberus_jiracloud_apiuser_apitoken\",\"cerberus_github_apitoken\",\"cerberus_azuredevops_accesstoken\",\"cerberus_gitlab_apitoken\")";
103104

104105
public static final Integer CACHE_DURATION = 60;
105106
public static final Integer SHORT_CACHE_DURATION = 2;

source/src/main/java/org/cerberus/core/crud/service/impl/ParameterService.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ public boolean isToSecureParameter(Parameter parameter) {
436436
|| parameter.getParam().equals(Parameter.VALUE_cerberus_xraycloud_clientsecret)
437437
|| parameter.getParam().equals(Parameter.VALUE_cerberus_xraydc_token)
438438
|| parameter.getParam().equals(Parameter.VALUE_cerberus_jiracloud_apiuser_apitoken)
439-
|| parameter.getParam().equals(Parameter.VALUE_cerberus_github_apitoken)) {
439+
|| parameter.getParam().equals(Parameter.VALUE_cerberus_github_apitoken)
440+
|| parameter.getParam().equals(Parameter.VALUE_cerberus_gitlab_apitoken)) {
440441
return true;
441442
}
442443
return false;

source/src/main/java/org/cerberus/core/enums/MessageEventEnum.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -391,16 +391,16 @@ public enum MessageEventEnum {
391391
CONTROL_SUCCESS_NOTVISIBLE(300, "OK", "Element '%STRING1%' is present and not visible on the page.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
392392
CONTROL_SUCCESS_CHECKED(300, "OK", "Element '%STRING1%' is checked.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
393393
CONTROL_SUCCESS_NOTCHECKED(300, "OK", "Element '%STRING1%' is not checked.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
394-
CONTROL_SUCCESS_ELEMENTTEXTEQUAL(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is equal to %VALUE% (%CASESENSITIVE%).", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
395-
CONTROL_SUCCESS_ELEMENTTEXTDIFFERENT(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is different than %VALUE% (%CASESENSITIVE%).", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
394+
CONTROL_SUCCESS_ELEMENTTEXTEQUAL(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is equal to '%VALUE%' (%CASESENSITIVE%).", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
395+
CONTROL_SUCCESS_ELEMENTTEXTDIFFERENT(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is different than '%VALUE%' (%CASESENSITIVE%).", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
396396
CONTROL_SUCCESS_ELEMENTTEXTCONTAINS(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' contains '%VALUE%' (%CASESENSITIVE%).", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
397397
CONTROL_SUCCESS_ELEMENTTEXTNOTCONTAINS(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' does not contain '%VALUE%' (%CASESENSITIVE%).", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
398-
CONTROL_SUCCESS_ELEMENTNUMERICEQUAL(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is equal than %VALUE%.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
399-
CONTROL_SUCCESS_ELEMENTNUMERICDIFFERENT(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is different than %VALUE%.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
400-
CONTROL_SUCCESS_ELEMENTNUMERICGREATER(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is greater than %VALUE%.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
401-
CONTROL_SUCCESS_ELEMENTNUMERICGREATEROREQUAL(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is greater or equal to %VALUE%.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
402-
CONTROL_SUCCESS_ELEMENTNUMERICMINOR(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is lower than %VALUE%.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
403-
CONTROL_SUCCESS_ELEMENTNUMERICMINOROREQUAL(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is lower or equal to %VALUE%.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
398+
CONTROL_SUCCESS_ELEMENTNUMERICEQUAL(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is equal than '%VALUE%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
399+
CONTROL_SUCCESS_ELEMENTNUMERICDIFFERENT(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is different than '%VALUE%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
400+
CONTROL_SUCCESS_ELEMENTNUMERICGREATER(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is greater than '%VALUE%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
401+
CONTROL_SUCCESS_ELEMENTNUMERICGREATEROREQUAL(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is greater or equal to '%VALUE%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
402+
CONTROL_SUCCESS_ELEMENTNUMERICMINOR(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is lower than '%VALUE%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
403+
CONTROL_SUCCESS_ELEMENTNUMERICMINOROREQUAL(300, "OK", "Element '%ELEMENT%' with value '%ELEMENTVALUE%' is lower or equal to '%VALUE%'.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
404404
CONTROL_SUCCESS_STRINGARRAYCONTAINS(300, "OK", "Array '%ELEMENT%' contains '%VALUE%' %CASESENSITIVE%.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
405405
CONTROL_SUCCESS_NUMERICARRAYCONTAINS(300, "OK", "Array '%ELEMENT%' contains '%VALUE%'", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),
406406
CONTROL_SUCCESS_ELEMENTTEXTARRAYCONTAINS(300, "OK", "Element array '%ELEMENT%' with value '%ELEMENTVALUE%' contains '%VALUE%' %CASESENSITIVE%.", false, false, false, MessageGeneralEnum.EXECUTION_PE_TESTSTARTED),

source/src/main/java/org/cerberus/core/service/bug/github/impl/GithubService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public class GithubService implements IGithubService {
8888
private static final String DEFAULT_PROXYAUTHENT_USER = "squid";
8989
private static final String DEFAULT_PROXYAUTHENT_PASSWORD = "squid";
9090

91-
private static final String GITHUB_ISSUECREATION_URL_DEFAULT = "https://api.github.com/repos/";
92-
private static final String GITHUB_ISSUECREATION_URLPATH = "/issues";
91+
private static final String GITHUB_ISSUECREATION_URL_DEFAULT = "https://api.github.com/repos";
92+
private static final String GITHUB_ISSUECREATION_URLPATH = "issues";
9393
private static final String GITHUB_API_VERSION = "2022-11-28";
9494

9595
private static final int DEFAULT_XRAY_CACHE_DURATION = 300;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Cerberus Copyright (C) 2013 - 2025 cerberustesting
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This file is part of Cerberus.
6+
*
7+
* Cerberus is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* Cerberus is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with Cerberus. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.cerberus.core.service.bug.gitlab;
21+
22+
import org.cerberus.core.crud.entity.TestCaseExecution;
23+
24+
/**
25+
*
26+
* @author vertigo17
27+
*/
28+
public interface IGitlabGenerationService {
29+
30+
/**
31+
*
32+
* @param issueTypeName
33+
* @param execution
34+
* @return
35+
* @throws Exception
36+
*/
37+
public String generateGitlabDescriptionIssue(TestCaseExecution execution, String issueTypeName) throws Exception;
38+
39+
/**
40+
*
41+
* @param issueTypeName
42+
* @param execution
43+
* @return
44+
* @throws Exception
45+
*/
46+
public String generateGitlabTitleIssue(TestCaseExecution execution, String issueTypeName) throws Exception;
47+
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Cerberus Copyright (C) 2013 - 2025 cerberustesting
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This file is part of Cerberus.
6+
*
7+
* Cerberus is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* Cerberus is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with Cerberus. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.cerberus.core.service.bug.gitlab;
21+
22+
import org.cerberus.core.crud.entity.TestCase;
23+
import org.cerberus.core.crud.entity.TestCaseExecution;
24+
import org.json.JSONObject;
25+
26+
/**
27+
*
28+
* @author vertigo17
29+
*/
30+
public interface IGitlabService {
31+
32+
/**
33+
*
34+
* @param tc
35+
* @param execution
36+
* @param repoName
37+
* @param labelType
38+
* @return
39+
*/
40+
public JSONObject createGitlabIssue(TestCase tc, TestCaseExecution execution, String repoName, String labelType);
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* Cerberus Copyright (C) 2013 - 2025 cerberustesting
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This file is part of Cerberus.
6+
*
7+
* Cerberus is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* Cerberus is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with Cerberus. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.cerberus.core.service.bug.gitlab.impl;
21+
22+
import java.io.UnsupportedEncodingException;
23+
import java.sql.Timestamp;
24+
import java.text.SimpleDateFormat;
25+
import org.cerberus.core.crud.entity.TestCaseExecution;
26+
import org.cerberus.core.crud.service.IParameterService;
27+
import org.cerberus.core.crud.service.ITagService;
28+
import org.cerberus.core.util.StringUtil;
29+
import org.json.JSONException;
30+
import org.springframework.beans.factory.annotation.Autowired;
31+
import org.springframework.stereotype.Service;
32+
import org.cerberus.core.service.bug.gitlab.IGitlabGenerationService;
33+
34+
/**
35+
*
36+
* @author vertigo17
37+
*/
38+
@Service
39+
public class GitlabGenerationService implements IGitlabGenerationService {
40+
41+
private static final org.apache.logging.log4j.Logger LOG = org.apache.logging.log4j.LogManager.getLogger(GitlabGenerationService.class);
42+
43+
@Autowired
44+
private IParameterService parameterService;
45+
@Autowired
46+
private ITagService tagService;
47+
48+
@Override
49+
public String generateGitlabDescriptionIssue(TestCaseExecution execution, String LabelName) {
50+
String issueDescription = "";
51+
52+
try {
53+
String cerberusUrl = parameterService.getParameterStringByKey("cerberus_gui_url", "", "");
54+
if (StringUtil.isEmptyOrNull(cerberusUrl)) {
55+
cerberusUrl = parameterService.getParameterStringByKey("cerberus_url", "", "");
56+
}
57+
cerberusUrl = StringUtil.addSuffixIfNotAlready(cerberusUrl, "/");
58+
59+
String cerberusUrlExe = cerberusUrl + "TestCaseExecution.jsp?executionId=" + String.valueOf(execution.getId());
60+
String cerberusUrlTag = cerberusUrl + "ReportingExecutionByTag.jsp?Tag=" + StringUtil.encodeURL(execution.getTag());
61+
String cerberusUrlExeHisto = cerberusUrl + "ReportingExecutionOverTime.jsp?tests=" + StringUtil.encodeURL(execution.getTest()) + "&testcases=" + StringUtil.encodeURL(execution.getTestCase());
62+
63+
issueDescription = "Test Case: **" + execution.getTest() + "** - **" + execution.getTestCase() + "** - " + execution.getDescription() + " \n\n";
64+
issueDescription += "Executed on " + execution.getEnvironment() + " - " + execution.getCountry() + "\n";
65+
issueDescription += "On " + convertToDate(execution.getEnd()) + "\n\n";
66+
issueDescription += "Ended with status " + execution.getControlStatus() + "\n **" + execution.getControlMessage() + "**\n\n";
67+
issueDescription += "Please check the detailed execution [" + execution.getId() + "](" + cerberusUrlExe + ") \n";
68+
issueDescription += "You can also access [latest executions](" + cerberusUrlExeHisto + ") perfomed on that testcase.\n\n";
69+
issueDescription += "Execution was triggered from campaign execution [" + execution.getTag() + "](" + cerberusUrlTag + ")";
70+
71+
} catch (JSONException ex) {
72+
LOG.debug(ex, ex);
73+
} catch (UnsupportedEncodingException ex) {
74+
LOG.error(ex, ex);
75+
}
76+
return issueDescription;
77+
78+
}
79+
80+
@Override
81+
public String generateGitlabTitleIssue(TestCaseExecution execution, String LabelName) {
82+
String issueObject = "";
83+
84+
try {
85+
86+
issueObject = "TestCase Execution " + execution.getId() + " failed - " + execution.getTest() + " " + execution.getTestCase();
87+
88+
} catch (JSONException ex) {
89+
LOG.debug(ex, ex);
90+
}
91+
return issueObject;
92+
93+
}
94+
95+
private String convertToDate(long cerberusDate) {
96+
97+
SimpleDateFormat formater; // Define the MySQL Format.
98+
formater = new SimpleDateFormat("yyyy-MM-dd' at 'HH:mm:ss");
99+
100+
return formater.format(cerberusDate);
101+
102+
}
103+
104+
private String convertToDate(Timestamp cerberusDate) {
105+
106+
SimpleDateFormat formater; // Define the MySQL Format.
107+
formater = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
108+
109+
return formater.format(cerberusDate);
110+
111+
}
112+
}

0 commit comments

Comments
 (0)