/
priority.js
78 lines (68 loc) · 2.32 KB
/
priority.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
75
76
77
78
//# sourceURL=priority.js
'use strict';
// Classes passed as parameters by default
//
// The passed smart commit command
// command : com.atlassian.jira.plugins.dvcs.smartcommits.model.CommitCommands.CommitCommand
//
// The committer user
// user : com.atlassian.jira.user.ApplicationUser
//
// The issue specified in smart commit
// issue : com.atlassian.jira.issue.MutableIssue
//
// A command result to return execution errors
// commandResult : com.atlassian.jira.plugins.dvcs.smartcommits.model.CommandsResults.CommandResult
//
// The commit revision ID
// revision : java.lang.String
//
// The full commit message
// commitComment : java.lang.String
//
// The commit timestamp (unixtime format)
// commitTime : long
//
// An e-mail of the commit author
// authorEmail : java.lang.String
//
// An author name of the commit
// authorName : java.lang.String
function getComponent(componentName) {
var componentAccessor = Java.type("com.atlassian.jira.component.ComponentAccessor");
var clazz = Java.type("java.lang.Class")
return componentAccessor.getOSGiComponentInstanceOfType(clazz.forName(componentName));
}
function searchForPriority(prioName) {
var priorityManager = getComponent("com.atlassian.jira.config.PriorityManager");
for each (var prio in priorityManager.getPriorities()) {
if (prioName == prio.getName() || prioName == prio.getId()) {
return prio.getId();
}
}
return null;
}
var issueService = getComponent("com.atlassian.jira.bc.issue.IssueService");
var prioName = command.getArguments().get(0);
var prioId = searchForPriority(prioName);
if (prioId) {
// Create parameters for update
var issueInputParameters = issueService.newIssueInputParameters();
issueInputParameters.setPriorityId(prioId);
// Call validate
var validateResult = issueService.validateUpdate(user, issue.getId(), issueInputParameters);
// Check for error and call the operation
if (!validateResult.getErrorCollection().hasAnyErrors()) {
issueService.update(user, validateResult);
} else {
// Report errors if any
for each (var err in validateResult.getErrorCollection().getErrors()) {
commandResult.addError(err);
}
for each (var err in validateResult.getErrorCollection().getErrorMessages()) {
commandResult.addError(err);
}
}
} else {
commandResult.addError("Priority '" + prioName + "' not found");
}