|
1 | 1 | # JIRA API Gem
|
2 | 2 |
|
3 | 3 | [](https://codeclimate.com/github/sumoheavy/jira-ruby)
|
4 |
| -[](https://travis-ci.org/sumoheavy/jira-ruby) |
| 4 | +[](https://github.com/sumoheavy/jira-ruby/actions/workflows/CI.yml) |
5 | 5 |
|
6 | 6 | This gem provides access to the Atlassian JIRA REST API.
|
7 | 7 |
|
8 |
| -## Slack |
| 8 | +## Example usage |
9 | 9 |
|
10 |
| -Join our Slack channel! You can find us [here](https://jira-ruby-slackin.herokuapp.com/) |
| 10 | +# Jira Ruby API - Sample Usage |
11 | 11 |
|
12 |
| -## Example usage |
| 12 | +This sample usage demonstrates how you can interact with JIRA's API using the [jira-ruby gem](https://github.com/sumoheavy/jira-ruby). |
13 | 13 |
|
14 |
| -```ruby |
15 |
| -require 'rubygems' |
16 |
| -require 'jira-ruby' |
| 14 | +### Dependencies |
| 15 | + |
| 16 | +Before running, install the `jira-ruby` gem: |
17 | 17 |
|
| 18 | +```shell |
| 19 | +gem install jira-ruby |
| 20 | +``` |
| 21 | + |
| 22 | +### Sample Usage |
| 23 | +Connect to JIRA |
| 24 | +Firstly, establish a connection with your JIRA instance by providing a few configuration parameters: |
| 25 | +There are other ways to connect to JIRA listed below | [Personal Access Token](#configuring-jira-to-use-personal-access-tokens-auth) |
| 26 | +- private_key_file: The path to your RSA private key file. |
| 27 | +- consumer_key: Your consumer key. |
| 28 | +- site: The URL of your JIRA instance. |
| 29 | + |
| 30 | +```ruby |
18 | 31 | options = {
|
19 |
| - :username => 'username', |
20 |
| - :password => 'pass1234', |
21 |
| - :site => 'http://mydomain.atlassian.net:443/', |
22 |
| - :context_path => '', |
23 |
| - :auth_type => :basic |
| 32 | + :private_key_file => "rsakey.pem", |
| 33 | + :context_path => '', |
| 34 | + :consumer_key => 'your_consumer_key', |
| 35 | + :site => 'your_jira_instance_url' |
24 | 36 | }
|
25 | 37 |
|
26 | 38 | client = JIRA::Client.new(options)
|
| 39 | +``` |
27 | 40 |
|
28 |
| -project = client.Project.find('SAMPLEPROJECT') |
| 41 | +### Retrieve and Display Projects |
29 | 42 |
|
30 |
| -project.issues.each do |issue| |
31 |
| - puts "#{issue.id} - #{issue.summary}" |
| 43 | +After establishing the connection, you can fetch all projects and display their key and name: |
| 44 | +```ruby |
| 45 | +projects = client.Project.all |
| 46 | + |
| 47 | +projects.each do |project| |
| 48 | + puts "Project -> key: #{project.key}, name: #{project.name}" |
32 | 49 | end
|
33 | 50 | ```
|
34 | 51 |
|
| 52 | +### Handling Fields by Name |
| 53 | +The jira-ruby gem allows you to refer to fields by their custom names rather than identifiers. Make sure to map fields before using them: |
| 54 | + |
| 55 | +```ruby |
| 56 | +client.Field.map_fields |
| 57 | + |
| 58 | +old_way = issue.customfield_12345 |
| 59 | + |
| 60 | +# Note: The methods mapped here adopt a unique style combining PascalCase and snake_case conventions. |
| 61 | +new_way = issue.Special_Field |
| 62 | +``` |
| 63 | + |
| 64 | +### JQL Queries |
| 65 | +To find issues based on specific criteria, you can use JIRA Query Language (JQL): |
| 66 | + |
| 67 | +```ruby |
| 68 | +client.Issue.jql(a_normal_jql_search, fields:[:description, :summary, :Special_field, :created]) |
| 69 | +``` |
| 70 | + |
| 71 | +### Several actions can be performed on the Issue object such as create, update, transition, delete, etc: |
| 72 | +### Creating an Issue |
| 73 | +```ruby |
| 74 | +issue = client.Issue.build |
| 75 | +labels = ['label1', 'label2'] |
| 76 | +issue.save({ |
| 77 | + "fields" => { |
| 78 | + "summary" => "blarg from in example.rb", |
| 79 | + "project" => {"key" => "SAMPLEPROJECT"}, |
| 80 | + "issuetype" => {"id" => "3"}, |
| 81 | + "labels" => labels, |
| 82 | + "priority" => {"id" => "1"} |
| 83 | + } |
| 84 | +}) |
| 85 | +``` |
| 86 | + |
| 87 | +### Updating/Transitioning an Issue |
| 88 | +```ruby |
| 89 | +issue = client.Issue.find("10002") |
| 90 | +issue.save({"fields"=>{"summary"=>"EVEN MOOOOOOARRR NINJAAAA!"}}) |
| 91 | + |
| 92 | +issue_transition = issue.transitions.build |
| 93 | +issue_transition.save!('transition' => {'id' => transition_id}) |
| 94 | +``` |
| 95 | + |
| 96 | +### Deleting an Issue |
| 97 | +```ruby |
| 98 | +issue = client.Issue.find('SAMPLEPROJECT-2') |
| 99 | +issue.delete |
| 100 | +``` |
| 101 | + |
| 102 | +### Other Capabilities |
| 103 | +Apart from the operations listed above, this API wrapper supports several other capabilities like: |
| 104 | + • Searching for a user |
| 105 | + • Retrieving an issue's watchers |
| 106 | + • Changing the assignee of an issue |
| 107 | + • Adding attachments and comments to issues |
| 108 | + • Managing issue links and much more. |
| 109 | + |
| 110 | +Not all examples are shown in this README; refer to the complete script example for a full overview of the capabilities supported by this API wrapper. |
| 111 | + |
35 | 112 | ## Links to JIRA REST API documentation
|
36 | 113 |
|
37 | 114 | * [Overview](https://developer.atlassian.com/display/JIRADEV/JIRA+REST+APIs)
|
|
87 | 164 | > After you have entered all the information click OK and ensure OAuth authentication is
|
88 | 165 | > enabled.
|
89 | 166 |
|
90 |
| -For 2 legged oauth in server mode only, not in cloud based JIRA, make sure to `Allow 2-Legged OAuth` |
| 167 | +For two legged oauth in server mode only, not in cloud based JIRA, make sure to `Allow 2-Legged OAuth` |
91 | 168 |
|
92 | 169 | ## Configuring JIRA to use HTTP Basic Auth
|
93 | 170 |
|
|
0 commit comments