dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

buck.el (5951B)


      1 ;;; buck.el --- minuscule client library for the Bitbucket API  -*- lexical-binding: t -*-
      2 
      3 ;; Copyright (C) 2016-2022  Jonas Bernoulli
      4 
      5 ;; Author: Jonas Bernoulli <jonas@bernoul.li>
      6 ;; Homepage: https://github.com/magit/ghub
      7 ;; Keywords: tools
      8 ;; SPDX-License-Identifier: GPL-3.0-or-later
      9 
     10 ;; This file is not part of GNU Emacs.
     11 
     12 ;; This file is free software; you can redistribute it and/or modify
     13 ;; it under the terms of the GNU General Public License as published by
     14 ;; the Free Software Foundation; either version 3, or (at your option)
     15 ;; any later version.
     16 
     17 ;; This file is distributed in the hope that it will be useful,
     18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     20 ;; GNU General Public License for more details.
     21 
     22 ;; For a copy of the GPL see https://www.gnu.org/licenses/gpl.txt.
     23 
     24 ;;; Commentary:
     25 
     26 ;; Buck is a library that provides basic support for using the Bitbucket API
     27 ;; from Emacs packages.  It abstracts access to API resources using only
     28 ;; a handful of functions that are not resource-specific.
     29 
     30 ;; This library is implemented on top of Ghub.  Unlike Ghub, Buck does
     31 ;; not support the guided creation of tokens because Bitbucket lacks the
     32 ;; features that would be necessary to implement that.  Users have to
     33 ;; create tokens through the web interface.
     34 
     35 ;;; Code:
     36 
     37 (require 'ghub)
     38 
     39 (defconst buck-default-host "api.bitbucket.org/2.0"
     40   "The default host that is used if `buck.host' is not set.")
     41 
     42 ;; HEAD and PATCH are not supported according to
     43 ;; https://developer.atlassian.com/bitbucket/api/2/reference/meta/uri-uuid
     44 
     45 (cl-defun buck-get (resource &optional params
     46                              &key query payload headers
     47                              silent unpaginate noerror reader
     48                              username auth host
     49                              callback errorback extra)
     50   "Make a `GET' request for RESOURCE, with optional query PARAMS.
     51 Like calling `ghub-request' (which see) with \"GET\" as METHOD
     52 and `bitbucket' as FORGE."
     53   (ghub-request "GET" resource params :forge 'bitbucket
     54                 :query query :payload payload :headers headers
     55                 :silent silent :unpaginate unpaginate
     56                 :noerror noerror :reader reader
     57                 :username username :auth auth :host host
     58                 :callback callback :errorback errorback :extra extra))
     59 
     60 (cl-defun buck-put (resource &optional params
     61                              &key query payload headers
     62                              silent unpaginate noerror reader
     63                              username auth host
     64                              callback errorback extra)
     65   "Make a `PUT' request for RESOURCE, with optional payload PARAMS.
     66 Like calling `ghub-request' (which see) with \"PUT\" as METHOD
     67 and `bitbucket' as FORGE."
     68   (ghub-request "PUT" resource params :forge 'bitbucket
     69                 :query query :payload payload :headers headers
     70                 :silent silent :unpaginate unpaginate
     71                 :noerror noerror :reader reader
     72                 :username username :auth auth :host host
     73                 :callback callback :errorback errorback :extra extra))
     74 
     75 (cl-defun buck-post (resource &optional params
     76                               &key query payload headers
     77                               silent unpaginate noerror reader
     78                               username auth host
     79                               callback errorback extra)
     80   "Make a `POST' request for RESOURCE, with optional payload PARAMS.
     81 Like calling `ghub-request' (which see) with \"POST\" as METHOD
     82 and `bitbucket' as FORGE."
     83   (ghub-request "POST" resource params :forge 'bitbucket
     84                 :query query :payload payload :headers headers
     85                 :silent silent :unpaginate unpaginate
     86                 :noerror noerror :reader reader
     87                 :username username :auth auth :host host
     88                 :callback callback :errorback errorback :extra extra))
     89 
     90 (cl-defun buck-delete (resource &optional params
     91                                 &key query payload headers
     92                                 silent unpaginate noerror reader
     93                                 username auth host
     94                                 callback errorback extra)
     95   "Make a `DELETE' request for RESOURCE, with optional payload PARAMS.
     96 Like calling `ghub-request' (which see) with \"DELETE\" as METHOD
     97 and `bitbucket' as FORGE."
     98   (ghub-request "DELETE" resource params :forge 'bitbucket
     99                 :query query :payload payload :headers headers
    100                 :silent silent :unpaginate unpaginate
    101                 :noerror noerror :reader reader
    102                 :username username :auth auth :host host
    103                 :callback callback :errorback errorback :extra extra))
    104 
    105 (cl-defun buck-request (method resource &optional params
    106                                &key query payload headers
    107                                silent unpaginate noerror reader
    108                                username auth host
    109                                callback errorback extra)
    110   "Make a request for RESOURCE and return the response body.
    111 Like calling `ghub-request' (which see) with `bitbucket' as FORGE."
    112   (ghub-request method resource params :forge 'bitbucket
    113                 :query query :payload payload :headers headers
    114                 :silent silent :unpaginate unpaginate
    115                 :noerror noerror :reader reader
    116                 :username username :auth auth :host host
    117                 :callback callback :errorback errorback :extra extra))
    118 
    119 (cl-defun buck-repository-id (owner name &key username auth host)
    120   "Return the id of the repository specified by OWNER, NAME and HOST."
    121   (substring (cdr (assq 'uuid
    122                         (buck-get (format "/repositories/%s/%s" owner name)
    123                                   nil
    124                                   :username username :auth auth :host host)))
    125              1 -1))
    126 
    127 ;;; _
    128 (provide 'buck)
    129 ;;; buck.el ends here