Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Gitea, Gogs and Bitbucket #67

Merged
merged 10 commits into from Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Expand Up @@ -5,6 +5,9 @@ PKG = ghub
ELS = $(PKG).el
ELS += $(PKG)-graphql.el
ELS += glab.el
ELS += gtea.el
ELS += gogs.el
ELS += buck.el
ELCS = $(ELS:.el=.elc)

DEPS =
Expand Down
47 changes: 18 additions & 29 deletions README.md
@@ -1,38 +1,27 @@
Ghub.el — Minuscule client library for the Github API
=====================================================
Ghub — Minuscule client libraries for the APIs of various Git forges
====================================================================

Ghub is a library that provides basic support for using the Github
REST (v3) and GraphQL (v4) APIs from Emacs packages. It abstracts
access to API resources using only a handful of functions that are
not resource-specific.
Ghub provides basic support for using the APIs of various Git forges
from Emacs packages. Originally it only supported the Github REST
API, but now it also supports the Github GraphQL API as well as the
REST APIs of Gitlab, Gitea, Gogs and Bitbucket.

Ghub handles the creation, storage and use of access tokens using a
setup wizard to make it easier for users to get started and to reduce
the support burden imposed on package maintainers. It also comes with
a comprehensive manual to address the cases when things don't just
work as expected or in case you don't want to use the wizard.
Ghub abstracts access to API resources using only a handful of basic
functions such as `ghub-get`. These are convenience wrappers around
`ghub-request`. Additional forge-specific wrappers like `glab-put`,
`gtea-put`, `gogs-post` and `buck-delete` are also available. Ghub
does not provide any resource-specific functions, with the exception
of `FORGE-repository-id`.

When accessing Github, then Ghub handles the creation and storage of
access tokens using a setup wizard to make it easier for users to get
started. The tokens for other forges have to be created manually.

Ghub is intentionally limited to only provide these two essential
features — basic request functions and guided setup — to avoid being
too opinionated, which would hinder wide adoption. It is assumed that
wide adoption would make life easier for users and maintainers alike,
because then all packages that talk to the Github API could be
configured the same way.
because then all packages that talk to forge APIs could be configured
the same way.

Please consult the [manual][manual-ghub] for more information.

Glab.el — Minuscule client library for the Gitlab API
=====================================================

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. Instructions can be found
[here][manual-glab].

[manual-ghub]: https://magit.vc/manual/ghub
[manual-glab]: https://magit.vc/manual/ghub/Gitlab-Support.html
128 changes: 128 additions & 0 deletions buck.el
@@ -0,0 +1,128 @@
;;; buck.el --- minuscule client library for the Bitbucket 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:

;; Buck is a library that provides basic support for using the Bitbucket 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, Buck does
;; not support the guided creation of tokens because Bitbucket lacks the
;; features that would be necessary to implement that. Users have to
;; create tokens through the web interface.

;;; Code:

(require 'ghub)

(defconst buck-default-host "api.bitbucket.org/2.0"
"The default host that is used if `buck.host' is not set.")

;; HEAD and PATCH are not supported according to
;; https://developer.atlassian.com/bitbucket/api/2/reference/meta/uri-uuid

(cl-defun buck-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 `bitbucket' as FORGE."
(ghub-request "GET" resource params :forge 'bitbucket
: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 buck-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 `bitbucket' as FORGE."
(ghub-request "PUT" resource params :forge 'bitbucket
: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 buck-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 `bitbucket' as FORGE."
(ghub-request "POST" resource params :forge 'bitbucket
: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 buck-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 `bitbucket' as FORGE."
(ghub-request "DELETE" resource params :forge 'bitbucket
: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 buck-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 `bitbucket' as FORGE."
(ghub-request method resource params :forge 'bitbucket
: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 buck-repository-id (owner name &key username auth host)
"Return the id of the repository specified by OWNER, NAME and HOST."
(substring (cdr (assq 'uuid
(buck-get (format "/repositories/%s/%s" owner name)
nil
:username username :auth auth :host host)))
1 -1))

;;; _
(provide 'buck)
;;; buck.el ends here