Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# the repo. Unless a later match takes precedence,
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.
* @cdavis-personal
* @cdaviis @tpospisil
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Describe the change(s).
Describe the reason for the change(s).

## Testing
Describe how to test your change(s).
Describe how to test your change(s).
4 changes: 2 additions & 2 deletions .github/workflows/gem-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Ruby Gem

on:
push:
branches: [ "main" ]
# branches: [ "main" ]
pull_request:
branches: [ "main" ]
# branches: [ "main" ]

jobs:
build:
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
## [Unreleased]

## [0.6.0] - 2025-08-20

### Changed
- Updated Test Cycles resource to support `testCycleIdOrKey` parameter for all relevant methods
- Renamed resource methods for consistency with the API (e.g., `create_test_cycle` instead of `create_testcycle`)
- Updated CLI implementation to handle both ID and key parameters
- Changed payload generators to use `projectKey` instead of `projectId` to match API requirements
- Improved CLI parameter handling using Thor options hash
- Added better handling for boolean parameters in automation payloads

### Added
- Added aliases for backward compatibility with old method names
- Added better parameter descriptions in CLI commands
- Added support for `autoCloseCycle` parameter in automation payloads

### Backward Compatibility
- Maintained full backward compatibility with existing code
- CLI commands support both positional arguments and options hash
- Payload generators accept both `project_id` (numeric) and `project_key` (string)
- Resource methods maintain aliases for old method names
- API client automatically handles both numeric IDs and string keys

## [0.1.0] - 2022-11-24

- Initial release
7 changes: 7 additions & 0 deletions exe/zephyr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'zephyr_ruby'
require 'zephyr_ruby/cli'

ZephyrRuby::CLI::Main.start(ARGV)
8 changes: 8 additions & 0 deletions lib/zephyr_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@

module ZephyrRuby
class Error < StandardError; end

# Load CLI functionality if Thor is available
begin
require 'thor'
require_relative 'zephyr_ruby/cli'
rescue LoadError
# CLI functionality not available
end
end
43 changes: 43 additions & 0 deletions lib/zephyr_ruby/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

require 'thor'
require 'nokogiri'
require_relative 'cli/helpers/cli_helpers'
require_relative 'cli/test_cycles'
require_relative 'cli/test_plans'

module ZephyrRuby
module CLI
# Main CLI class for zephyr_ruby
class Main < Thor
class_option :api_key, type: :string, desc: 'Zephyr API Key (can also be set via ZEPHYR_API_KEY env var)'

def initialize(*args)
super
# Only check for API key if we're not showing help
return if ARGV.include?('help') || ARGV.include?('--help') || ARGV.empty?

api_key = options[:api_key] || ENV['ZEPHYR_API_KEY']
unless api_key
puts "Error: API key is required. Set it with --api-key option or ZEPHYR_API_KEY env var"
exit(1)
end

@zephyr_client = ZephyrRuby::Client.new(api_key)
end

desc "test_cycles", "Test cycles commands"
subcommand "test_cycles", TestCycles

desc "test_plans", "Test plans commands"
subcommand "test_plans", TestPlans

# Make the client accessible to subcommands
no_commands do
def zephyr_client
@zephyr_client
end
end
end
end
end
77 changes: 77 additions & 0 deletions lib/zephyr_ruby/cli/helpers/cli_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# frozen_string_literal: true

module ZephyrRuby
module CLI
# Helpers module to share common methods among the CLI classes
module Helpers
def generate_automations_payload(project_identifier, file, auto_close_cycle, name, description, auto_create_test_cases)
# Convert to boolean if it's not already
auto_create_test_cases = auto_create_test_cases.to_s.downcase == 'true' unless [true, false].include?(auto_create_test_cases)

payload = {
file: file,
autoCreateTestCases: auto_create_test_cases,
testCycle: {
name: name,
description: description || ""
}
}

# Handle different formats of project identifier for backward compatibility
if project_identifier.is_a?(Integer) || project_identifier.to_s.match?(/^\d+$/)
# Old style: numeric project_id - convert to string for new API
payload[:projectKey] = project_identifier.to_s
# Also include projectId for backward compatibility with any custom integrations
payload[:projectId] = project_identifier.to_i
else
# New style: string project_key
payload[:projectKey] = project_identifier
end

# Add autoCloseCycle if provided
if auto_close_cycle
auto_close_cycle = auto_close_cycle.to_s.downcase == 'true' unless [true, false].include?(auto_close_cycle)
payload[:autoCloseCycle] = auto_close_cycle
end

payload
end

def generate_test_cycle_payload(name, description, start_date, end_date, project_identifier)
payload = {
name: name,
description: description,
plannedStartDate: start_date,
plannedEndDate: end_date
}

# Handle different formats of project identifier for backward compatibility
if project_identifier.is_a?(Hash)
# New style: {key: value} format from refactored code
payload.merge!(project_identifier)
elsif project_identifier.is_a?(Integer) || project_identifier.to_s.match?(/^\d+$/)
# Old style: numeric project_id
payload[:projectId] = project_identifier.to_i
else
# New style: string project_key
payload[:projectKey] = project_identifier
end

payload
end

def generate_test_plan_payload(project_key, name, objective, folder_id, status_name, owner_id, labels, custom_fields = {})
{
projectKey: project_key,
name: name,
objective: objective,
folderId: folder_id,
statusName: status_name,
ownerId: owner_id,
labels: labels,
customFields: custom_fields
}
end
end
end
end
Loading
Loading