summaryrefslogtreecommitdiffstats
path: root/tools/lint/updatebot
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:44:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:44:51 +0000
commit9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /tools/lint/updatebot
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/lint/updatebot')
-rw-r--r--tools/lint/updatebot/__init__.py3
-rw-r--r--tools/lint/updatebot/validate_yaml.py52
2 files changed, 55 insertions, 0 deletions
diff --git a/tools/lint/updatebot/__init__.py b/tools/lint/updatebot/__init__.py
new file mode 100644
index 0000000000..c580d191c1
--- /dev/null
+++ b/tools/lint/updatebot/__init__.py
@@ -0,0 +1,3 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
diff --git a/tools/lint/updatebot/validate_yaml.py b/tools/lint/updatebot/validate_yaml.py
new file mode 100644
index 0000000000..802a9033fa
--- /dev/null
+++ b/tools/lint/updatebot/validate_yaml.py
@@ -0,0 +1,52 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+from mozbuild.vendor.moz_yaml import load_moz_yaml
+from mozlint import result
+from mozlint.pathutils import expand_exclusions
+
+
+class UpdatebotValidator:
+ def lint_file(self, path, **kwargs):
+ if not kwargs.get("testing", False) and not path.endswith("moz.yaml"):
+ # When testing, process all files provided
+ return None
+ if not kwargs.get("testing", False) and "test/files/updatebot" in path:
+ # When not testing, ignore the test files
+ return None
+
+ try:
+ yaml = load_moz_yaml(path)
+
+ if "vendoring" in yaml and yaml["vendoring"].get("flavor", None) == "rust":
+ yaml_revision = yaml["origin"]["revision"]
+
+ with open("Cargo.lock", "r") as f:
+ for line in f:
+ if yaml_revision in line:
+ return None
+
+ return f"Revision {yaml_revision} specified in {path} wasn't found in Cargo.lock"
+
+ return None
+ except Exception as e:
+ return f"Could not load {path} according to schema in moz_yaml.py: {e}"
+
+
+def lint(paths, config, **lintargs):
+ # expand_exclusions expects a list, and will convert a string
+ # into it if it doesn't receive one
+ if not isinstance(paths, list):
+ paths = [paths]
+
+ errors = []
+ files = list(expand_exclusions(paths, config, lintargs["root"]))
+
+ m = UpdatebotValidator()
+ for f in files:
+ message = m.lint_file(f, **lintargs)
+ if message:
+ errors.append(result.from_config(config, path=f, message=message))
+
+ return errors