<commit_before>module Jira
  class AuthenticationController < ApplicationController
    before_action { session[:jira] ||= {} }
    
    def initiate
      request_token = jira_client.request_token(oauth_callback: jira.jira_finalise_url)
      Rails.logger.info(request_token.inspect)

      session[:jira][:request_token] = request_token.token
      session[:jira][:request_token_secret] = request_token.secret
      
      Rails.logger.info('~~ initiate ~~')
      Rails.logger.info(session[:jira].inspect)
      
      redirect_to request_token.authorize_url
    end
    
    def finalise
      request_token = get_request_token
      return unless request_token
      
      Rails.logger.info('~~ finalise ~~')
      
      access_token = request_token.init_access_token(oauth_verifier: params[:oauth_verifier])
      current_user.jira_token = access_token.token
      current_user.jira_secret = access_token.secret
      current_user.save!
      
      if session[:jira] && (problem_id = session[:jira][:create_issue])
        problem = Problem.find(problem_id)
        issue = IssueService.create_issue(self, problem, current_user) if problem
        
        if issue
          flash[:error] = issue.errors.full_messages.join(', ') unless issue.valid?
          return redirect_to(main_app.app_problem_path(problem.app, problem))
        end
      end

      redirect user_path(current_user)
    ensure
      session[:jira] = nil
    end
    
    private
    
    def jira_client
      @jira_client ||= ErrbitJiraEngine.create_client
    end
    
    def get_request_token
      return @request_token if @request_token
      
      Rails.logger.info('~~ get_request_token ~~')
      Rails.logger.info(session[:jira].inspect)
      
      token = session[:jira][:request_token]
      secret = session[:jira][:request_token_secret]
      
      if token.present? && secret.present?
        Rails.logger.info('setting request_token..')
        @request_token = jira_client.set_request_token(token, secret)
      else
        Rails.logger.info('something is blank: #{token.blank?} && #{secret.blank?}. redirecting.')
        redirect_to jira.jira_initiate_path
      end
      
      @request_token
    end
  end
end<commit_msg>attempt string session vars<commit_after>module Jira
  class AuthenticationController < ApplicationController
    before_action { session[:jira] ||= {} }
    
    def initiate
      request_token = jira_client.request_token(oauth_callback: jira.jira_finalise_url)
      Rails.logger.info(request_token.inspect)

      session[:jira]['request_token'] = request_token.token
      session[:jira]['request_token_secret'] = request_token.secret
      
      Rails.logger.info('~~ initiate ~~')
      Rails.logger.info(session[:jira].inspect)
      
      redirect_to request_token.authorize_url
    end
    
    def finalise
      request_token = get_request_token
      return unless request_token
      
      Rails.logger.info('~~ finalise ~~')
      
      access_token = request_token.init_access_token(oauth_verifier: params[:oauth_verifier])
      current_user.jira_token = access_token.token
      current_user.jira_secret = access_token.secret
      current_user.save!
      
      if session[:jira] && (problem_id = session[:jira][:create_issue])
        problem = Problem.find(problem_id)
        issue = IssueService.create_issue(self, problem, current_user) if problem
        
        if issue
          flash[:error] = issue.errors.full_messages.join(', ') unless issue.valid?
          return redirect_to(main_app.app_problem_path(problem.app, problem))
        end
      end

      redirect user_path(current_user)
    ensure
      session[:jira] = nil
    end
    
    private
    
    def jira_client
      @jira_client ||= ErrbitJiraEngine.create_client
    end
    
    def get_request_token
      return @request_token if @request_token
      
      Rails.logger.info('~~ get_request_token ~~')
      Rails.logger.info(session[:jira].inspect)
      
      token = session[:jira]['request_token']
      secret = session[:jira]['request_token_secret']
      
      if token.present? && secret.present?
        Rails.logger.info('setting request_token..')
        @request_token = jira_client.set_request_token(token, secret)
      else
        Rails.logger.info("something is blank: #{token.blank?} && #{secret.blank?}. redirecting.")
        redirect_to jira.jira_initiate_path
      end
      
      @request_token
    end
  end
end
{'fraction_non_alphanumeric': 0.09910714285714285, 'fraction_numerical': 0.0, 'mean_word_length': 2.8168654173764907, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3228618', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1356, 'n_words': 222}