-
Notifications
You must be signed in to change notification settings - Fork 1
/
redorg.el
73 lines (62 loc) · 2.41 KB
/
redorg.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
(require 'csv)
(setq redorg-redmine-url "http://10.65.10.4:3000/")
(setq redorg-query-id "6")
(setq redorg-project-names '("spine" "mediation-miaso"))
(setq redorg-autologin-cookie "LC0K44Lbq4O70bMu5eG8QJHccc0fCN7bp27rgjei")
(setq redorg-buffer-name "regorg.org")
;; relies on following variables
;; redorg-redmine-url - base url of redmine
;; redorg-query-id - id of the query
;; redorg-project-names - list of project names to import tasks from
;; redorg-autologin-cookie - cookie to login into redmine
;; redorg-buffer-name - name of buffer to insert tasks
(defun import-redmine-tasks ()
"imports tasks from redmine"
(interactive)
(mapc 'process-project redorg-project-names))
(defun process-project (prj-name)
"queries csv data on project PRJ-NAME from redmine"
()
(with-temp-buffer
(append-to-buffer redorg-buffer-name (list "\n" "** " prj-name "\n"))
(call-process "curl"
nil
t
nil
"-s"
"--cookie" (concat "autologin=" redorg-autologin-cookie)
(concat redorg-redmine-url "projects/" prj-name "/issues?query_id=" redorg-query-id "&format=csv"))
(mapc 'process-one-task (csv-parse-buffer t))
(append-to-buffer redorg-buffer-name (list "\n\n"))))
(defun process-export-file (file-name)
"processes csv file name FILE_NAME"
()
(with-temp-buffer
(append-to-buffer redorg-buffer-name (list "** " file-name "\n"))
(insert-file-contents file-name)
(mapc 'process-one-task (csv-parse-buffer t))
(append-to-buffer redorg-buffer-name (list "\n\n"))))
;; uses current buffer ???
(defun process-one-task (task)
"processes one task in csv form. TASK is a list of alists"
()
(append-to-buffer redorg-buffer-name (list "*** TODO " (my-assoc "Subject" task) " (" (my-assoc "#" task) ") \n" )))
(defun my-assoc (key where)
"returns cdr from (assoc KEY WHERE)"
() (cdr (assoc key where)))
(defun append-to-buffer (buffer texts)
"appends each element from TEXTS to BUFFER"
()
(let ((orig-buffer (current-buffer)))
(save-excursion
(let ((buff (get-buffer-create buffer)))
(set-buffer buff)
(mapc 'insert texts)))))
(defun append-to-buffer (buffer texts)
()
(let ((old-buf (current-buffer)))
(save-excursion
(let ((new-buf (get-buffer-create buffer)))
(set-buffer new-buf)
(dolist (text texts)
(insert-string text))))))