<commit_before>#
# Author:: <NAME> (<<EMAIL>>)
# Copyright:: Copyright (c) 2013 <NAME>.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# require 'chef/knife'

class Chef
  class Knife
    module GithubBase

      def self.included(includer)
        includer.class_eval do

          deps do
            require 'chef/mixin/shell_out'
            require 'mixlib/versioning'
          end

          option :github_url,
                 :long => "--github_url URL",
                 :description => "URL of the github enterprise appliance"

          option :github_organizations,
                 :long => "--github_org ORG:ORG",
                 :description => "Lookup chef cookbooks in this colon-separated list of organizations",
                 :proc => lambda { |o| o.split(":") }

          option :github_link,
                 :long => "--github_link TYPE",
                 :description => "Link type: ssh, http, git (dafault: ssh)"

          option :github_api_version,
                 :long => "--github_api_ver VERSION",
                 :description => "Version number of the API (default: v3)"

          option :github_ssl_verify_mode,
                 :long => "--github_ssl_verify_mode",
                 :description => "SSL verify mode: verify_peer, verify_none (default: verify_peer)",
                 :boolean => true

          option :github_cache,
                 :long => "--github_cache MIN",
                 :description => "Max life-time for local cache files in minutes (default: 900)"

          option :github_tmp,
                 :long => "--github_tmp PATH",
                 :description => "A path where temporary files for the diff function will be made default: /tmp/gitdiff)"

          def validate_base_options
            unless locate_config_value('github_url')
              ui.error "Github URL not specified"
              exit 1
            end
            unless locate_config_value('github_organizations')
              ui.error "Github organization(s) not specified"
              exit 1
            end

            @github_url             = locate_config_value("github_url")
            @github_organizations   = locate_config_value("github_organizations")
            @github_cache           = (locate_config_value("github_cache") || 900).to_i
            @github_link            = locate_config_value("github_link") || 'ssh'
            @github_api_version     = locate_config_value("github_api_version") || 'v3'
            @github_ssl_verify_mode = locate_config_value("github_ssl_verify_mode") || 'verify_peer'
            @github_tmp             = locate_config_value("github_tmp") || '/var/tmp/gitdiff'
            @github_tmp             = "#{@github_tmp}#{Process.pid}"
          end

          def display_debug_info
            Chef::Log.debug("github_url: " + @github_url.to_s)
            Chef::Log.debug("github_org: " + @github_organizations.to_s)
            Chef::Log.debug("github_api: " + @github_api_version.to_s)
            Chef::Log.debug("github_link: " + @github_link.to_s)
            Chef::Log.debug("github_cache: " + @github_cache.to_s)
            Chef::Log.debug("github_ssl_mode: " + @github_ssl_verify_mode.to_s)
          end

          def locate_config_value(key)
            key = key.to_sym
            config[key] || Chef::Config[:knife][key]
          end

          def get_github_link(object)
            link = locate_config_value('github_link')
            git_link = case link
              when 'ssh' then 'ssh_url'
              when 'http' then 'clone_url'
              when 'https' then 'clone_url'
              when 'svn' then 'svn_url'
              when 'html' then 'html_url'
              when 'git' then 'git_url'
              else 'ssh_url'
            end
            if object.nil? || object.empty?
              return git_link
            else
              return object[git_link]
            end
          end

          def get_all_repos(orgs)
            # Parse every org and merge all into one hash
            repos = {}
            orgs.each do |org|
              get_repos(org).each { |repo| name = repo['name'] ; repos["#{name}"] = repo } 
            end
            repos
          end<commit_msg>would like to retire the other function because this name is more meaning full and the other funtion is working incorrect<commit_after>#
# Author:: <NAME> (<<EMAIL>>)
# Copyright:: Copyright (c) 2013 <NAME>.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# require 'chef/knife'

class Chef
  class Knife
    module GithubBase

      def self.included(includer)
        includer.class_eval do

          deps do
            require 'chef/mixin/shell_out'
            require 'mixlib/versioning'
          end

          option :github_url,
                 :long => "--github_url URL",
                 :description => "URL of the github enterprise appliance"

          option :github_organizations,
                 :long => "--github_org ORG:ORG",
                 :description => "Lookup chef cookbooks in this colon-separated list of organizations",
                 :proc => lambda { |o| o.split(":") }

          option :github_link,
                 :long => "--github_link TYPE",
                 :description => "Link type: ssh, http, git (dafault: ssh)"

          option :github_api_version,
                 :long => "--github_api_ver VERSION",
                 :description => "Version number of the API (default: v3)"

          option :github_ssl_verify_mode,
                 :long => "--github_ssl_verify_mode",
                 :description => "SSL verify mode: verify_peer, verify_none (default: verify_peer)",
                 :boolean => true

          option :github_cache,
                 :long => "--github_cache MIN",
                 :description => "Max life-time for local cache files in minutes (default: 900)"

          option :github_tmp,
                 :long => "--github_tmp PATH",
                 :description => "A path where temporary files for the diff function will be made default: /tmp/gitdiff)"

          def validate_base_options
            unless locate_config_value('github_url')
              ui.error "Github URL not specified"
              exit 1
            end
            unless locate_config_value('github_organizations')
              ui.error "Github organization(s) not specified"
              exit 1
            end

            @github_url             = locate_config_value("github_url")
            @github_organizations   = locate_config_value("github_organizations")
            @github_cache           = (locate_config_value("github_cache") || 900).to_i
            @github_link            = locate_config_value("github_link") || 'ssh'
            @github_api_version     = locate_config_value("github_api_version") || 'v3'
            @github_ssl_verify_mode = locate_config_value("github_ssl_verify_mode") || 'verify_peer'
            @github_tmp             = locate_config_value("github_tmp") || '/var/tmp/gitdiff'
            @github_tmp             = "#{@github_tmp}#{Process.pid}"
          end

          def display_debug_info
            Chef::Log.debug("github_url: " + @github_url.to_s)
            Chef::Log.debug("github_org: " + @github_organizations.to_s)
            Chef::Log.debug("github_api: " + @github_api_version.to_s)
            Chef::Log.debug("github_link: " + @github_link.to_s)
            Chef::Log.debug("github_cache: " + @github_cache.to_s)
            Chef::Log.debug("github_ssl_mode: " + @github_ssl_verify_mode.to_s)
          end

          def locate_config_value(key)
            key = key.to_sym
            config[key] || Chef::Config[:knife][key]
          end

          def  get_repo_clone_link
            link = locate_config_value('github_link')
            repo_link = case link
              when 'ssh' then 'ssh_url'
              when 'http' then 'clone_url'
              when 'https' then 'clone_url'
              when 'svn' then 'svn_url'
              when 'html' then 'html_url'
              when 'git' then 'git_url'
              else 'ssh_url'
            end
            return repo_link
          end

          def get_github_link(object)
            link = locate_config_value('github_link')
            git_link = case link
              when 'ssh' then 'ssh_url'
              when 'http' then 'clone_url'
              when 'https' then 'clone_url'
              when 'svn' then 'svn_url'
              when 'html' then 'html_url'
              when 'git' then 'git_url'
              else 'ssh_url'
            end
            if object.nil? || object.empty?
              return git_link
            else
              return object[git_link]
            end
          end

          def get_all_repos(orgs)
            # Parse every org and merge all into one hash
            repos = {}
            orgs.each do |org|
              get_repos(org).each { |repo| name = repo['name'] ; repos["#{name}"] = repo } 
            end
            repos
          end
{'fraction_non_alphanumeric': 0.09686666007709796, 'fraction_numerical': 0.003953741227636651, 'mean_word_length': 1.8744318181818183, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2203483', 'n_tokens_mistral': 2799, 'n_tokens_neox': 2702, 'n_words': 760}