-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjira-actions.el
141 lines (122 loc) · 5.41 KB
/
jira-actions.el
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
;;; jira-issues.el --- Actions on items -*- lexical-binding: t -*-
;; Copyright (C) 2025 Pablo González Carrizo
;; Created: 2025-02-16
;; Author: Pablo González Carrizo <unmonoqueteclea@gmail.com>
;; This file is NOT part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; Manage actions on Jira objects
;;; Code:
(require 'transient)
(require 'tablist)
(require 'jira-api)
(require 'jira-utils)
(defun jira-actions--marked-issue-description ()
"TODO: This will change if the list of issues fields is changed."
(let ((vector (cdr (car (tablist-get-marked-items)))))
(aref vector (1- (length vector)))))
(defun jira-actions--add-worklog ()
"Add a worklog to marked issue."
(let* ((args (transient-args 'jira-actions-add-worklog-menu))
(notify (transient-arg-value "--notify-users" args))
(comment (transient-arg-value "--comment=" args))
(estimate (transient-arg-value "--new-estimate=" args))
(date (transient-arg-value "--date=" args))
(time (transient-arg-value "--time=" args))
(adjust-estimate
(if (and estimate (not (string-empty-p estimate))) "new" "auto")))
(jira-api-call
"POST" (concat "issue/"(jira-utils-marked-item) "/worklog")
:params `(("notifyUsers" . ,(if notify "true" "false"))
("adjustEstimate" . ,adjust-estimate)
,@(when (string= adjust-estimate "new")
`(("newEstimate" . ,estimate))))
:data `(("started" . ,date)
("comment" . (("type" . "doc")
("version" . 1)
("content" . ((("type" . "paragraph")
("content" . ((("type" . "text")
("text" . ,comment)))))))))
("timeSpent" . ,time))
:callback (lambda (_data _response) (jira-tempo)))))
(transient-define-prefix jira-actions-add-worklog-menu ()
"Show menu for adding a Worklog to a Jira Issue."
:value (lambda () `
(,(concat "--comment=" (jira-utils-marked-item)
": " (jira-actions--marked-issue-description))
,(concat "--date="
(format-time-string "%FT%T.%3N%z" (current-time)))
"--time=1h"))
["Arguments"
("n" "Notify users" "--notify-users")
("e" "New estimate" "--new-estimate=")
("c" "Comment" "--comment=")
("d" "Date" "--date=")
("t" "Time Spent" "--time=")]
["Actions"
("a" "Add worklog"
(lambda () (interactive) (jira-actions--add-worklog)))]
(interactive)
(if (jira-utils-marked-item)
(transient-setup 'jira-actions-add-worklog-menu)
(message "Run jira-issues first")))
(defun jira-actions--change-issue ()
"Apply user-selected options to marked issue."
(let* ((args (transient-args 'jira-actions-change-issue-menu))
(status (transient-arg-value "--status=" args))
(resolution (transient-arg-value "--resolution=" args))
(status-id (cdr (assoc status jira-active-issue-transitions)))
(time-estimate (transient-arg-value "--time-estimate=" args))
(hook (lambda (_data _response) (run-hooks 'jira-issues-changed-hook))))
(when status-id
(jira-api-call
"POST" (concat "issue/" (jira-utils-marked-item) "/transitions")
:data `(("transition" . (("id" . ,status-id))))
:callback hook))
(when (or resolution time-estimate)
(jira-api-call
"PUT" (concat "issue/" (jira-utils-marked-item))
:data `(("fields" .
,(let (fields)
(when resolution
(push `( "resolution" . (("name" . ,resolution))) fields))
(when time-estimate
(push `( "timetracking" . (("originalEstimate" . ,time-estimate))) fields))
fields)))
:callback hook))))
(transient-define-prefix jira-actions-change-issue-menu ()
"Show menu for updating a Jira Issue."
["Arguments"
("s" "Status" "--status="
:choices
(lambda () (mapcar (lambda (tr) (car tr)) jira-active-issue-transitions)))
("r" "Resolution" "--resolution="
:choices
(lambda () (mapcar (lambda (res) (car res)) jira-resolutions)))
("e" "Time Estimate" "--time-estimate=")]
["Actions"
("c" "Change" (lambda () (interactive) (jira-actions--change-issue)))]
(interactive)
(if (jira-utils-marked-item)
(progn ;; retrieve possible statuses transtions
(jira-api-get-transitions (jira-utils-marked-item))
(transient-setup 'jira-actions-change-issue-menu))
(message "Run jira-issues first")))
(defun jira-actions-open-issue (issue-key)
"Open ISSUE-KEY in browser."
(browse-url (format "%s/browse/%s" jira-base-url issue-key)))
(provide 'jira-actions)
;;; jira-actions.el ends here