Skip to content

Commit

Permalink
Merge branch 'master' into fix-get-user
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbrodie authored Apr 30, 2024
2 parents 2dbb9ca + 3e1deb0 commit 0434027
Show file tree
Hide file tree
Showing 14 changed files with 244 additions and 78 deletions.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: Bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
A runnable code example to reproduce the issue.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: Feature
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context about the feature request here.
100 changes: 100 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "master" ]
paths-ignore:
- '**/*.md'
- 'http-basic-example.rb'
- 'example.rb'
pull_request:
branches: [ "master" ]
paths-ignore:
- '**/*.md'
- 'http-basic-example.rb'
- 'example.rb'
schedule:
- cron: '0 13 * * *'

jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
# required for all workflows
security-events: write

# required to fetch internal or private CodeQL packs
packages: read

# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
matrix:
include:
- language: ruby
build-mode: none
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
1 change: 0 additions & 1 deletion lib/jira-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
require 'jira/resource/issue_picker_suggestions'
require 'jira/resource/remotelink'
require 'jira/resource/sprint'
require 'jira/resource/sprint_report'
require 'jira/resource/resolution'
require 'jira/resource/issue'
require 'jira/resource/filter'
Expand Down
6 changes: 2 additions & 4 deletions lib/jira/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module JIRA
# :default_headers => {},
# :use_client_cert => false,
# :read_timeout => nil,
# :max_retries => nil,
# :http_debug => false,
# :shared_secret => nil,
# :cert_path => nil,
Expand Down Expand Up @@ -86,6 +87,7 @@ class Client
:default_headers,
:use_client_cert,
:read_timeout,
:max_retries,
:http_debug,
:issuer,
:base_url,
Expand Down Expand Up @@ -230,10 +232,6 @@ def Sprint
JIRA::Resource::SprintFactory.new(self)
end

def SprintReport
JIRA::Resource::SprintReportFactory.new(self)
end

def ServerInfo
JIRA::Resource::ServerInfoFactory.new(self)
end
Expand Down
1 change: 1 addition & 0 deletions lib/jira/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def http_conn(uri)
http_conn.verify_mode = @options[:ssl_verify_mode]
http_conn.ssl_version = @options[:ssl_version] if @options[:ssl_version]
http_conn.read_timeout = @options[:read_timeout]
http_conn.max_retries = @options[:max_retries] if @options[:max_retries]
http_conn.ca_file = @options[:ca_file] if @options[:ca_file]
http_conn
end
Expand Down
8 changes: 3 additions & 5 deletions lib/jira/resource/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.endpoint_name
end

def self.meta(client)
response = client.get(client.options[:rest_base_path] + '/attachment/meta')
response = client.get("#{client.options[:rest_base_path]}/attachment/meta")
parse_json(response.body)
end

Expand All @@ -42,7 +42,7 @@ def self.meta(client)
# @yieldparam [IO] file The IO object streaming the download.
def download_file(headers = {}, &block)
default_headers = client.options[:default_headers]
URI.open(content, default_headers.merge(headers), &block)
URI.parse(content).open(default_headers.merge(headers), &block)
end

# Downloads the file contents as a string object.
Expand All @@ -54,9 +54,7 @@ def download_file(headers = {}, &block)
# @param [Hash] headers Any additional headers to call Jira.
# @return [String,NilClass] The file contents.
def download_contents(headers = {})
download_file(headers) do |file|
file.read
end
download_file(headers, &:read)
end

def save!(attrs, path = url)
Expand Down
32 changes: 8 additions & 24 deletions lib/jira/resource/sprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,22 @@ def self.find(client, key)

# get all issues of sprint
def issues(options = {})
jql = 'sprint = ' + id.to_s
jql = "sprint = #{id.to_s}"
jql += " and updated >= '#{options[:updated]}'" if options[:updated]
Issue.jql(client, jql)
end

def add_issue(issue)
add_issues( [ issue ])
add_issues([issue])
end

def add_issues(issues)
issue_ids = issues.map{ |issue| issue.id }
issue_ids = issues.map(&:id)
request_body = { issues: issue_ids }.to_json
client.post("#{agile_path}/issue", request_body)
true
end

def sprint_report
get_sprint_details_attribute('sprint_report')
end

def start_date
get_sprint_details_attribute('start_date')
end
Expand All @@ -47,36 +43,24 @@ def complete_date
def get_sprint_details_attribute(attribute_name)
attribute = instance_variable_get("@#{attribute_name}")
return attribute if attribute

get_sprint_details
instance_variable_get("@#{attribute_name}")
end

def get_sprint_details
search_url =
"#{client.options[:site]}#{client.options[:client_path]}/rest/greenhopper/1.0/rapid/charts/sprintreport?rapidViewId=#{rapidview_id}&sprintId=#{id}"
"#{client.options[:site]}#{client.options[:client_path]}/rest/agile/1.0/sprint/#{id}"
begin
response = client.get(search_url)
rescue StandardError
return nil
end
json = self.class.parse_json(response.body)

@start_date = Date.parse(json['sprint']['startDate']) unless json['sprint']['startDate'] == 'None'
@end_date = Date.parse(json['sprint']['endDate']) unless json['sprint']['endDate'] == 'None'
@completed_date = Date.parse(json['sprint']['completeDate']) unless json['sprint']['completeDate'] == 'None'
@sprint_report = client.SprintReport.build(json['contents'])
end

def rapidview_id
return @attrs['rapidview_id'] if @attrs['rapidview_id']
search_url = client.options[:site] + '/secure/GHGoToBoard.jspa?sprintId=' + id.to_s
begin
response = client.get(search_url)
rescue JIRA::HTTPError => error
return unless error.response.instance_of? Net::HTTPFound
rapid_view_match = /rapidView=(\d+)&/.match(error.response['location'])
@attrs['rapidview_id'] = rapid_view_match[1] unless rapid_view_match.nil?
end
@start_date = json['startDate'] && Date.parse(json['startDate'])
@end_date = json['endDate'] && Date.parse(json['endDate'])
@complete_date = json['completeDate'] && Date.parse(json['completeDate'])
end

def save(attrs = {}, _path = nil)
Expand Down
8 changes: 0 additions & 8 deletions lib/jira/resource/sprint_report.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/jira/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module JIRA
VERSION = '2.3.0'.freeze
VERSION = '3.0.0'.freeze
end
22 changes: 22 additions & 0 deletions spec/jira/http_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
JIRA::HttpClient.new(options)
end

let(:basic_client_with_max_retries) do
options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS).merge(
max_retries: 2
)
JIRA::HttpClient.new(options)
end

let(:response) do
response = double('response')
allow(response).to receive(:kind_of?).with(Net::HTTPSuccess).and_return(true)
Expand Down Expand Up @@ -331,6 +338,21 @@
expect(client.http_conn(client.uri).ca_file).to eql('/opt/custom.ca.pem')
end

it 'allows overriding max_retries' do
http_conn = double
uri = double
host = double
port = double
expect(uri).to receive(:host).and_return(host)
expect(uri).to receive(:port).and_return(port)
expect(Net::HTTP).to receive(:new).with(host, port).and_return(http_conn)
expect(http_conn).to receive(:use_ssl=).with(basic_client.options[:use_ssl]).and_return(http_conn)
expect(http_conn).to receive(:verify_mode=).with(basic_client.options[:ssl_verify_mode]).and_return(http_conn)
expect(http_conn).to receive(:read_timeout=).with(basic_client.options[:read_timeout]).and_return(http_conn)
expect(http_conn).to receive(:max_retries=).with(basic_client_with_max_retries.options[:max_retries]).and_return(http_conn)
expect(basic_client_with_max_retries.http_conn(uri)).to eq(http_conn)
end

it 'returns a http connection' do
http_conn = double
uri = double
Expand Down
Loading

0 comments on commit 0434027

Please sign in to comment.