Category: Atlassian JIRA
-
jira-markup-mode: Emacs major mode for JIRA-markup-formatted text files
Editing Jira markup in a simple browser text pane is a PITA. So I shall give this a try!
-
extracting fields from a Jira “issue” (like a very nice and useful description)? how to get the markup source of the issue description?
No, Jira does not let you read (“per se“) the markup source of an “issue” β that’s why I went this way in the first placeΒ π
- http://Jochen.Hayek.name/wp/blog-en/2015/12/02/jira-rest-api/Β β using Jira’s REST API: a “β¦/rest/api/2/issue/⦔ URL
- http://Jochen.Hayek.name/wp/blog-en/2015/12/22/jq-json-processor/ β how to use
jqfor json-tidying
jq . X.json > X.pretty.json
- http://Jochen.Hayek.name/wp/blog-en/2018/01/17/json-extract-structure/Β β extract the structure tree of your JSON data using
jqΒ and a nice command line
jq -c 'path(..)|[.[]|tostring]|join("/")|"."+.' X.pretty.json- the field we are interested in is
fields/description
jq ".fields.description" X.json > X.description.txt
- save the value of that field to a separate file!
- remove the leading and trailing double-quotes!
- replace all
\"with ordinary double-quotes! - remove
\r! - replace
\nwith ordinary new-lines!
jq ".fields.description" X.json | perl -pe 's/^"(.*)"$/$1/; s/\\"/"/g; s/\\r//g; s/\\n/\n/g' > X.description.txt
- β¦
- looks good, doesn’t it?
-
“Markdown”: further reading
- https://en.wikipedia.org/wiki/Markdown
- https://en.wikipedia.org/wiki/Markup_language
- https://en.wikipedia.org/wiki/Lightweight_markup_language — includes various tables
- http://daringfireball.net/projects/markdown/syntax – where it all began
- http://www.markdowntutorial.com
- http://www.markdowntutorial.com/conclusion/
- https://help.github.com/articles/basic-writing-and-formatting-syntax/
- https://github.github.com/gfm/ β GitHub Flavored Markdown spec
- https://gitlab.com/help/user/markdown β GitLab Flavored Markdown spec (a customer GitLab installation provides (resp. seems to provide) a version with a TOC)
- https://jira.atlassian.com/secure/WikiRendererHelpAction.jspa – Jira and its markup language
- https://en.wikipedia.org/wiki/Creole_(markup)
- http://overapi.com/org-mode β Emacs org-mode and its markup language
Emacs and Markdown:
-
one of my ongoing main software projects: create “diary entries” from activity streams
- my JIRA project activities β solved using JIRA’s REST API and in use
- procmail log file reflecting my incoming e-mail β solved β¦ and in use
- my blogging activities: my own WordPress “blogs” (better use the REST API than the Atom feed), the company “blogs” (Atlassian Confluence (also a wiki), β¦), β¦
- my wiki authoring activities: Wikipedia, β¦
Sample URL-s:
On Mediawiki’s CMS a user’s activity streams looks like this:
- https://en.wikipedia.org/wiki/Special:Contributions/Johayek (has an Atom feed)
On β¦ β¦ looks like this:
- β¦
These are the means to achieve my goals:
- Atom feeds
- REST API-s
-
Stephen Dolan’s “jq” is a lightweight and flexible command-line JSON processor
- https://stedolan.github.io/jq/
- https://stedolan.github.io/jq/tutorial/
- https://stedolan.github.io/jq/manual/
- https://github.com/stedolan/jq
- https://github.com/stedolan/jq/wiki
- https://github.com/stedolan/jq/wiki/Cookbook
- https://stackoverflow.com/questions/tagged/jq
- http://shop.oreilly.com/product/0636920032823.do β o’Reilly “Data Science at the Command Line” β has some examples making use of jq
- https://library.oreilly.com/book/0636920032823/data-science-at-the-command-line/84.xhtml?ref=toc#_jq β behind a paywall
- available as source (portable C) and as executables for various Intel-based platforms, i.e. some Linux distributions, Mac OS X, Windows incl. Cygwin
- https://cygwin.com/packages/x86_64/jq/
- https://www.safaribooksonline.com/library/view/json-at-work/9781491982389/ch06.html#json_search : β¦,
jq,jqPlay,jq-tutorial, β¦
“jq” (presumably) stands for “JSON query processor”.
jq helps writing shell scripts processing JSON responses from e.g. RESTful application APIs like Jenkins, Atlassian JIRA, Atlassian Confluence, β¦ β code making use of powerful means like XPath (β¦) or jq is supposedly far more readable than Python / Perl / β¦ scripts slurping the JSON and processing it (w/o jq resp. XPath) β but there are also Python resp. Perl bindings for jq.
Hope and fear
A couple of weeks ago I had written a shell script querying a Jenkins server’s REST API “Γ la XML”. Now it looks a little straighter to query the API “Γ la JSON” and employ jq. But the critical question is, whether the (industrial) customer (I wrote the Jenkins utility for) will like the dependency on a utility like jq. My Jenkins utility might have to serve for quite a couple of years β but who can predict the future and availability of jq?
Update 2016-02-23: Meanwhile I built a shell script with a couple of simple jq queries accessing Jenkins CI. Looks rather impressive to me.
If you do XPath queries from shell scripts, you always have the option to rewrite the shell script as Python or Perl script. But what about JSON queries (…) in Python or Perl?
- https://pypi.python.org/pypi/jq
- https://github.com/spiritloose/JQ — “Perl binding for jq”
By default, jq pretty-prints JSON output.
$ jq . < β¦ > β¦
-
the JIRA REST API, how to authenticate, β¦
- https://en.wikipedia.org/wiki/Jira_(software)
- https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-basic-authentication
- https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-cookie-based-authentication
- https://metacpan.org/module/json_pp β a nice utility, that also does JSON pretty-printing; it comes with http://search.cpan.org/perldoc?JSON
There are certainly legion of reasons to use a REST API and also to use the JIRA REST API, I wanted to create a linear “diary” of JIRA actions.
This is our sample JIRA issue URL:
http://kelpie9:8081/browse/QA-31
This is its corresponding REST URL:
http://kelpie9:8081/rest/api/2/issue/QA-31
Find yourself a working sample JIRA issue URL use the corresponding REST URL in your browser, save the JSON returned to a file!
You usually want to read “pretty” / tidied JSON, so before you start reading JSON, find yourself a JSON-tidy utility:
Usually we want to retrieve JSON from JIRA through REST URLs via the curl utility.
CAVEAT: See my note on the cookie jar below!
This is the “simple example”, that the page referred to above (“Basic Authentication“) shows you:
$ curl -D- -u fred:fred -X GET
-H "Content-Type: application/json"
http://kelpie9:8081/rest/api/2/search?jql=assignee=fredIf your JIRA site requires you to use “Basic Authentication”, you have to encode username:password base64-wise, and this is how to do it:
$ echo -n fred:fred | base64So if you want to use “Basic Authentication” with these credentials, this is how … (using our sample REST URL):
$ curl -D- -X GET
-H "Authorization: Basic $(echo -n fred:fred | base64)"
-H "Content-Type: application/json"
"http://kelpie9:8081/rest/api/2/issue/QA-31"During my experiments I got locked out of the company’s Active Directory / SSO quite a few times — and I had to call the help desk in order to get my account reset. This is what JIRA tells you, once it decides you have to go through a CAPTCHA_CHALLENGE procedure, because you are behaving a little too suspicious:
HTTP/1.1 403 Forbidden
Server: Apache-Coyote/1.1
X-AREQUESTID: ...
X-Seraph-LoginReason: AUTHENTICATED_FAILED
Set-Cookie: JSESSIONID=...; Path=/; Secure; HttpOnly
WWW-Authenticate: OAuth realm="https%3A%2F%2Fjira.___.com"
X-Content-Type-Options: nosniff
X-Authentication-Denied-Reason: CAPTCHA_CHALLENGE; login-url=https://jira.___.com/login.jsp
Content-Type: text/html;charset=UTF-8
Content-Length: 6494
Date: Wed, 02 Dec 2015 11:59:15 GMT
But once you are beyond this, making use of the JIRA REST API works like a charm.
Update: Although I certainly had not failed (“basic”) authentication, JIRA got my Active Directory / SSO account locked again and again. My new strategy:
- 1st logon through “basic authentication” and store the cookie jar
- further authentications (during a script run) though the cookie stored before — yes, I will supply you with examples here in the near future
Wishlist:
- instead of shell+curl use perl+libcurl
- use the “epic link” to get the “epic link nice name” in order to describe the issue as “issue# + epic-link-nice-name + summary”
- extend the tool to also deal with Atlassian Confluence
-
Atlassian FishEye: Subversion, Git, Mercurial, CVS, & Perforce in your browser.
FishEye – Subversion, Git, Mercurial, CVS, & Perforce in your browser.:
FishEye provides a web interface for Subversion, Git, CVS & Perforce source control repositories. Features include email & RSS feeds, JIRA integration, charts, search.
Get started for $10 or a free 30-day trial.