Skip to content

Instantly share code, notes, and snippets.

@Geczy
Last active August 10, 2020 18:42
Show Gist options
  • Save Geczy/4099fc408aceff08d3fe597085224e6f to your computer and use it in GitHub Desktop.
Save Geczy/4099fc408aceff08d3fe597085224e6f to your computer and use it in GitHub Desktop.
jira auto time logger
// timespent is EMPTY AND assignee = currentUser() AND resolution != Unresolved ORDER BY updated DESC
Number.prototype.pad = function (size) {
var s = String(this);
while (s.length < (size || 2)) {
s = "0" + s;
}
return s;
};
var monthNames = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
];
function openIssue() {
document
.querySelector(".issuerow.focused")
.querySelector(".issue-actions-trigger")
.click();
var waitForLogTimeButton = setInterval(() => {
var logButton = document.querySelector(
".ajs-layer.box-shadow.active a.aui-list-item-link.issueaction-log-work"
);
if (logButton) {
clearInterval(waitForLogTimeButton);
logPoints();
}
}, 100);
}
function logPoints() {
console.log("Activating dropdown toggle");
document
.querySelector(
".ajs-layer.box-shadow.active a.aui-list-item-link.issueaction-log-work"
)
.click();
console.log("Waiting for dropdown menu to open");
var waitForModalOpen = setInterval(() => {
var modal = document.querySelector("#log-work-time-logged");
if (modal) {
clearInterval(waitForModalOpen);
inTheModal();
}
}, 100);
}
function inTheModal() {
var pointInput = document.querySelector("#log-work-time-logged");
var dateInput = document.querySelector("#log-work-date-logged-date-picker");
var currIssue = document.querySelector(".issuerow.focused");
var time = currIssue.querySelector(".updated time").getAttribute("datetime");
var d = new Date(time);
var pasteTime = `${d.getDate().pad()}/${
monthNames[d.getMonth()]
}/${d.getFullYear().toString().substr(-2)}`;
var points = parseInt(
currIssue.querySelector(".customfield_10105").innerText,
10
);
if (isNaN(points)) {
points = 1;
}
points = points * 3;
pointInput.value = `${points}h`;
dateInput.value = `${pasteTime} 10:00 AM`;
var submitButton = document.querySelector("#log-work-submit");
if (submitButton) submitButton.click();
goNextIssue();
}
function goNextIssue() {
var waitForCloseModal = setInterval(() => {
var modal = document.querySelector("#log-work-time-logged");
if (!modal) {
clearInterval(waitForCloseModal);
var nextRow = document.querySelector(".issuerow.focused").nextSibling;
if (!nextRow) {
alert("No more issues found");
return;
}
nextRow.click();
openIssue();
}
}, 100);
}
openIssue();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment