-
Notifications
You must be signed in to change notification settings - Fork 10
/
task.clj
104 lines (84 loc) · 3.83 KB
/
task.clj
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
(ns flower.tracker.jira.task
(:require [clojure.data :as data]
[clojure.set :as set]
[flower.common :as common]
[flower.macros :as macros]
[flower.tracker.proto :as proto]
[flower.tracker.jira.common :as jira.common]))
;;
;; Private declarations
;;
(declare private-get-jira-workitem-comments)
(declare private-set-jira-workitem!)
(declare private-get-jira-workitem-url)
;;
;; Public definitions
;;
(defrecord JiraTrackerTaskComment [comment-author
comment-text]
proto/TrackerTaskCommentProto
(get-author [tracker-task-comment] comment-author)
(get-text [tracker-task-comment] comment-text))
(defrecord JiraTrackerTask [tracker task-id task-title task-type task-state task-tags task-description task-comments-future]
proto/TrackerTaskProto
(get-tracker [tracker-task] tracker)
(get-task-id [tracker-task] task-id)
(get-task-url [tracker-task] (private-get-jira-workitem-url tracker-task))
(get-state [tracker-task] task-state)
(get-type [tracker-task] task-type)
(get-comments [tracker-task] @task-comments-future)
(upsert! [tracker-task] (private-set-jira-workitem! tracker-task)))
(macros/public-definition get-jira-workitems cached)
;;
;; Private definitions
;;
(defn- private-get-jira-workitems-before-map [tracker query]
(map #(map->JiraTrackerTask
{:tracker tracker
:task-id (.getKey %)
:task-title (.getSummary %)
:task-type (.getName (.getIssueType %))
:task-assignee (some-> %
.getAssignee
.getName)
:task-state (.getName (.getStatus %))
:task-tags (.getLabels %)
:task-description (.getDescription %)
:task-comments-future (macros/future-or-delay (private-get-jira-workitem-comments tracker %))})
(if (string? query)
(jira.common/get-jira-query-inner tracker query)
(if (empty? query)
(jira.common/get-jira-query-inner tracker (str "project=\"" (proto/get-project-name tracker) "\""))
(jira.common/get-jira-workitems-inner tracker query)))))
(defn- private-get-jira-workitem-comments [tracker workitem-inner]
(let [notes (try (jira.common/get-jira-workitem-comments-inner tracker workitem-inner)
(catch java.io.IOException e nil))]
(map #(map->JiraTrackerTaskComment {:comment-author (some-> %
.getAuthor
.getName)
:comment-text (.getBody %)})
notes)))
(defn- private-get-jira-workitems [tracker query]
(map (get-in (proto/get-tracker-component tracker)
[:context :tasks-map-function]
(fn [task] task))
(private-get-jira-workitems-before-map tracker query)))
(defn- private-set-jira-workitem! [tracker-task]
(let [tracker (proto/get-tracker tracker-task)
task-id (proto/get-task-id tracker-task)
old-workitem (first (proto/get-tasks tracker [task-id]))
fields (second (data/diff old-workitem tracker-task))
task-inner (jira.common/set-jira-workitem-inner! tracker task-id fields)
new-task-id (if task-inner
(.getKey task-inner)
task-id)]
(when common/*behavior-implicit-cache-cleaning*
(jira.common/get-jira-workitems-inner-clear-cache!)
(jira.common/get-jira-query-inner-clear-cache!)
(get-jira-workitems-clear-cache!))
(first (proto/get-tasks tracker [new-task-id]))))
(defn- private-get-jira-workitem-url [tracker-task]
(let [tracker (proto/get-tracker tracker-task)
project-url (proto/get-project-url tracker)
task-id (proto/get-task-id tracker-task)]
(str project-url "/issues/" task-id)))