Skip to content

Commit

Permalink
Merge pull request #28 from salesforce/lint
Browse files Browse the repository at this point in the history
lint
  • Loading branch information
vswamidass-sfdc authored May 2, 2024
2 parents 6300eee + 82e3f5f commit e9e3ceb
Show file tree
Hide file tree
Showing 161 changed files with 416 additions and 87 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

Expand Down
2 changes: 2 additions & 0 deletions app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationCable
class Channel < ActionCable::Channel::Base
end
Expand Down
2 changes: 2 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationCable
class Connection < ActionCable::Connection::Base
end
Expand Down
12 changes: 8 additions & 4 deletions app/controllers/admin/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
class Admin::DashboardController < ApplicationController
before_action :current_user_is_admin?
# frozen_string_literal: true

def index
# admin dashboard view
module Admin
class DashboardController < ApplicationController
before_action :current_user_is_admin?

def index
# admin dashboard view
end
end
end
10 changes: 8 additions & 2 deletions app/controllers/api/v1/documents_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
class Api::V1::DocumentsController < BaseDocumentsController
skip_before_action :verify_authenticity_token
# frozen_string_literal: true

module Api
module V1
class DocumentsController < BaseDocumentsController
skip_before_action :verify_authenticity_token
end
end
end
10 changes: 8 additions & 2 deletions app/controllers/api/v1/libraries_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
class Api::V1::LibrariesController < BaseLibrariesController
skip_before_action :verify_authenticity_token, only: :create
# frozen_string_literal: true

module Api
module V1
class LibrariesController < BaseLibrariesController
skip_before_action :verify_authenticity_token, only: :create
end
end
end
10 changes: 8 additions & 2 deletions app/controllers/api/v1/questions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
class Api::V1::QuestionsController < BaseQuestionsController
skip_before_action :verify_authenticity_token, only: :create
# frozen_string_literal: true

module Api
module V1
class QuestionsController < BaseQuestionsController
skip_before_action :verify_authenticity_token, only: :create
end
end
end
2 changes: 2 additions & 0 deletions app/controllers/api_tokens_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApiTokensController < ApplicationController
before_action :set_api_token, only: %i[show edit update destroy]

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
include Pundit::Authorization

Expand Down
14 changes: 5 additions & 9 deletions app/controllers/base_documents_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class BaseDocumentsController < ApplicationController
helper_method :can_manage_documents?
before_action :set_document, only: %i[show edit update]
Expand All @@ -21,9 +23,7 @@ def index
@documents = @documents.where(library_id: params[:library_id])
end

if params[:contains].present?
@documents = @documents.search_by_title_and_document(params[:contains])
end
@documents = @documents.search_by_title_and_document(params[:contains]) if params[:contains].present?
@documents = @documents.page(params[:page])
end

Expand All @@ -45,9 +45,7 @@ def update

respond_to do |format|
if @document.update(params)
if @document.previous_changes.include?('check_hash')
EmbedDocumentJob.set(priority: 5).perform_later(@document.id)
end
EmbedDocumentJob.set(priority: 5).perform_later(@document.id) if @document.previous_changes.include?('check_hash')

format.html do
redirect_to document_url(@document), notice: 'Document was successfully updated.'
Expand Down Expand Up @@ -89,9 +87,7 @@ def create
total_jobs = Delayed::Job.count
delay_seconds = total_jobs * 3 # 3 second delay per job in the queue

if @document.previous_changes.include?('check_hash')
EmbedDocumentJob.set(priority: 5, wait: delay_seconds.seconds).perform_later(@document.id)
end
EmbedDocumentJob.set(priority: 5, wait: delay_seconds.seconds).perform_later(@document.id) if @document.previous_changes.include?('check_hash')

format.html do
redirect_to document_url(@document), notice: 'Document was successfully created.'
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/base_libraries_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class BaseLibrariesController < ApplicationController
before_action :set_library, only: %i[show edit update destroy]

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/base_questions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class BaseQuestionsController < ApplicationController
before_action :set_question, only: %i[show edit update destroy]
include NeighborConcern
Expand Down
28 changes: 14 additions & 14 deletions app/controllers/concerns/gpt_concern.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'net/http'
require 'httparty'
require 'uri'
Expand Down Expand Up @@ -29,7 +31,7 @@ def get_generation(prompt)
end

def call_openai_embedding(input)
access_token = ENV['OPENAI_API_KEY']
access_token = ENV.fetch('OPENAI_API_KEY', nil)
endpoint_url = 'https://api.openai.com/v1/embeddings'
headers = {
'Authorization' => "Bearer #{access_token}",
Expand All @@ -54,7 +56,7 @@ def call_openai_embedding(input)
end

def call_openai_generation(prompt)
access_token = ENV['OPENAI_API_KEY']
access_token = ENV.fetch('OPENAI_API_KEY', nil)
endpoint_url = 'https://api.openai.com/v1/chat/completions'
headers = {
'Authorization' => "Bearer #{access_token}",
Expand All @@ -64,18 +66,16 @@ def call_openai_generation(prompt)
messages: [
{ role: 'user', content: prompt }
],
model: ENV['EGPT_GEN_MODEL'] || 'gpt-3.5-turbo-16k',
model: ENV['EGPT_GEN_MODEL'] || 'gpt-3.5-turbo-16k'
# Add additional parameters as required by OpenAI
}

response = HTTParty.post(endpoint_url, body: body.to_json, headers:)
if response.code == 200
return JSON.parse(response.body)['choices'].first['message']['content']
else
# Handle error
puts "Error calling OpenAI API for generation: #{response.code} - #{response.message}"
''
end
return JSON.parse(response.body)['choices'].first['message']['content'] if response.code == 200

# Handle error
puts "Error calling OpenAI API for generation: #{response.code} - #{response.message}"
''
end

def call_salesforce_connect_gpt_embedding(input)
Expand Down Expand Up @@ -155,8 +155,8 @@ def call_salesforce_connect_gpt_generation(prompt)
def get_salesforce_connect_oauth_token
encoded_client_id = URI.encode_www_form_component(ENV['SALESFORCE_CONNECT_CLIENT_ID'] || '')
encoded_client_secret = URI.encode_www_form_component(ENV['SALESFORCE_CONNECT_CLIENT_SECRET'] || '')
encoded_username = ENV['SALESFORCE_CONNECT_USERNAME']
encoded_password = ENV['SALESFORCE_CONNECT_PASSWORD']
encoded_username = ENV.fetch('SALESFORCE_CONNECT_USERNAME', nil)
encoded_password = ENV.fetch('SALESFORCE_CONNECT_PASSWORD', nil)

token_request_data = {
grant_type: 'password',
Expand All @@ -166,8 +166,8 @@ def get_salesforce_connect_oauth_token
password: encoded_password
}

token_request_body = URI.encode_www_form(token_request_data)
oauth_url = ENV['SALESFORCE_CONNECT_ORG_URL'] + '/services/oauth2/token'
URI.encode_www_form(token_request_data)
oauth_url = "#{ENV.fetch('SALESFORCE_CONNECT_ORG_URL', nil)}/services/oauth2/token"

begin
uri = URI.parse(oauth_url)
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/concerns/hashable.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Hashable
extend ActiveSupport::Concern

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/concerns/neighbor_concern.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module NeighborConcern
extend ActiveSupport::Concern

Expand Down
6 changes: 4 additions & 2 deletions app/controllers/concerns/salesforce_gpt_concern.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'net/http'
require 'httparty'

Expand Down Expand Up @@ -107,8 +109,8 @@ def get_salesforce_connect_oauth_token
password: encoded_password
}

token_request_body = URI.encode_www_form(token_request_data)
oauth_url = ENV.fetch('SALESFORCE_CONNECT_ORG_URL', nil) + '/services/oauth2/token'
URI.encode_www_form(token_request_data)
oauth_url = "#{ENV.fetch('SALESFORCE_CONNECT_ORG_URL', nil)}/services/oauth2/token"

begin
uri = URI.parse(oauth_url)
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/delayed_jobs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class DelayedJobsController < ApplicationController
before_action :set_job, only: [:destroy]

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/documents_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class DocumentsController < BaseDocumentsController
include NeighborConcern

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/libraries_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class LibrariesController < BaseLibrariesController
# GET /libraries/new
def new
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/questions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class QuestionsController < BaseQuestionsController
# GET /questions/1 or /questions/1.json
def show
Expand Down
8 changes: 5 additions & 3 deletions app/controllers/saml_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class SamlController < ApplicationController
skip_before_action :verify_authenticity_token
def init
Expand All @@ -11,12 +13,12 @@ def lookup_or_create_user_by_email(email)

if user.nil?
# Create a user
user = User.new(email: email)
user = User.new(email:)
end

return nil unless user.save

puts 'Created user: ' + user.email
puts "Created user: #{user.email}"

# Failed to create user

Expand All @@ -41,7 +43,7 @@ def consume
notice = 'Login failed. Please contact an admin for help.'
end

redirect_to root_path, notice: notice
redirect_to root_path, notice:
else
redirect_to(request.create(saml_settings))
end
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class SessionsController < ApplicationController
skip_before_action :require_login

Expand All @@ -15,7 +17,7 @@ def create

def set_debug
session[:debug] = params[:debug]
redirect_to root_url, notice: 'Debug set: ' + session[:debug]
redirect_to root_url, notice: "Debug set: #{session[:debug]}"
end

def logout
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class UsersController < ApplicationController
before_action :set_user, only: %i[show edit update destroy]

Expand Down
6 changes: 5 additions & 1 deletion app/helpers/admin/dashboard_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
module Admin::DashboardHelper
# frozen_string_literal: true

module Admin
module DashboardHelper
end
end
2 changes: 2 additions & 0 deletions app/helpers/api_tokens_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module ApiTokensHelper
end
2 changes: 2 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationHelper
def full_title(page_title = '')
base_title = 'Fack'
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/delayed_jobs_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module DelayedJobsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/documents_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module DocumentsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/libraries_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module LibrariesHelper
end
6 changes: 4 additions & 2 deletions app/helpers/markdown_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'redcarpet'
# Create a custom renderer that sets a custom class for block-quotes.
class CustomRender < Redcarpet::Render::HTML
Expand All @@ -7,7 +9,7 @@ class CustomRender < Redcarpet::Render::HTML
'>' => '&gt;',
'"' => '&quot;',
"'" => '&#39;'
}
}.freeze

def escape_html(text)
text.gsub(/[&<>"']/) { |match| ESCAPE_TABLE[match] }
Expand Down Expand Up @@ -60,7 +62,7 @@ def render_markdown(text)
renderer = CustomRender.new(escape_html: true)
# renderer = Redcarpet::Render::HTML.new(hard_wrap: true)

markdown = Redcarpet::Markdown.new(renderer, extensions = {})
markdown = Redcarpet::Markdown.new(renderer, {})
markdown.render(text).html_safe
end
end
2 changes: 2 additions & 0 deletions app/helpers/questions_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module QuestionsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/sessions_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module SessionsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module UsersHelper
end
2 changes: 2 additions & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked
Expand Down
Loading

0 comments on commit e9e3ceb

Please sign in to comment.