Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIRA::HTTPError: Not Found - /jira/request_client.rb:13:in request' #399

Open
Sachin796 opened this issue Jan 19, 2023 · 2 comments
Open

Comments

@Sachin796
Copy link

Sachin796 commented Jan 19, 2023

Help to resolve JIRA::HTTPError: Not Found error while executing a ruby file from policies file.

Behaviour

  • I am currently making use of .triage-policies file for some automation in which I have a function that uses the jira-ruby gem to connect to the ,local JIRA server setup.
  • The curent URL is of the format https://jira.xxx.xx
  • For the policies file I am currently using the gitlab-triage project, which has an option to mention a function which is written inside the custom .rb files and those functions are executed.

Approach

  • The following is the code snippet that is used to connect to the JIRA using the gem

# frozen_string_literal: true

require 'jira-ruby'
require 'json'

module Test
  module Jira
    # Connection to JIRA API.
    class Connection
      API_TOKEN = ENV.fetch('JIRA_USER_TOKEN', nil)
      attr_reader :client

      def initialize
        @params = {
          site:            'https://jira.xxx.xx:443',
          context_path:    '',
          username:        ENV.fetch('JIRA_USERNAME', nil),
          password:        ENV.fetch('JIRA_USER_TOKEN', nil),
          auth_type:       :basic,
          use_ssl:          true,
          ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE
        }
        @client = JIRA::Client.new(@params)
      end

      def find_project()
        client.Project.find((ENV.fetch('JIRA_PROJECT_ID', nil)))
      rescue JIRA::HTTPError => e
        puts 'Error while finding project'
        puts e.response.code
        puts e.response.message
      end
    end
  end
end


  • The code written above works fine if I write it inside a file called test.rb and execute it with the commands ruby test.rb OR bundle exec ruby test.rb. The output that I get in this approach is as below..
$ ruby test.rb
For a better Pry experience on Windows, please use ansicon:
 https://github.com/adoxa/ansicon
If you use an alternative to ansicon and dont want to see this warning again,
you can add "Pry.config.windows_console_warning = false" to your pryrc.

C:/Users/User_Name/Documents/test.rb:343 :

   338:   use_ssl: true,
   339:   ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE
   340: }
   341:
   342: client = JIRA::Client.new(options)
=> 343: binding.pry

[1] pry(main)> client.Project.find('<<ID>>')
=> #<JIRA::Resource::Project:0x000002bc4356f660
@attrs=
 {"key"=>"<<ID>>",
  "expand"=>"description,lead,url,projectKeys",
  "self"=>"https://jira.xxx.xxx.xx/rest/api/2/project/<<ID>>",
  "id"=>"<<ID>>",
  "description"=>"",
  "lead"=>
  • When I try to execute the same snippet of code but using the policies file... it gives me the following error.

[4] pry(#<Test::Jira::Connection>)> client.Project.find('<<id>>') JIRA::HTTPError: Not Found from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/jira-ruby-2.2.0/lib/jira/request_client.rb:13:in request'
`

  • I am currently uncertain of why the issue is present only when I run the code using a policies file and not the standalone .rb file.

  • I have all the envand proxies setup, and I can get the data using the API call using Postman.

image

  • STRUCTURE OF THE POLICIES FILE

image

Any help would be great!

Thank you.

@Sachin796
Copy link
Author

Sachin796 commented Mar 8, 2023

Hi,
Can anyone let me know if they can help out with the bug that I am facing if they have experienced the same.

Thanks.

@Sachin796
Copy link
Author

Hi,
Can anyone let me know if they can help out with the bug.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant