Function: gitlab-ci-request-lint

gitlab-ci-request-lint is a natively compiled function defined in gitlab-ci-mode.el.

Signature

(gitlab-ci-request-lint CALLBACK &optional SILENT)

Documentation

Run the current buffer against the GitLab CI linter.

This function uploads the contents of the current buffer to
‘gitlab-ci-url’, authorizing the request with
‘gitlab-ci-api-token’ (if set).

When the request is complete, CALLBACK receives two arguments. If the first is ‘finished’, then the second is the decoded JSON response from the API. If it is ‘errored’, then the second is an error message. SILENT is as to ‘url-retrieve’.

Source Code

;; Defined in /nix/store/i3kilmgmg3bk0mkr28r6pk0h5mg4s0wd-emacs-packages-deps/share/emacs/site-lisp/elpa/gitlab-ci-mode-20191022.2017/gitlab-ci-mode.el
(defun gitlab-ci-request-lint (callback &optional silent)
  "Run the current buffer against the GitLab CI linter.

This function uploads the contents of the current buffer to
‘gitlab-ci-url’, authorizing the request with
‘gitlab-ci-api-token’ (if set).

When the request is complete, CALLBACK receives two arguments.
If the first is ‘finished’, then the second is the decoded JSON
response from the API.  If it is ‘errored’, then the second is an
error message.  SILENT is as to ‘url-retrieve’."
  (let* ((url-request-method "POST")
         (url-request-data
          (let ((h (make-hash-table)))
            (puthash "content" (substring-no-properties (buffer-string)) h)
            (encode-coding-string (json-encode h) 'utf-8)))
         (url-request-extra-headers
          '(("Content-Type" . "application/json")))
         (url (concat gitlab-ci-url "/api/v4/ci/lint")))

    (when gitlab-ci-api-token
      (add-to-list 'url-request-extra-headers
                   `("Private-Token" . ,gitlab-ci-api-token)))

    ;; TODO: Handle HTTP 429 responses and delay internally. (However,
    ;; GitLab’s API limit is fairly high relative to human typing speed,
    ;; so the idle timers within e.g. Flycheck may be enough for now.)
    (url-retrieve url #'gitlab-ci--lint-results
                  (list callback (current-buffer))
                  silent)))