<commit_before># frozen_string_literal: true

# Copyright 2015-2017, the Linux Foundation, IDA, and the
# CII Best Practices badge contributors
# SPDX-License-Identifier: MIT

# rubocop:disable Metrics/BlockLength

# The priority is based upon order of creation:
# first created -> highest priority.
# See how all your routes lay out with "rake routes".

# This regex defines all legal locale values:
LEGAL_LOCALE = /(?:#{I18n.available_locales.join("|")})/.freeze

# This regex is used to verify criteria levels in routes:
VALID_CRITERIA_LEVEL = /[0-2]/.freeze

# Confirm that number-only id is provided
VALID_ID = /[1-9][0-9]*/.freeze

# Valid values for static badge display
VALID_STATIC_VALUE = /0|[1-9]{1,2}|passing|silver|gold/.freeze

Rails.application.routes.draw do
  # First, handle routing of special cases.
  # Warning: Routes that don't take a :locale value must include a
  # "skip_before_action :redir_missing_locale ..." in their controller.

  # The "robots.txt" file is always at the root of the
  # document tree and has no locale. Handle it specially.
  get '/robots.txt' => 'static_pages#robots',
      defaults: { format: 'text' }, as: :robots

  # The /projects/NUMBER/badge image route needs speed and never uses a
  # locale. Perhaps most importantly, badge images need to have
  # a single canonical name so that the CDN caches will work correctly.
  # If we use a single canonical name for a badge image, we can then
  # change or invalidate a single CDN cache to update a badge image.
  # If we had different routes for each locale, there'd be much
  # more work to change or invalidate them, with no purpose.
  # Therefore, instead of redirecting the badge image to a locale if
  # one is not listed, we do *NOT* support locale URLs in this case.
  get '/projects/:id/badge' => 'projects#badge',
      defaults: { format: 'svg' }

  # The /badge_static/:value route needs speed and never uses a locale.
  # Beware: This route produces a result unconnected to a project's status.
  # Do NOT use this route on a project's README.md page!
  get '/badge_static/:value' => 'badge_static#show',
      constraints: { value: VALID_STATIC_VALUE },
      defaults: { format: 'svg' }

  # These routes never use locales, so that the cache is shared across locales.
  get '/project_stats/total_projects', to: 'project_stats#total_projects',
    as: 'total_projects_project_stats',
    constraints: ->(req) { req.format == :json }
  get '/project_stats/nontrivial_projects',
      to: 'project_stats#nontrivial_projects',
      as: 'nontrivial_projects_project_stats',
      constraints: ->(req) { req.format == :json }<commit_msg>Check ID in route get /projects/:id/badge<commit_after># frozen_string_literal: true

# Copyright 2015-2017, the Linux Foundation, IDA, and the
# CII Best Practices badge contributors
# SPDX-License-Identifier: MIT

# rubocop:disable Metrics/BlockLength

# The priority is based upon order of creation:
# first created -> highest priority.
# See how all your routes lay out with "rake routes".

# This regex defines all legal locale values:
LEGAL_LOCALE = /(?:#{I18n.available_locales.join("|")})/.freeze

# This regex is used to verify criteria levels in routes:
VALID_CRITERIA_LEVEL = /[0-2]/.freeze

# Confirm that number-only id is provided
VALID_ID = /[1-9][0-9]*/.freeze

# Valid values for static badge display
VALID_STATIC_VALUE = /0|[1-9]{1,2}|passing|silver|gold/.freeze

Rails.application.routes.draw do
  # First, handle routing of special cases.
  # Warning: Routes that don't take a :locale value must include a
  # "skip_before_action :redir_missing_locale ..." in their controller.

  # The "robots.txt" file is always at the root of the
  # document tree and has no locale. Handle it specially.
  get '/robots.txt' => 'static_pages#robots',
      defaults: { format: 'text' }, as: :robots

  # The /projects/NUMBER/badge image route needs speed and never uses a
  # locale. Perhaps most importantly, badge images need to have
  # a single canonical name so that the CDN caches will work correctly.
  # If we use a single canonical name for a badge image, we can then
  # change or invalidate a single CDN cache to update a badge image.
  # If we had different routes for each locale, there'd be much
  # more work to change or invalidate them, with no purpose.
  # Therefore, instead of redirecting the badge image to a locale if
  # one is not listed, we do *NOT* support locale URLs in this case.
  get '/projects/:id/badge' => 'projects#badge',
      constraints: { id: VALID_ID },
      defaults: { format: 'svg' }

  # The /badge_static/:value route needs speed and never uses a locale.
  # Beware: This route produces a result unconnected to a project's status.
  # Do NOT use this route on a project's README.md page!
  get '/badge_static/:value' => 'badge_static#show',
      constraints: { value: VALID_STATIC_VALUE },
      defaults: { format: 'svg' }

  # These routes never use locales, so that the cache is shared across locales.
  get '/project_stats/total_projects', to: 'project_stats#total_projects',
    as: 'total_projects_project_stats',
    constraints: ->(req) { req.format == :json }
  get '/project_stats/nontrivial_projects',
      to: 'project_stats#nontrivial_projects',
      as: 'nontrivial_projects_project_stats',
      constraints: ->(req) { req.format == :json }
{'fraction_non_alphanumeric': 0.09908565030789326, 'fraction_numerical': 0.007837283075200598, 'mean_word_length': 3.9084249084249083, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '3550372', 'n_tokens_mistral': 1650, 'n_tokens_neox': 1611, 'n_words': 630}