/
utils.js
75 lines (64 loc) · 2.48 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//# sourceURL=utils.js
'use strict';
//get first issue key from stringField
function getIssueKey(stringField) {
var regexp = /([A-Za-z][A-Za-z0-9_]{1,19}-\d+)/g;
var keys = [];
var result = regexp.exec(stringField);
while (result) {
keys.push(result[0]);
result = regexp.exec(stringField);
}
return keys.length > 0 ? keys[0] : null;
}
//get accepted transitions from issue
function getPossibleNextActions(workflowManager, issue) {
var status = issue.getStatus();
var workFlow = workflowManager.getWorkflow(issue);
var currentStep = workFlow.getLinkedStep(status);
return currentStep.getActions();
}
//find status id by actionName among possibleActionsList
function getStatusIdForActionName(actionName, possibleActionsList) {
for each(var actionDescriptor in possibleActionsList) {
if (actionDescriptor.getName() === actionName) {
return actionDescriptor.getId();
}
}
return null;
}
//find status id by actionName among possibleActionsList
function getStatusIdForActionNameIgnoreCase(actionName, possibleActionsList) {
for each (var actionDescriptor in possibleActionsList) {
if (actionDescriptor.getName().toLowerCase() === actionName.toLowerCase()) {
return actionDescriptor.getId();
}
}
return null;
}
//get component by component full name
function getComponent(componentName) {
var componentAccessor = getComponentAccessor();
var clazz = Java.type("java.lang.Class")
return componentAccessor.getOSGiComponentInstanceOfType(clazz.forName(componentName));
}
//get component accessor
function getComponentAccessor() {
return Java.type("com.atlassian.jira.component.ComponentAccessor");
}
//form error message
function formError(issue, i18nHelper, commandName, templateName) {
function getIssueState(issue, i18nHelper) {
return (issue.getStatusObject() == null)
? i18nHelper.getText("git.repository.smartcommits.transition.error.unknownstatus")
: s.getName();
};
var errorHandler = Java.type("com.atlassian.jira.plugins.dvcs.smartcommits.model.CommitHookHandlerError");
return errorHandler.fromSingleError(
commandName, issue.getKey(), i18nHelper.getText(templateName, issue.getKey(), getIssueState(issue))
);
}
// Returns a logger to write into the Jira logs
function getJiraLogger() {
return Java.type("org.apache.log4j.Logger").getLogger("com.bigbrassband.jira.git.services.scripting.ScriptService");
}