Sha256: 2ba49e7d2cef073afe8f6a47fca3f32de690ab7857fde096c6a7e4e4aa0425c7

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

require 'json'
require 'uri'
require 'io/console'

module LgPodPlugin

  class LConfig
    attr_accessor :host
    attr_accessor :base_url
    attr_accessor :project_name
    attr_accessor :access_token
    attr_accessor :refresh_token
    attr_accessor :project

    def initialize
    end

    public
    def self.get_config(git, uri)
      return nil unless uri&.host
      return nil unless LUtils.is_gitlab_uri(git, uri.hostname)
      user_id = LUserAuthInfo.get_user_id(uri.hostname)
      user_info = LSqliteDb.shared.query_user_info(user_id)
      # 用户授权 token 不存在, 提示用户输入用户名密码
      unless user_info
        user_info = GitLabAPI.get_gitlab_access_token(uri, user_id)
        return nil unless user_info
      end
      user_info = GitLabAPI.check_gitlab_access_token_valid(uri, user_info)
      return nil unless user_info
      config = LConfig.new
      config.host = uri.hostname
      config.access_token = user_info.access_token
      config.refresh_token = user_info.refresh_token
      config.base_url = LUtils.get_gitlab_base_url(git)
      config.project_name = LUtils.get_git_project_name(git)
      config.project = LSqliteDb.shared.query_project_info(config.project_name, git)
      unless config.project
        config.project = GitLabAPI.request_project_info(config.host, config.project_name, config.access_token, git)
      end
      return config
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lg_pod_plugin-1.1.6.7 lib/lg_pod_plugin/config/l_config.rb