app/models/project.rb
class Project < ApplicationRecord
has_and_belongs_to_many :users
has_many :merge_requests, dependent: :destroy
has_many :locked_branches, dependent: :delete_all
validates :name, presence: true
validates :linter, format: { with: %r{\A[^\./](?!.*(\.\.|[&|<>])).*\z},
message: "can't have pipes, dots, slashes, two dots, etc, try to use a script in your " \
'project directory' },
allow_blank: true
validate :validate_repository
def gitlab_ci?
gitlab_ci_project_url.present?
end
def jira_enabled?
jira_api_url.present? && jira_ticket_regexp.present? && jira_username.present? && jira_password.present?
end
def configuration_hash
Digest::MD5.hexdigest(linter)
end
private
def validate_repository
is_valid = URI::DEFAULT_PARSER.make_regexp =~ repository && /\A[^ ;&|]+\z/ =~ repository
errors.add(:repository, 'is not a valid URI') unless is_valid
end
end