From d59f2d7bd17c3a7695dd5101ee13a7af9e193682 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Thu, 12 Jun 2025 13:34:39 +0530 Subject: [PATCH] chore: fix cyclomatic complexity --- app/helpers/github/integration_helper.rb | 16 ++++++++-------- app/models/integrations/app.rb | 11 ++++++++--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/helpers/github/integration_helper.rb b/app/helpers/github/integration_helper.rb index ad1cb880c..b73219b66 100644 --- a/app/helpers/github/integration_helper.rb +++ b/app/helpers/github/integration_helper.rb @@ -4,15 +4,15 @@ module Github::IntegrationHelper # @param account_id [Integer] The account ID to encode in the token # @return [String, nil] The encoded JWT token or nil if client secret is missing def generate_github_token(account_id) - return if client_secret.blank? + return if github_client_secret.blank? - JWT.encode(token_payload(account_id), client_secret, 'HS256') + JWT.encode(github_token_payload(account_id), github_client_secret, 'HS256') rescue StandardError => e Rails.logger.error("Failed to generate Github token: #{e.message}") nil end - def token_payload(account_id) + def github_token_payload(account_id) { sub: account_id, iat: Time.current.to_i @@ -24,18 +24,18 @@ module Github::IntegrationHelper # @param token [String] The JWT token to verify # @return [Integer, nil] The account ID from the token or nil if invalid def verify_github_token(token) - return if token.blank? || client_secret.blank? + return if token.blank? || github_client_secret.blank? - decode_token(token, client_secret) + github_decode_token(token, github_client_secret) end private - def client_secret - @client_secret ||= GlobalConfigService.load('GITHUB_CLIENT_SECRET', nil) + def github_client_secret + @github_client_secret ||= GlobalConfigService.load('GITHUB_CLIENT_SECRET', nil) end - def decode_token(token, secret) + def github_decode_token(token, secret) JWT.decode(token, secret, true, { algorithm: 'HS256', verify_expiration: true diff --git a/app/models/integrations/app.rb b/app/models/integrations/app.rb index b8fd61827..d8bf17448 100644 --- a/app/models/integrations/app.rb +++ b/app/models/integrations/app.rb @@ -31,10 +31,15 @@ class Integrations::App params[:fields] end - # There is no way to get the account_id from the linear callback - # so we are using the generate_linear_token method to generate a token and encode it in the state parameter + # There is no way to get the account_id from the linear/github callback + # so we are using the generate token method to generate a token and encode it in the state parameter def encode_state - generate_linear_token(Current.account.id) + case params[:id] + when 'linear' + generate_linear_token(Current.account.id) + when 'github' + generate_github_token(Current.account.id) + end end def action