-
Notifications
You must be signed in to change notification settings - Fork 30
/
gitlab-projects.el
143 lines (116 loc) · 5.09 KB
/
gitlab-projects.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
142
143
;;; gitlab-projects.el --- Projects API
;; Copyright (C) 2014, 2015, 2016 Nicolas Lamirault <[email protected]>
;; 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 2
;; of the License, 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 this program; if not, write to the Free Software
;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
;; 02110-1301, USA.
;;; Commentary:
;; See API doc :
;; https://github.com/gitlabhq/gitlabhq/blob/master/doc/api/projects.md
;;; Code:
(require 'dash)
(require 's)
(require 'gitlab-http)
(defun gitlab-list-projects (&optional page per-page)
"Get a list of projects accessible by the authenticated user.
PAGE: current page number
PER-PAGE: number of items on page max 100"
(let* ((params '()))
(when page
(add-to-list 'params (cons 'per_page (number-to-string per-page))))
(when per-page
(add-to-list 'params (cons 'page (number-to-string page))))
(perform-gitlab-request "GET"
"projects"
params
200)))
(defun gitlab-list-all-projects ()
"Get a list of all projects accessible by the authenticated user."
(interactive)
(let* ((page 1)
(per-page 100)
(projects)
(all-projects (gitlab-list-projects page per-page))
(all-projects-count (length all-projects)))
(while (>= all-projects-count (* page per-page))
(setq projects (gitlab-list-projects page per-page))
(setq all-projects (vconcat all-projects projects))
(setq all-projects-count (length all-projects))
(setq page (1+ page)))
all-projects))
(defun gitlab-list-owned-projects ()
"Get a list of projects which are owned by the authenticated user."
(perform-gitlab-request "GET" "projects" '((owned . "true")) 200))
(defun gitlab-get-project (project-id)
"Get a specific project, identified by PROJECT-ID."
(perform-gitlab-request "GET"
(format "projects/%s"
(url-hexify-string
(format "%s"project-id)))
nil
200))
(defun gitlab-search-projects (name)
"Search for projects by name which are accessible to the authenticated user.
NAME is a string contained in the project name."
(perform-gitlab-request "GET"
(s-concat "projects/search/" name)
nil
200))
(defun gitlab-list-project-members (project-id)
"Get a list of a project's team members.
PROJECT-ID is The ID or NAMESPACE/PROJECT_NAME of a project."
(perform-gitlab-request "GET"
(format "projects/%s/members"
(url-hexify-string
(format "%s" project-id)))
nil
200))
(defun gitlab-add-project (project-name)
"Add a specific project, identified by PROJECT-NAME."
(perform-gitlab-request "POST"
(format "projects/%s"
(url-hexify-string
(format "%s" project-name)))
nil
201))
(defun gitlab-list-project-events (project-id)
"Get the events for the specified project, identified by PROJECT-ID.
Sorted from newest to latest."
(perform-gitlab-request "GET"
(format "projects/%s/events"
(url-hexify-string
(format "%s" project-id)))
nil
200))
(defun gitlab-projects--get-issue-link (project-id issue-id)
"Create the URL to show a project's issue.
`PROJECT-ID' is the project ID
`ISSUE-ID' is the issue ID."
(-when-let (project (gitlab-get-project project-id))
(s-concat (gitlab--get-host)
"/"
(assoc-default 'path_with_namespace project)
"/issues/"
(number-to-string issue-id))))
(defun gitlab-list-project-labels (project-id)
"Get the labels for the project identified by PROJECT-ID."
(perform-gitlab-request "GET"
(format "projects/%s/labels"
(url-hexify-string
(format "%s" project-id)))
nil
200))
(defun gitlab-list-project-labels-names (project-id)
"Get a list of the labels' names."
(let ((labels (gitlab-list-project-labels project-id)))
(--map (assoc-default 'name it) labels)))
(provide 'gitlab-projects)
;;; gitlab-projects.el ends here