ScriptRunner
[Jobs] ์์ง์ ์ ๋ณด ๋๊ธฐํ ํ๋ก์ธ์ค
์ฌ๋ด API๋ฅผ ํ์ฉํด์, ์ง๋ผ ๊ณ์ ์ ์์ง์ ์ ๋ณด๋ฅผ ๋งตํํด์ฃผ๋ ๋ฐฐ์น๋ฅผ Groovy ๋ก ์์ฑ
Source Code
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.*;
import com.atlassian.jira.issue.customfields.*;
import com.atlassian.jira.user.UserPropertyManager;
import com.atlassian.jira.user.*;
import com.atlassian.jira.user.util.UserUtil;
import groovy.json.*;
import org.apache.http.client.methods.*;
import org.apache.http.entity.*;
import org.apache.http.impl.client.*;
def userPropertyManager = ComponentAccessor.userPropertyManager;
UserUtil userUtil = ComponentAccessor.getUserUtil();
def url = "https://xxxxx.com/api/service/findByEmail?email="
int qty = 0
int activeCount = 0;
int inactiveCount = 0;
int failCount = 0;
for(ApplicationUser u in userUtil.getUsers())
{
if(!u.isActive()) {
inactiveCount++;
continue;
}
else activeCount++;
//log.warn(u)
//log.warn(u.emailAddress)
if(u.emailAddress != null) {
def get = new HttpGet(url+u.emailAddress)
get.addHeader("host", "xxxxxxx.com")
get.addHeader("apikey", "xxxxxxxxxxxxxxxxxx")
get.addHeader("content-type", "application/json")
def client = HttpClientBuilder.create().build()
def response = client.execute(get)
if(response.getStatusLine().getStatusCode() == 200) {
def bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))
def jsonResponse = bufferedReader.getText()
def slurper = new JsonSlurper()
def resultMap = slurper.parseText(jsonResponse)
if(resultMap["recordset"] != null) {
try {
resultMap["recordset"]["teamName"] != null ? userPropertyManager.getPropertySet(u).setString('jira.meta.team', resultMap.recordset[0].teamName) : null;
resultMap["recordset"]["jobClassCode"] != null ? userPropertyManager.getPropertySet(u).setString('jira.meta.jobClassCode', resultMap.recordset[0].jobClassCode) : null;
}
catch(Exception e)
{
failCount++;
log.warn("error user:"+u)
log.error(e)
}
}
}
}
}
log.warn("active: "+activeCount + "\nfail: "+failCount + "\ninactive: "+inactiveCount);
Groovy
๋ณต์ฌ
[Behaviours] ํน์ ํ๋ ์ ํ ๊ฑธ๊ธฐ
์ฌ์ฉ์์ ํน์ฑ, ํ๋ก์ ํธ ๋ณ, ํ๋ ์กฐ๊ฑด์ ๋ง๊ฒ, ์ง๋ผ๋ด์์ ์์ ๋๋ ๋ณผ ์ ์๋๋ก ์ธ์ธํ ์กฐ์ ๊ฐ๋ฅ
ํน์ ์ฌ์ฉ์ ์ ์ธ
ํน์ ์ปจ๋์
์ ๋ง๊ฒ ์คํฌ๋ฆฝํธ ์คํ
[Workflows] ์ํฌํ๋ก์ฐ๋ฅผ ์ข ๋ ์์ธํ๊ฒ ์ปจํธ๋กค ๊ฐ๋ฅ
JSINCLUDER
Javascript ๋ฅผ ์ง๋ผ์ ํน์ ํ์ด์ง, ํ๋ก์ ํธ์ ์ฃผ์
ํด์ ์ฌ์ฉ ํ ์ ์์
์คํฌ๋ฆฝํธ ์ฃผ์
/*
Created by Phil 2020.07.06
WORKING VERSION
jsincluder issues in function footer column
*/
try {
let currentIdx = 0, ghxIssuesInEpicTableTRRows = 1, estimate = 0;
function timedevide(value) {
var week = 0;
var day = 0;
var hour = 0;
hour = parseFloat(value % 40); //์๊ฐ ๊ณ์ฐ
day = parseInt(hour / 8); //๋ ๊ณ์ฐ
week = parseInt((value - hour) / 40); // ์ฃผ ๊ณ์ฐ
if (9 < hour < 40) { // ์๊ฐ์ด 9~40์๊ฐ ์ฌ์ด์ผ ๊ฒฝ์ฐ ๊ณ์ฐ
hour = hour - (day * 8)
}
else if (8 <= hour <= 9) { // ์๊ฐ์ด 8~9 ์๊ฐ์ผ ๊ฒฝ์ฐ ๊ณ์ฐ
hour = hour - 8
}
return { // ๊ฒฐ๊ณผ๊ฐ ๋ฆฌํด
h: +hour.toFixed(4),
d: +day.toFixed(4),
w: +week.toFixed(4)
}
}
const loopForever = () => {
if (currentIdx < ghxIssuesInEpicTableTRRows) {
// console.log('currentIdx: '+currentIdx+' ghxIssuesInEpicTableTRRows: '+ghxIssuesInEpicTableTRRows);
setTimeout(loopForever, 500);
// console.log('loop');
} else {
// console.log('currentIdx: '+currentIdx+' ghxIssuesInEpicTableTRRows: '+ghxIssuesInEpicTableTRRows);
var actions2 = AJS.$('#ghx-issues-in-epic-table tbody');
AJS.$(actions2).before('<thead><tr class="issuerow"><th></th><th>Key</th><th>Summary</th><th></th><th>Status</th><th>Assignee</th><th>Due Date</th><th>Original<br/>Estimate</th><th></th></tr></thead>');
AJS.$(actions2).after('<tfoot><tr class="issuerow"><td></td><td></td><td></td><td></td><td>์ด๊ณต์</td><td>' + +(estimate / 160).toFixed(4) + '</td><td>Sum</td><td>' + timedevide(estimate).w + "Week " + timedevide(estimate).d + "Day " + timedevide(estimate).h + "Hour " + '</td><td></td></tr></tfoot>');
}
}
AJS.$(document).ready(function () {
try {
//Updated 2020.07.06 by Phil
let rows = AJS.$('#ghx-issues-in-epic-table tr');
ghxIssuesInEpicTableTRRows = rows.length;
// console.log("total row: "+ghxIssuesInEpicTableTRRows);
if (rows.length > 0) {
loopForever();
}
rows.each(function () {
// ์ฌ๊ธฐ์ ์์ผ๋ฉด getJson ๋ณด๋ค ๋จผ์ ์ฒ๋ฆฌ๋จ
// currentIdx = currentIdx + 1;
var row = this;
var value;
var issueKey = AJS.$(this).attr("data-issuekey");
if (issueKey) {
AJS.$.getJSON(AJS.contextPath() + '/rest/api/latest/issue/' + issueKey, function (data) {
value = 0;
if (data.fields.aggregatetimeoriginalestimate) {
value = data.fields.aggregatetimeoriginalestimate / 3600;
estimate = estimate + value;
}
else
{
value = 0;
}
var actions = AJS.$(row).find('td.issue_actions');
duedate = data.fields.duedate;
AJS.$(actions).before('<td class="nav">' + duedate + '</td>');
AJS.$(actions).before('<td class="nav">' + timedevide(value).w + "Week " + timedevide(value).d + "Day " + timedevide(value).h + "Hour " + '</td>');
// console.log("index: "+currentIdx + " value:" +value);
currentIdx = currentIdx + 1;
});
}
else
{
// console.log(AJS.$(this));
currentIdx = currentIdx + 1;
}
// console.log('estimate: '+estimate);
});
} catch (error1) {
alert(`๋ค์๊ณผ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค: ${error1.name}: ${error1.message}`);
// console.log(error1);
}
});
} catch (error) {
alert(`๋ค์๊ณผ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค: ${error.name}: ${error.message}`);
// console.log(error);
}
JavaScript
๋ณต์ฌ