nyymanni / jiralib2 Goto Github PK
View Code? Open in Web Editor NEWLisp bindings to JIRA REST API (used by Ejira)
License: GNU General Public License v3.0
Lisp bindings to JIRA REST API (used by Ejira)
License: GNU General Public License v3.0
This is my setup:
(require 'use-package)
(use-package jiralib2
:init
(setq jiralib2-url jira-server
jiralib2-auth 'basic
jiralib2-user-login-name user
request--curl-cookie-jar "")) ; following troubleshooting tip at README
; (it didn't work)
When I try to perform a query with jiralib2-jql-search
, the following happens:
user-error: Request failed: invalid request:
((errorMessages
Field 'assignee' does not exist or this field cannot be viewed by anonymous users.
Field 'issuetype' does not exist or this field cannot be viewed by anonymous users.)
(errors))
My current workaround is switching back and forth from 'basic
to 'cookie
and running M-x jiralib2-session-login
until the query works (it usually takes one back and forth).
Any idea of what's going on?
M-x emacs-version
: GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0) of 2021-03-27, modified by Debiancurl --version
:curl 7.74.0 (x86_64-pc-linux-gnu) libcurl/7.74.0 OpenSSL/1.1.1k zlib/1.2.11 brotli/1.0.9 libidn2/2.3.0 libpsl/0.21.0 (+libidn2/2.3.0) libssh2/1.9.0 nghttp2/1.43.0 librtmp/2.3
Release-Date: 2020-12-09
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps mqtt pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets
FIrst, thank you for this project!
jirallib2-get-users
fetches first 1000 rather than all users. This is preventing me from assigning an issue to myself or others not in the first 1000 listed. To fetch all users it is necessary to make multiple calls to the Jira REST API with startAt
incrementing by maxResults
until the length of the returned list of results is < 1000 (see this post).
Hi,
I've for a while been experiencing problems with requests against JIRA Cloud.
When using the default curl backend of request, I'm running into what seems to be a race condition when updating the Ejira agenda. At some point, the update process fails with the error »semaphore never called«.
When instead using url-retrieve as request backend, the update process works fine (and much quicker than with curl for some reason), but I get botched encoding in Org. I traced the error back to this function, where replacing 'no-conversion with 'cp1252 (wtf?) fixes the issue:
(defun request--parse-data (response encoding parser)
"In RESPONSE buffer, decode via ENCODING, then send to PARSER."
(let ((buffer (request-response--buffer response)))
(when (buffer-live-p buffer)
(with-current-buffer buffer
(request-log 'trace "request--parse-data: %s" (buffer-string))
(unless (eq (request-response-status-code response) 204)
(recode-region (point-min) (point-max) encoding 'cp1252) ; <-- Jira sending Windows-1252?
(goto-char (point-min))
(setf (request-response-data response)
(if parser (funcall parser) (buffer-string))))))))
This is of course just a hack, but I don't know how to proceed from here. Any suggestions? I'm on Emacs 28.1, BTW, with the latest request.el from Elpa, request-20221004.1331 as of this writing.
The jiralib2--get-users
function uses a fixed value of 1000 for the number of users it fetches at a time. However, I'm working with a server that has set its server-side limit to a smaller value (100). Since the API result data does not indicate this truncation in any way, the function thinks that the result is complete, since it is smaller than expected.
Would a PR to make max-results
configurable be acceptable?
I need to see what kind of JSON we get "raw" from this query but I don't think converting Issue labels to lisp labels is what's intended.
So Jira server at my corp using SAML frontend which requires javascript to as for AD auth then RSA auth then one gets a cookie. In full featured browsers this (can be made to) work(s) yet Ive tried with eww but it doesn't allow for javascript, and via the jiralib.. Am I just SOL due to the auth setup of our jira?
My environment is
Msys2 mingw64 and emacs
(emacs-version)
"GNU Emacs 26.3 (build 1, x86_64-w64-mingw32)
of 2019-11-02"
When I execute jiralib2-session-login to interact with my corp JIRA, jiralib2 return "Request failed: Could not reach the server".
I dig where wrong is.
I found the following error message in request block.
{"errorMessages":["Unexpected character ('u' (code 117)): expected a valid value ...
[error] request--callback: JSON readtable error: 40
Is there any way how to avoid this error?
Supplement information.
in scratch buffer
request-curl
"curl"
(executable-find request-curl)
"c:/msys64/usr/bin/curl.exe"
(setq request-log-level 'debug)
debug
(setq request-message-level 'debug)
debug
The following is request full debug message.
[debug] request--curl: curl --silent --location --cookie c:/yama/.emacs.d/request/curl-cookie-jar --cookie-jar c:/yama/.emacs.d/request/curl-cookie-jar --include --write-out \n(:num-redirects %{num_redirects} :url-effective %{url_effective}) --compressed --data-binary @c:/Users/000091~1/AppData/Local/Temp/emacs-requestnRROyU --request POST --header Content-Type: application/json https://www.tool.mycorp.biz/jira3/rest/auth/1/session
[debug] request--curl-callback: event finished
[debug] request--callback: UNPARSED
(:num-redirects 0 :url-effective password:hogehoge)HTTP/1.1 200 Connection established
HTTP/2 400
date: Tue, 14 Apr 2020 01:06:32 GMT
content-type: application/json;charset=UTF-8
content-length: 207
set-cookie: AWSALB=v7sHULgUTwH78j3aLHTXOmWAUc/YTk3BvABGp0Vo3TnHUMvnH9TH8Q2BJg4lTTnACUlQLw4k67eXcjmtsNDVdW+GIEqLqlqdaxwCNcGIx1Z9pMDUcEejkHz0aEqP; Expires=Tue, 21 Apr 2020 01:06:32 GMT; Path=/
set-cookie: AWSALBCORS=v7sHULgUTwH78j3aLHTXOmWAUc/YTk3BvABGp0Vo3TnHUMvnH9TH8Q2BJg4lTTnACUlQLw4k67eXcjmtsNDVdW+GIEqLqlqdaxwCNcGIx1Z9pMDUcEejkHz0aEqP; Expires=Tue, 21 Apr 2020 01:06:32 GMT; Path=/; SameSite=None; Secure
server: Apache
x-arequestid: 606x884703x2
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
content-security-policy: frame-ancestors 'self'
x-asen: SEN-2142834
x-asessionid: 1imrpu
x-ausername: anonymous
cache-control: no-cache, no-store, no-transform
content-encoding: gzip
vary: User-Agent
set-cookie: atlassian.xsrf.token=BYQ7-3M04-IV5R-DIUI_77ad03398c8a3fb26c858937396345390bda1a86_lout; Path=/jira3; Secure
set-cookie: JSESSIONID=E33C01D1FF3A9DF410F8189B59AC6844; Path=/jira3; Secure; HttpOnly
{"errorMessages":["Unexpected character ('u' (code 117)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@462591fe; line: 1, column: 2]"]}
[error] request--callback: JSON readtable error: 40
[debug] request--callback: executing error
[error] request-default-error-callback: https://www.tool.mycorp.biz/jira3/rest/auth/1/session parse-error
user-error: Request failed: Could not reach the server
Mark set [2 times]
Quit [2 times]
Mark set
Our Jira instance seems to work with different token authentication but it is very similar to the token authentication (just use Bearer
instead of Token
in Authentication field.
I'd like to push the patch I made to make the instance I use working. My Lisp-fu is weak but it is at least obvious what needs to be done.
diff --git a/jiralib2.el b/jiralib2.el
index bfcbfdf..163de29 100644
--- a/jiralib2.el
+++ b/jiralib2.el
@@ -68,6 +68,7 @@
:type '(choice
(const :tag "Cookie authentication" cookie)
(const :tag "Token authentication" token)
+ (const :tag "Bearer authentication" bearer)
(const :tag "Basic authentication" basic)))
(defvar jiralib2-json-array-type 'list
@@ -87,14 +88,17 @@
(interactive)
(setq jiralib2--session
(let* ((username (or username
+ (eq jiralib2-auth 'bearer)
jiralib2-user-login-name
(read-string "Username: ")))
(password (or password
- (and (eq jiralib2-auth 'token) jiralib2-token)
+ (and (member jiralib2-auth '(bearer token)) jiralib2-token)
(read-passwd (format "Password or token for user %s: "
username)))))
(cond ((member jiralib2-auth '(basic token))
(base64-encode-string (format "%s:%s" username password) t))
+ ((eq jiralib2-auth 'bearer)
+ jiralib2-token)
((eq jiralib2-auth 'cookie)
(let* ((json-array-type jiralib2-json-array-type)
(reply-data
@@ -162,6 +166,9 @@ Does not check for session validity."
:headers `(("Content-Type" . "application/json")
,(cond ((eq jiralib2-auth 'cookie)
`("cookie" . ,jiralib2--session))
+ ((eq jiralib2-auth 'bearer)
+ `("Authorization" . ,(format "Bearer %s"
+ jiralib2--session)))
((member jiralib2-auth '(basic token))
`("Authorization" . ,(format "Basic %s"
jiralib2--session)))))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.