aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix-data-service/comparison.scm12
-rw-r--r--guix-data-service/jobs/load-new-guix-revision.scm45
-rw-r--r--guix-data-service/model/lint-checker.scm68
-rw-r--r--guix-data-service/model/lint-warning.scm12
-rw-r--r--sqitch/deploy/translations_for_lint_checker_descriptions.sql40
-rw-r--r--sqitch/revert/translations_for_lint_checker_descriptions.sql7
-rw-r--r--sqitch/sqitch.plan1
-rw-r--r--sqitch/verify/translations_for_lint_checker_descriptions.sql7
8 files changed, 179 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
diff --git a/sqitch/deploy/translations_for_lint_checker_descriptions.sql b/sqitch/deploy/translations_for_lint_checker_descriptions.sql
new file mode 100644
index 0000000..3a2ed8e
--- /dev/null
+++ b/sqitch/deploy/translations_for_lint_checker_descriptions.sql
@@ -0,0 +1,40 @@
+-- Deploy guix-data-service:translations_for_lint_checker_descriptions to pg
+
+BEGIN;
+
+CREATE TABLE lint_checker_descriptions (
+ id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
+ locale varchar NOT NULL,
+ description varchar NOT NULL,
+ UNIQUE (locale, description)
+);
+
+CREATE TABLE lint_checker_description_sets (
+ id integer NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
+ description_ids integer[] NOT NULL,
+ UNIQUE (description_ids)
+);
+
+ALTER TABLE lint_checkers ADD COLUMN lint_checker_description_set_id integer REFERENCES lint_checker_description_sets(id);
+
+INSERT INTO lint_checker_descriptions(locale, description)
+SELECT DISTINCT 'en_US.utf8', description
+ FROM lint_checkers;
+
+INSERT INTO lint_checker_description_sets (description_ids)
+SELECT DISTINCT ARRAY_AGG(
+ id)
+ FROM lint_checker_descriptions
+ GROUP BY id;
+
+UPDATE lint_checkers
+ SET lint_checker_description_set_id =
+ lint_checker_description_sets.id
+ FROM lint_checker_description_sets
+ INNER JOIN lint_checker_descriptions
+ ON lint_checker_description_sets.description_ids[1] = lint_checker_descriptions.id
+ WHERE lint_checkers.description = lint_checker_descriptions.description;
+
+ALTER TABLE lint_checkers DROP COLUMN description;
+
+COMMIT;
diff --git a/sqitch/revert/translations_for_lint_checker_descriptions.sql b/sqitch/revert/translations_for_lint_checker_descriptions.sql
new file mode 100644
index 0000000..a310ea5
--- /dev/null
+++ b/sqitch/revert/translations_for_lint_checker_descriptions.sql
@@ -0,0 +1,7 @@
+-- Revert guix-data-service:translations_for_lint_checker_descriptions from pg
+
+BEGIN;
+
+-- XXX Add DDLs here.
+
+COMMIT;
diff --git a/sqitch/sqitch.plan b/sqitch/sqitch.plan
index cb57737..911c43b 100644
--- a/sqitch/sqitch.plan
+++ b/sqitch/sqitch.plan
@@ -59,3 +59,4 @@ load_new_guix_revision_jobs_make_commits_unique 2020-03-27T21:38:42Z Christopher
remove_odd_package_derivations 2020-04-24T20:36:06Z Christopher Baines <mail@cbaines.net> # Remove odd package derivations
build_servers_lookup_builds 2020-05-24T15:18:09Z Christopher Baines <mail@cbaines.net> # Add build_servers.lookup_builds
make_nar_urls_file_size_optional 2020-06-03T05:27:29Z Christopher Baines <mail@cbaines.net> # Make the nar_urls.file_size optional
+translations_for_lint_checker_descriptions 2020-05-22T19:49:37Z daniela <daniela@linux-ijv5> # Support translations for lint checker descriptions
diff --git a/sqitch/verify/translations_for_lint_checker_descriptions.sql b/sqitch/verify/translations_for_lint_checker_descriptions.sql
new file mode 100644
index 0000000..7736f88
--- /dev/null
+++ b/sqitch/verify/translations_for_lint_checker_descriptions.sql
@@ -0,0 +1,7 @@
+-- Verify guix-data-service:translations_for_lint_checker_descriptions on pg
+
+BEGIN;
+
+-- XXX Add verifications here.
+
+ROLLBACK;