Skip to content

itmagelab/rujira

Repository files navigation

RUJIRA

Ruby

RUJIRA is a Ruby gem for easy interaction with the Jira API. It provides a simple and flexible interface to work with Jira resources and includes Rake tasks for convenient command-line operations.

This project was created as an alternative to https://github.com/sumoheavy/jira-ruby, offering a more user-friendly and intuitive interface. It lets you work with requests as objects or hash arrays, provides flexibility in choosing a connection adapter, and makes the codebase easier to maintain.


Features

  • Easy DSL for building and executing Jira API requests.
  • Built-in Rake tasks for console operations (e.g., creating issues, updating data, exporting).

Installation

Add to your Gemfile:

gem 'rujira', '~> 0.7.0'

Or install directly:

gem install rujira

Quick Start

Configuration

 cat .env
RUJIRA_TOKEN='<TOKEN>'
RUJIRA_DEBUG=true
LOG_LEVEL=error

Example of usage

By default, we can use an object-oriented approach, but this method does not cover all API capabilities.

url = ENV.fetch('RUJIRA_URL', 'http://localhost:8080')
client = Rujira::Client.new(url, wrap_responses: true)

project = random_name
me = client.Myself.get
project = me.create_software_project key: project.to_s,
                                     name: project.to_s
task = project.add_task summary: 'BOT: added a new task.',
                        description: 'This task was generated by the bot when creating changes in the repository.'
task.add_comment 'Bot added a comment as obj #1'
task.attach_file '/tmp/upload.file'

Demonstrates the full lifecycle of a Jira user: creation, retrieval, update, deactivation, and deletion using the Rujira client.

url = ENV.fetch('RUJIRA_URL', 'http://localhost:8080')
client = Rujira::Client.new(url, wrap_responses: true)

username = random_name
me = client.Myself.get

user = client.User.create do
  payload({
            name: username,
            password: username,
            emailAddress: "#{username}@username",
            displayName: "#{username} created be #{me.name}",
            applicationKeys: ['jira-core']
          })
end

user = client.User.get user.key

user.update do
  payload emailAddress: 'root@test'
end

user.deactivate!
user.delete

This function demonstrates that the library supports executing requests in parallel using multiple threads. By processing tasks concurrently, it significantly improves performance when handling a large number of repetitive operations, such as creating or deleting entities.

url = ENV.fetch('RUJIRA_URL', 'http://localhost:8080')
client = Rujira::Client.new(url, debug: true, wrap_responses: false, lazy: true)

me = client.Myself.get.execute

queue = Queue.new

project_name = random_name
project = client.Project.create do
  payload key: project_name.to_s,
          name: project_name.to_s,
          projectTypeKey: 'software',
          lead: me['name']
end.to_obj

count.times do
  task = project.add_task summary: 'BOT: added a new task.',
                          description: 'This task was generated by the bot when creating changes in the repository.'
  queue << task
end

workers = thread.times.map do
  Thread.new do
    until queue.empty?
      begin
        task = begin
          queue.pop(true)
        rescue StandardError
          nil
        end
        next unless task

        task = task.to_obj

        task.delete
      rescue StandardError => e
        warn "Error in thread: #{e.message}"
      end
    end
  end
end

workers.each(&:join)
project.delete

Alternatively, we can work with the API directly, as with a regular request dispatcher; in this form, most operations are available.

require 'date'

now = Date.today
before = now + 30

project = random_name
url = ENV.fetch('RUJIRA_URL', 'http://localhost:8080')
client = Rujira::Client.new(url, debug: true)

client.ServerInfo.get
name = client.Myself.get['name']

client.Project.create do
  payload key: project.to_s,
          name: project.to_s,
          projectTypeKey: 'software',
          lead: name
end
client.Project.get project.to_s
client.Issue.create do
  payload fields: {
    project: { key: project.to_s },
    summary: 'BOT: added a new feature.',
    description: 'This task was generated by the bot when creating changes in the repository.',
    issuetype: { name: 'Task' }
  }
  params updateHistory: true
end

client.Board.list
client.Board.get 1

sprint = client.Sprint.create do
  payload name: 'Bot Sprint',
          originBoardId: 1,
          goal: 'Finish core features for release 1.0',
          autoStartStop: false
end
client.Sprint.issue sprint['id'], ["#{project}-1"]

client.Sprint.replace sprint['id'] do
  payload state: 'future',
          name: 'Bot Sprint',
          originBoardId: 1,
          goal: 'Finish core features for release 1.0',
          startDate: now,
          endDate: before,
          autoStartStop: true
end

update = client.Sprint.update sprint['id'] do
  payload name: "Bot Sprint #{project}"
end
issues = client.Sprint.get_issue sprint['id']

client.Issue.get "#{project}-1"

client.Issue.watchers "#{project}-1", name
search = client.Search.get do
  payload jql: "project = #{project} and status IN (\"To Do\", \"In Progress\") ORDER BY issuekey",
          maxResults: 10,
          startAt: 0,
          fields: %w[id key]
end
client.Issue.comment "#{project}-1" do
  payload body: 'Adding a new comment'
end
client.Issue.edit "#{project}-1" do
  payload update: {
            labels: [{ add: 'bot' }, { remove: 'some' }]
          },
          fields: {
            assignee: { name: name },
            summary: 'This is a shorthand for a set operation on the summary field'
          }
end

sprints = client.Board.sprint 1
sprints['values'].each do |sprint|
  client.Sprint.delete sprint['id']
end
search['issues'].each do |issue|
  client.Issue.delete issue['id'] do
    params deleteSubtasks: true
  end
end
client.Project.delete project.to_s

client.Dashboard.list
client.Dashboard.get 10_000
  • The builder method automatically applies the authorization token.
  • The block allows customization of headers, parameters, and other request options.

Rake Tasks

The gem includes Rake tasks for easy use from the command line. Examples:

rake jira:board:get               # Get a board
rake jira:board:list              # Get list of boards
rake jira:board:sprint            # Get a boards sprint
rake jira:dashboard:get           # Get a dashboard
rake jira:dashboard:list          # Get list of dashboards
rake jira:issue:attach            # Example usage attaching in issue
rake jira:issue:create            # Create a issue
rake jira:issue:delete            # Delete issue
rake jira:issue:generate_link     # Generate a Jira link for creating a new issue
rake jira:issue:search            # Search issue by fields
rake jira:project:create          # Create project
rake jira:project:list            # Get list of projects
rake jira:server_info             # Test connection by getting server information
rake jira:sprint:properties:list  # Get sprint properties
rake jira:whoami                  # Test connection by getting username
rake jira:issue:create PROJECT=ITMG SUMMARY='The short summary information' \
      DESCRIPTION='The base description of task' ISSUETYPE='Task'
rake jira:issue:search JQL='project = ITMG'
rake jira:issue:attach FILE='upload.png' ISSUE_ID='ITMG-1'

Generate a Jira Issue Creation Link

The generate_link task interactively collects input (project, summary, description, and issue type) and generates a ready-to-use Jira URL with pre-filled fields for creating a new issue.

It opens your default editor for entering the description and then outputs a link that can be opened in a browser.

Usage

rake jira::issue::generate_link

Example session

Project key (e.g., ABC): TEST
Summary (short description): Fix login bug
Opening editor for description...
Issue type (Bug/Task/Story): Bug

Output

Generated issue creation link:
https://your-jira-instance/secure/CreateIssueDetails!init.jspa?pid=10000&summary=Fix+login+bug&description=Steps+to+reproduce...&reporter=john.doe&issuetype=1

Development runs

docker compose up -d
open http://localhost:8080
curl -H "Authorization: Bearer <JIRA_ACCESS_TOKEN>" 'http://localhost:8080/rest/api/2/search?expand=summary'
curl -vv -X POST --data '"some"' -H "Authorization: Bearer <JIRA_ACCESS_TOKEN>" -H "Content-Type: application/json" 'http://localhost:8080/rest/api/2/issue/ITMG-70/watchers'
curl -D- -F "file=@upload.png" -X POST -H "X-Atlassian-Token: nocheck" \
    -H "Authorization: Bearer <JIRA_ACCESS_TOKEN>" 'http://localhost:8080/rest/api/2/issue/ITMG-70/attachments'

Contribution

  • Pull requests are welcome.
  • For issues or feature requests, please use GitHub Issues.

License

MIT License © 2025 iTmageLAB

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

 
 
 

Contributors