Skip to content

Commit 9401c9b

Browse files
committed
Merge branch 'develop'
Signed-off-by: Nicolas Lamirault <[email protected]>
2 parents f28c8d8 + 463fe06 commit 9401c9b

File tree

10 files changed

+262
-62
lines changed

10 files changed

+262
-62
lines changed

ChangeLog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# emacs-gitlab ChangeLog
22

3+
## Version 0.5 (06/04/2015)
4+
5+
- ``FIX`` Unit tests on issues API
6+
- ``FIX`` List projects without page parameters
7+
- ``#20``: List all issues and projects (pagination refactoring) (Thanks [marcinant][])
8+
- ``#19``: Feature/extend gitlab mode (Thanks [marcinant][])
9+
310
## Version 0.4 (05/29/2015)
411

512
- Initial support for Users API (Thanks [marcinant][])

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,20 @@ management. Install it and retrieve dependencies :
6969

7070
* Setup your Gitlab informations :
7171

72-
$ export GITLAB_HOST="http://gitlab.foo.com"
73-
$ export GITLAB_USERNAME="foo"
74-
$ export GITLAB_PASSWORD="bar"
75-
$ export GITLAB_TOKEN_ID="xxxxxxxxxxxxxx"
76-
$ export GITLAB_PROJECT_ID=111222
77-
$ export GITLAB_PROJECT_NAME="myproject"
78-
$ export GITLAB_PROJECT_DESCRIPTION="a project description"
79-
$ export GITLAB_ISSUE_ID=145645
80-
$ export GITLAB_ISSUE_TITLE="the issue title"
72+
$ cat $HOME/.emacs-gitlab.rc
73+
#!/bin/bash
74+
export GITLAB_HOST="https://gitlab.com"
75+
export GITLAB_USERNAME="yourusername"
76+
export GITLAB_PASSWORD="yourpassword"
77+
export GITLAB_PROJECT_ID=111222
78+
export GITLAB_PROJECT_NAME="myproject"
79+
export GITLAB_PROJECT_DESCRIPTION="a project description"
80+
export GITLAB_ISSUE_ID=145645
81+
export GITLAB_ISSUE_TITLE="the issue title"
8182

8283
* Launch unit tests :
8384

85+
$ . $HOME/.emacs-gitlab.rc
8486
$ make clean test
8587

8688

@@ -104,6 +106,8 @@ See [LICENSE](LICENSE).
104106

105107
Nicolas Lamirault <[email protected]>
106108

109+
110+
107111
[emacs-gitlab]: https://github.com/nlamirault/emacs-gitlab
108112
[badge-license]: https://img.shields.io/badge/license-GPL_2-green.svg?style=flat
109113
[LICENSE]: https://github.com/nlamirault/emacs-gitlab/blob/master/LICENSE

gitlab-issues.el

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,32 @@
3030
(require 'gitlab-utils)
3131

3232

33-
(defun gitlab-list-issues ()
33+
(defun gitlab-list-issues (page per-page)
3434
"Get all issues created by authenticated user.
35-
STATE Return all issues or just those that are opened or closed
36-
LABELS - Comma-separated list of label names"
35+
PAGE: current page number
36+
PER-PAGE: number of items on page max 100"
3737
(let ((params '()))
38-
;; (when state
39-
;; (add-to-list params (cons "state" state)))
40-
;; (when labels
41-
;; (add-to-list params (cons "labels" labels)))
42-
(perform-gitlab-request "GET" "issues" params 200)))
43-
38+
(add-to-list 'params (cons 'per_page (number-to-string per-page)))
39+
(add-to-list 'params (cons 'page (number-to-string page)))
40+
(perform-gitlab-request "GET"
41+
"issues"
42+
params
43+
200)))
44+
45+
(defun gitlab-list-all-issues ()
46+
"Get a list of all issues."
47+
(interactive)
48+
(let* ((page 1)
49+
(per-page 100)
50+
(issues)
51+
(all-issues (gitlab-list-issues page per-page))
52+
(all-issues-count (length all-issues)))
53+
(while (>= all-issues-count (* page per-page))
54+
(setq issues (gitlab-list-issues page per-page))
55+
(setq all-issues (vconcat all-issues issues))
56+
(setq all-issues-count (length all-issues))
57+
(setq page (1+ page)))
58+
all-issues))
4459

4560
(defun gitlab--get-issue-uri (project-id issue-id)
4661
"Retrieve URI to retrieve an issue.
@@ -52,17 +67,42 @@ ISSUE-ID : The ID of a project issue"
5267
"/issues/"
5368
issue-id))
5469

55-
(defun gitlab-list-project-issues (project-id)
70+
(defun gitlab-list-project-issues (project-id &optional page per-page)
5671
"Get a list of project issues.
72+
PROJECT-ID : The ID of a project
73+
PAGE: current page number
74+
PER-PAGE: number of items on page max 100"
75+
(let ((params '()))
76+
(when page
77+
(add-to-list 'params (cons 'per_page (number-to-string per-page))))
78+
(when per-page
79+
(add-to-list 'params (cons 'page (number-to-string page))))
80+
(perform-gitlab-request "GET"
81+
(s-concat "projects/"
82+
(url-hexify-string
83+
(format "%s" project-id))
84+
"/issues")
85+
params
86+
200)))
87+
88+
(defun gitlab-list-all-project-issues (project-id &optional page per-page)
89+
"Get a list of all PROJECT-ID issues.
90+
PROJECT-ID : The ID of a project
91+
PAGE: current page number
92+
PER-PAGE: number of items on page max 100"
93+
(interactive)
94+
(let* ((page 1)
95+
(per-page 100)
96+
(issues)
97+
(all-issues (gitlab-list-project-issues project-id page per-page))
98+
(all-issues-count (length all-issues)))
99+
(while (>= all-issues-count (* page per-page))
100+
(setq issues (gitlab-list-project-issues project-id page per-page))
101+
(setq all-issues (vconcat all-issues issues))
102+
(setq all-issues-count (length all-issues))
103+
(setq page (1+ page)))
104+
all-issues))
57105

58-
PROJECT-ID : The ID of a project"
59-
(perform-gitlab-request "GET"
60-
(s-concat "projects/"
61-
(url-hexify-string
62-
(format "%s" project-id))
63-
"/issues")
64-
nil
65-
200))
66106

67107
(defun gitlab-get-issue (project-id issue-id)
68108
"Gets a single project issue.
@@ -109,10 +149,11 @@ LABELS comma-separated list label names"
109149
"Create a project issue.
110150
111151
PROJECT-ID the ID or NAMESPACE%2FPROJECT_NAME of a project
152+
ISSUE-ID : The ID of a project issue
112153
TITLE issue title
113154
DESCRIPTION issue description
114-
ASSIGNEE assignee ID
115-
MILESTONE milestone ID
155+
ASSIGNEE-ID assignee ID
156+
MILESTONE-ID milestone ID
116157
LABELS comma-separated list label names"
117158
(lwarn '(gitlab) :debug "UPDATE ISSUE in project: %s\n" project-id)
118159
(perform-gitlab-request "PUT"

gitlab-mode.el

Lines changed: 106 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
(require 'browse-url)
2929
(require 'tabulated-list)
30+
(require 'vc-git)
3031

3132
;; Gitlab library
3233

@@ -41,30 +42,124 @@
4142
(interactive)
4243
(message (concat "Current ID is: " (tabulated-list-get-id))))
4344

44-
45+
(defun project-make-button (text &rest props)
46+
"Make button with TEXT propertized with PROPS."
47+
(let ((button-text (if (display-graphic-p)
48+
text
49+
(concat "[" text "]")))
50+
(button-face (if (display-graphic-p)
51+
'(:box (:line-width 2 :color "dark grey")
52+
:background "light grey"
53+
:foreground "black")
54+
'link)))
55+
(apply 'insert-text-button button-text
56+
'face button-face
57+
'follow-link t
58+
props)))
4559

4660
;; Projects
61+
(defun gitlab-project-clone-button-action (button)
62+
"Action for BUTTON."
63+
(interactive)
64+
65+
(let* ((project (gitlab-get-project (button-get button 'project-id)))
66+
(name (assoc-default 'path project))
67+
(repo (assoc-default 'ssh_url_to_repo project))
68+
(target-dir (read-directory-name "Clone to directory:" (first query-replace-defaults))))
69+
70+
(if (file-directory-p (expand-file-name name target-dir))
71+
(progn
72+
(message "Target directory exists and is not empty. Trying to pull.")
73+
(let ((default-directory (file-name-as-directory (expand-file-name name target-dir))))
74+
(vc-git-command nil 0 nil "pull" repo)))
75+
(progn
76+
(make-directory name target-dir)
77+
(vc-git-command nil 0 nil "clone" repo (file-name-as-directory (expand-file-name name target-dir)))))
78+
(revert-buffer nil t)
79+
(goto-char (point-min))))
80+
4781

4882
(defun gitlab-goto-project ()
4983
"Got to web page of the project."
50-
(let ((project (tabulated-list-get-entry)))
84+
(interactive)
85+
(let* ((project (gitlab-get-project (tabulated-list-get-id))))
5186
(browse-url (assoc-default 'web_url project))))
5287

5388
;;;###autoload
89+
(defun gitlab-show-project-description (project)
90+
"Doc string PROJECT."
91+
(interactive)
92+
(with-help-window (help-buffer)
93+
(with-current-buffer standard-output
94+
(let ((desc (assoc-default 'description project))
95+
(homepage (assoc-default 'web_url project))
96+
(id (assoc-default 'id project))
97+
(status (number-to-string (assoc-default 'visibility_level project))))
98+
99+
(insert " Name: ")
100+
(princ (assoc-default 'name project))
101+
(princ "\n")
102+
(insert " Path: ")
103+
(princ (assoc-default 'path_with_namespace project))
104+
(princ "\n\n")
105+
106+
(insert " Repository: ")
107+
(princ (assoc-default 'ssh_url_to_repo project))
108+
(insert "\n\n")
109+
110+
(insert " " (propertize "Status" 'font-lock-face 'bold) ": ")
111+
(cond ((string= status "0")
112+
(insert (propertize (capitalize "Private") 'font-lock-faces 'font-lock-builtin-face)))
113+
((string= status "10")
114+
(insert (propertize (capitalize "Internal") 'font-lock-faces 'font-lock-builtin-face)))
115+
((string= status "20")
116+
(insert (propertize (capitalize "Public") 'font-lock-faces 'font-lock-builtin-face))))
117+
(insert " -- ")
118+
(project-make-button
119+
"Clone to / Pull"
120+
'action 'gitlab-project-clone-button-action
121+
'project-id id)
122+
123+
(insert "\n\n")
124+
125+
126+
(insert " " (propertize "Summary" 'font-lock-face 'bold)
127+
": " (if desc desc) "\n")
128+
129+
(when homepage
130+
(insert " " (propertize "Homepage" 'font-lock-face 'bold) ": ")
131+
(help-insert-xref-button homepage 'help-url homepage)
132+
(insert "\n"))))))
133+
134+
135+
(defun gitlab-describe-project (&optional button)
136+
"Describe the current pproject.
137+
If optional arg BUTTON is non-nil, describe its associated project."
138+
(interactive)
139+
(let ((project (gitlab-get-project (tabulated-list-get-id))))
140+
(if project
141+
(gitlab-show-project-description project)
142+
(user-error "No project here"))))
143+
144+
145+
>>>>>>> develop
54146
(defun gitlab-show-projects ()
55147
"Show Gitlab projects."
56148
(interactive)
57149
(pop-to-buffer "*Gitlab projects*" nil)
58150
(gitlab-projects-mode)
59151
(setq tabulated-list-entries
60-
(create-projects-entries (gitlab-list-projects)))
152+
(create-projects-entries (gitlab-list-all-projects)))
61153
(tabulated-list-print t))
62154

63155
(defun create-projects-entries (projects)
64156
"Create entries for 'tabulated-list-entries from PROJECTS."
65157
(mapcar (lambda (p)
158+
66159
(let ((id (number-to-string (assoc-default 'id p)))
67-
(owner (assoc-default 'owner p))
160+
(owner (if (assoc-default 'owner p)
161+
(assoc-default 'owner p)
162+
(assoc-default 'namespace p)))
68163
(namespace (assoc-default 'namespace p)))
69164
(list id
70165
(vector ;id
@@ -78,7 +173,9 @@
78173

79174
(defun gitlab-goto-issue ()
80175
"Got to web page of the issue."
81-
)
176+
(interactive)
177+
(let ((project (gitlab-get-project (elt (tabulated-list-get-entry) 1))))
178+
(browse-url (concat (assoc-default 'web_url project) "/issues/" (tabulated-list-get-id)))))
82179

83180
(defun create-issues-entries (issues)
84181
"Create entries for 'tabulated-list-entries from ISSUES."
@@ -88,6 +185,7 @@
88185
(list id
89186
(vector ;id
90187
(assoc-default 'state i)
188+
(format "%s" (assoc-default 'project_id i))
91189
(assoc-default 'name author)
92190
(assoc-default 'title i)))))
93191
issues))
@@ -99,7 +197,7 @@
99197
(pop-to-buffer "*Gitlab issues*" nil)
100198
(gitlab-issues-mode)
101199
(setq tabulated-list-entries
102-
(create-issues-entries (gitlab-list-issues)))
200+
(create-issues-entries (gitlab-list-all-issues)))
103201
(tabulated-list-print t))
104202

105203

@@ -111,6 +209,7 @@
111209
(let ((map (make-keymap)))
112210
(define-key map (kbd "v") 'print-current-line-id)
113211
(define-key map (kbd "w") 'gitlab-goto-project)
212+
(define-key map (kbd "d") 'gitlab-describe-project)
114213
map)
115214
"Keymap for `gitlab-projects-mode' major mode.")
116215

@@ -142,16 +241,12 @@
142241
:group 'gitlab
143242
(setq tabulated-list-format [;("ID" 5 t)
144243
("State" 10 t)
244+
("Project" 8 t)
145245
("Author" 20 t)
146246
("Title" 0 t)])
147247
(setq tabulated-list-padding 2)
148248
(setq tabulated-list-sort-key (cons "Title" nil))
149249
(tabulated-list-init-header))
150250

151-
152-
153-
154-
155-
156251
(provide 'gitlab-mode)
157252
;;; gitlab-mode.el ends here

0 commit comments

Comments
 (0)