Get patch information from Gerrit using SSH

Source: Internet
Author: User

Use the command line (SSH) to query the Gerrit, official address: https://review.openstack.org/Documentation/cmd-query.html

Program examples

Import OS, JSON def Get_patch_info (Gerrit_home, patch_id):    cmd_str='ssh%s GERRIT query--format=json-- Comments change:%d'%(gerrit_home, patch_id)    = os.popen (cmd_str)    #  See note     process.close ()    = json.loads (output) # return is dict      return Jsn_data

Description: The query result will always return more than one row of query statistics on the last line, even if the query result is empty:
{"Morechanges": false, "runtimemilliseconds":, "RowCount": 1, "type": "Stats"}

If you use the shell, you can use JQ for parsing. JQ is able to format and select JSON results.

Install sudo apt-get install JQ

SSH review.example.com Gerrit Query--format=json--patch-sets--files change:89535 | JQ. > 89535-pretty.txtssh review.example.com Gerrit Query--format=json--patch-sets--files change:89535 > 89535-Pretty.txtcat89535-pretty.txt |JQ. Cat89535-pretty.txt | Jq". Status" #Remove the status of the patchCat89535-pretty.txt | Jq". Patchsets[0].files" #Remove the first Patchset modified file informationCat89535-pretty.txt | Jq"Keys" #List all keysCat89535-pretty.txt | Jq"Has (' owner ')" #whether the key exists

The following transfers are from: http://blog.chinaunix.net/uid-24774106-id-3830242.html

JSON-related I briefly introduced here, I hope to further understand the JQ and use can go to http://stedolan.github.io/jq/manual/, hope to understand the source of implementation, you can go to https://github.com/ STEDOLAN/JQ, it is expected that the author used flex and bison to parse json.

Our sample JSON comes from the first article in the reference document.

With Google search, there is an article in Kernalpanic about Jshon and json.sh provide additional ideas.

Reference documents:
1 How to parse JSON string via command line on Linux
2 Jq-command-line JSON processor

Get patch information from Gerrit using SSH

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.