diff options
Diffstat (limited to 'guix-data-service')
-rw-r--r-- | guix-data-service/comparison.scm | 12 | ||||
-rw-r--r-- | guix-data-service/jobs/load-new-guix-revision.scm | 45 | ||||
-rw-r--r-- | guix-data-service/model/lint-checker.scm | 68 | ||||
-rw-r--r-- | guix-data-service/model/lint-warning.scm | 12 |
4 files changed, 124 insertions, 13 deletions
diff --git a/guix-data-service/comparison.scm b/guix-data-service/comparison.scm index 3b940ac..40d10fe 100644 --- a/guix-data-service/comparison.scm +++ b/guix-data-service/comparison.scm @@ -607,7 +607,7 @@ WITH base_lint_warnings AS ( SELECT lint_warnings.id, packages.name, packages.version, lint_checkers.name AS lint_checker_name, - lint_checkers.description AS lint_checker_description, + lint_checker_descriptions.description AS lint_checker_description, lint_checkers.network_dependent AS lint_checker_network_dependent, locations.file, locations.line, locations.column_number, lint_warning_messages.message @@ -616,6 +616,10 @@ WITH base_lint_warnings AS ( ON lint_warnings.package_id = packages.id INNER JOIN lint_checkers ON lint_warnings.lint_checker_id = lint_checkers.id + INNER JOIN lint_checker_description_sets + ON lint_checkers.lint_checker_description_set_id = lint_checker_description_sets.id + INNER JOIN lint_checker_descriptions + ON lint_checker_descriptions.id = ANY (lint_checker_description_sets.description_ids) INNER JOIN locations ON lint_warnings.location_id = locations.id INNER JOIN lint_warning_message_sets @@ -632,7 +636,7 @@ WITH base_lint_warnings AS ( SELECT lint_warnings.id, packages.name, packages.version, lint_checkers.name AS lint_checker_name, - lint_checkers.description AS lint_checker_description, + lint_checker_descriptions.description AS lint_checker_description, lint_checkers.network_dependent AS lint_checker_network_dependent, locations.file, locations.line, locations.column_number, lint_warning_messages.message @@ -641,6 +645,10 @@ WITH base_lint_warnings AS ( ON lint_warnings.package_id = packages.id INNER JOIN lint_checkers ON lint_warnings.lint_checker_id = lint_checkers.id + INNER JOIN lint_checker_description_sets + ON lint_checkers.lint_checker_description_set_id = lint_checker_description_sets.id + INNER JOIN lint_checker_descriptions + ON lint_checker_descriptions.id = ANY (lint_checker_description_sets.description_ids) INNER JOIN locations ON lint_warnings.location_id = locations.id INNER JOIN lint_warning_message_sets diff --git a/guix-data-service/jobs/load-new-guix-revision.scm b/guix-data-service/jobs/load-new-guix-revision.scm index efc2f08..34809b0 100644 --- a/guix-data-service/jobs/load-new-guix-revision.scm +++ b/guix-data-service/jobs/load-new-guix-revision.scm @@ -30,6 +30,7 @@ #:use-module (guix inferior) #:use-module (guix profiles) #:use-module (guix utils) + #:use-module (guix i18n) #:use-module (guix progress) #:use-module (guix packages) #:use-module (guix derivations) @@ -448,7 +449,8 @@ WHERE job_id = $1" (and (or (inferior-eval '(and (resolve-module '(guix lint) #:ensure #f) - (use-modules (guix lint)) + (use-modules (guix lint) + (guix i18n)) #t) inf) (begin @@ -457,10 +459,38 @@ WHERE job_id = $1" #f)) (let ((checkers (inferior-eval - '(begin + `(begin + (define (lint-descriptions-by-locale checker) + (let* ((source-locale "en_US.utf8") + (source-description + (begin + (setlocale LC_MESSAGES source-locale) + (G_ (lint-checker-description checker)))) + (descriptions-by-locale + (filter-map + (lambda (locale) + (catch 'system-error + (lambda () + (setlocale LC_MESSAGES locale)) + (lambda (key . args) + (error + (simple-format + #f + "error changing locale to ~A: ~A ~A" + locale key args)))) + (let ((description + (G_ (lint-checker-description checker)))) + (setlocale LC_MESSAGES source-locale) + (if (string=? description source-description) + #f + (cons locale description)))) + (list ,@locales)))) + (cons (cons source-locale source-description) + descriptions-by-locale))) + (map (lambda (checker) (list (lint-checker-name checker) - (lint-checker-description checker) + (lint-descriptions-by-locale checker) (if (memq checker %network-dependent-checkers) #t #f))) @@ -1163,7 +1193,14 @@ WHERE job_id = $1" (let* ((lint-checker-ids (lint-checkers->lint-checker-ids conn - (map car inferior-lint-warnings))) + (map (match-lambda + ((name descriptions-by-locale network-dependent) + (list + name + network-dependent + (lint-checker-description-data->lint-checker-description-set-id + conn descriptions-by-locale)))) + (map car inferior-lint-warnings)))) (lint-warning-ids (insert-lint-warnings conn diff --git a/guix-data-service/model/lint-checker.scm b/guix-data-service/model/lint-checker.scm index a2a10a1..181d5fd 100644 --- a/guix-data-service/model/lint-checker.scm +++ b/guix-data-service/model/lint-checker.scm @@ -23,21 +23,75 @@ #:export (lint-checkers->lint-checker-ids lint-warning-count-by-lint-checker-for-revision insert-guix-revision-lint-checkers - lint-checkers-for-revision)) + lint-checkers-for-revision + lint-checker-description-data->lint-checker-description-set-id)) (define (lint-checkers->lint-checker-ids conn lint-checkers-data) (insert-missing-data-and-return-all-ids conn "lint_checkers" - '(name description network_dependent) + '(name network_dependent lint_checker_description_set_id) lint-checkers-data)) +(define (lint-checker-description-data->lint-checker-description-ids + conn descriptions-by-locale) + (insert-missing-data-and-return-all-ids + conn + "lint_checker_descriptions" + '(locale description) + (map (match-lambda + ((locale . description) + (list locale description))) + descriptions-by-locale))) + +(define (insert-lint-checker-description-set conn lint-description-ids) + (let ((query + (string-append + "INSERT INTO lint_checker_description_sets (description_ids) VALUES " + (string-append + "('{" + (string-join + (map number->string + (sort lint-description-ids <)) + ", ") + "}')") + " RETURNING id"))) + (match (exec-query conn query) + (((id)) id)))) + +(define (lint-checker-description-data->lint-checker-description-set-id + conn + descriptions-by-locale) + (let* ((lint-checker-description-ids + (lint-checker-description-data->lint-checker-description-ids + conn + descriptions-by-locale)) + (lint-checker-description-set-id + (exec-query + conn + (string-append + "SELECT id FROM lint_checker_description_sets" + " WHERE description_ids = ARRAY[" + (string-join (map number->string + (sort lint-checker-description-ids <)) ", ") + "]")))) + (string->number + (match lint-checker-description-set-id + (((id)) id) + (() + (insert-lint-checker-description-set conn lint-checker-description-ids)))))) + + (define (lint-warning-count-by-lint-checker-for-revision conn commit-hash) (define query " -SELECT lint_checkers.name, lint_checkers.description, +SELECT lint_checkers.name, lint_checker_descriptions.description, lint_checkers.network_dependent, revision_data.count FROM lint_checkers +INNER JOIN lint_checker_description_sets + ON lint_checkers.lint_checker_description_set_id = lint_checker_description_sets.id +INNER JOIN lint_checker_descriptions + ON lint_checker_descriptions.id = ANY (lint_checker_description_sets.description_ids) INNER JOIN ( SELECT lint_checker_id, COUNT(*) FROM lint_warnings @@ -76,9 +130,13 @@ ORDER BY count DESC") (exec-query conn " -SELECT name, description, network_dependent +SELECT lint_checkers.name, lint_checker_descriptions.description, lint_checkers.network_dependent FROM lint_checkers -WHERE id IN ( +INNER JOIN lint_checker_description_sets + ON lint_checkers.lint_checker_description_set_id = lint_checker_description_sets.id +INNER JOIN lint_checker_descriptions + ON lint_checker_descriptions.id = ANY (lint_checker_description_sets.description_ids) +WHERE lint_checkers.id IN ( SELECT lint_checker_id FROM guix_revision_lint_checkers INNER JOIN guix_revisions diff --git a/guix-data-service/model/lint-warning.scm b/guix-data-service/model/lint-warning.scm index b3942a7..f22681b 100644 --- a/guix-data-service/model/lint-warning.scm +++ b/guix-data-service/model/lint-warning.scm @@ -59,13 +59,17 @@ message-query) (define query (string-append " -SELECT lint_warnings.id, lint_checkers.name, lint_checkers.description, +SELECT lint_warnings.id, lint_checkers.name, lint_checker_descriptions.description, lint_checkers.network_dependent, packages.name, packages.version, locations.file, locations.line, locations.column_number, lint_warning_messages.message FROM lint_warnings INNER JOIN lint_checkers ON lint_warnings.lint_checker_id = lint_checkers.id +INNER JOIN lint_checker_description_sets + ON lint_checkers.lint_checker_description_set_id = lint_checker_description_sets.id +INNER JOIN lint_checker_descriptions + ON lint_checker_descriptions.id = ANY (lint_checker_description_sets.description_ids) INNER JOIN packages ON lint_warnings.package_id = packages.id INNER JOIN locations @@ -116,13 +120,17 @@ INNER JOIN lint_warning_messages commit-hash name version) (define query " -SELECT lint_warnings.id, lint_checkers.name, lint_checkers.description, +SELECT lint_warnings.id, lint_checkers.name, lint_checker_descriptions.description, lint_checkers.network_dependent, locations.file, locations.line, locations.column_number, lint_warning_messages.message FROM lint_warnings INNER JOIN lint_checkers ON lint_checkers.id = lint_warnings.lint_checker_id +INNER JOIN lint_checker_description_sets + ON lint_checkers.lint_checker_description_set_id = lint_checker_description_sets.id +INNER JOIN lint_checker_descriptions + ON lint_checker_descriptions.id = ANY (lint_checker_description_sets.description_ids) INNER JOIN packages ON lint_warnings.package_id = packages.id LEFT OUTER JOIN locations |