Class: Projects::DetectRepositoryLanguagesService

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/projects/detect_repository_languages_service.rb

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from BaseService

Instance Attribute Details

#programming_languagesObject (readonly)

Returns the value of attribute programming_languages


5
6
7
# File 'app/services/projects/detect_repository_languages_service.rb', line 5

def programming_languages
  @programming_languages
end

Instance Method Details

#executeObject

rubocop: disable CodeReuse/ActiveRecord


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/projects/detect_repository_languages_service.rb', line 8

def execute
  repository_languages = project.repository_languages
  detection = Gitlab::LanguageDetection.new(repository, repository_languages)

  matching_programming_languages = ensure_programming_languages(detection)

  RepositoryLanguage.transaction do
    RepositoryLanguage.where(project_id: project.id, programming_language_id: detection.deletions).delete_all

    detection.updates.each do |update|
      RepositoryLanguage
        .where(project_id: project.id)
        .where(programming_language_id: update[:programming_language_id])
        .update_all(share: update[:share])
    end

    Gitlab::Database.bulk_insert( # rubocop:disable Gitlab/BulkInsert
      RepositoryLanguage.table_name,
      detection.insertions(matching_programming_languages)
    )

    set_detected_repository_languages
  end

  project.repository_languages.reset
end