blob: fa35b351d2f17e0a3aea3c959c5547805dc27574 (
plain) (
blame)
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
144
145
146
147
148
149
150
151
152
153
|
;;; glab.el --- minuscule client library for the Gitlab API -*- lexical-binding: t -*-
;; Copyright (C) 2016-2018 Jonas Bernoulli
;; Author: Jonas Bernoulli <jonas@bernoul.li>
;; Homepage: https://github.com/magit/ghub
;; Keywords: tools
;; This file is not part of GNU Emacs.
;; This file 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 file 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.
;; For a copy of the GPL see https://www.gnu.org/licenses/gpl.txt.
;;; Commentary:
;; Glab is a library that provides basic support for using the Gitlab API
;; from Emacs packages. It abstracts access to API resources using only
;; a handful of functions that are not resource-specific.
;; This library is implemented on top of Ghub. Unlike Ghub, Glab does
;; not support the guided creation of tokens because Gitlab lacks the
;; features that would be necessary to implement that. Users have to
;; create tokens through the web interface.
;;; Code:
(require 'ghub)
(defconst glab-default-host "gitlab.com/api/v4"
"The default host that is used if `glab.host' is not set.")
(cl-defun glab-head (resource &optional params
&key query payload headers
silent unpaginate noerror reader
username auth host
callback errorback extra)
"Make a `HEAD' request for RESOURCE, with optional query PARAMS.
Like calling `ghub-request' (which see) with \"HEAD\" as METHOD
and `gitlab' as FORGE."
(ghub-request "HEAD" resource params :forge 'gitlab
:query query :payload payload :headers headers
:silent silent :unpaginate unpaginate
:noerror noerror :reader reader
:username username :auth auth :host host
:callback callback :errorback errorback :extra extra))
(cl-defun glab-get (resource &optional params
&key query payload headers
silent unpaginate noerror reader
username auth host
callback errorback extra)
"Make a `GET' request for RESOURCE, with optional query PARAMS.
Like calling `ghub-request' (which see) with \"GET\" as METHOD
and `gitlab' as FORGE."
(ghub-request "GET" resource params :forge 'gitlab
:query query :payload payload :headers headers
:silent silent :unpaginate unpaginate
:noerror noerror :reader reader
:username username :auth auth :host host
:callback callback :errorback errorback :extra extra))
(cl-defun glab-put (resource &optional params
&key query payload headers
silent unpaginate noerror reader
username auth host
callback errorback extra)
"Make a `PUT' request for RESOURCE, with optional payload PARAMS.
Like calling `ghub-request' (which see) with \"PUT\" as METHOD
and `gitlab' as FORGE."
(ghub-request "PUT" resource params :forge 'gitlab
:query query :payload payload :headers headers
:silent silent :unpaginate unpaginate
:noerror noerror :reader reader
:username username :auth auth :host host
:callback callback :errorback errorback :extra extra))
(cl-defun glab-post (resource &optional params
&key query payload headers
silent unpaginate noerror reader
username auth host
callback errorback extra)
"Make a `POST' request for RESOURCE, with optional payload PARAMS.
Like calling `ghub-request' (which see) with \"POST\" as METHOD
and `gitlab' as FORGE."
(ghub-request "POST" resource params :forge 'gitlab
:query query :payload payload :headers headers
:silent silent :unpaginate unpaginate
:noerror noerror :reader reader
:username username :auth auth :host host
:callback callback :errorback errorback :extra extra))
(cl-defun glab-patch (resource &optional params
&key query payload headers
silent unpaginate noerror reader
username auth host
callback errorback extra)
"Make a `PATCH' request for RESOURCE, with optional payload PARAMS.
Like calling `ghub-request' (which see) with \"PATCH\" as METHOD
and `gitlab' as FORGE."
(ghub-request "PATCH" resource params :forge 'gitlab
:query query :payload payload :headers headers
:silent silent :unpaginate unpaginate
:noerror noerror :reader reader
:username username :auth auth :host host
:callback callback :errorback errorback :extra extra))
(cl-defun glab-delete (resource &optional params
&key query payload headers
silent unpaginate noerror reader
username auth host
callback errorback extra)
"Make a `DELETE' request for RESOURCE, with optional payload PARAMS.
Like calling `ghub-request' (which see) with \"DELETE\" as METHOD
and `gitlab' as FORGE."
(ghub-request "DELETE" resource params :forge 'gitlab
:query query :payload payload :headers headers
:silent silent :unpaginate unpaginate
:noerror noerror :reader reader
:username username :auth auth :host host
:callback callback :errorback errorback :extra extra))
(cl-defun glab-request (method resource &optional params
&key query payload headers
silent unpaginate noerror reader
username auth host
callback errorback extra)
"Make a request for RESOURCE and return the response body.
Like calling `ghub-request' (which see) with `gitlab' as FORGE."
(ghub-request method resource params :forge 'gitlab
:query query :payload payload :headers headers
:silent silent :unpaginate unpaginate
:noerror noerror :reader reader
:username username :auth auth :host host
:callback callback :errorback errorback :extra extra))
(cl-defun glab-repository-id (owner name &key username auth host)
"Return the id of the repository specified by OWNER, NAME and HOST."
(number-to-string
(cdr (assq 'id (glab-get (format "/projects/%s%%2F%s" owner name)
nil :username username :auth auth :host host)))))
;;; _
(provide 'glab)
;;; glab.el ends here
|