1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 from mozbuild
.vendor
.moz_yaml
import load_moz_yaml
6 from mozlint
import result
7 from mozlint
.pathutils
import expand_exclusions
10 class UpdatebotValidator
:
11 def lint_file(self
, path
, **kwargs
):
12 if not kwargs
.get("testing", False) and not path
.endswith("moz.yaml"):
13 # When testing, process all files provided
15 if not kwargs
.get("testing", False) and "test/files/updatebot" in path
:
16 # When not testing, ignore the test files
20 yaml
= load_moz_yaml(path
)
22 if "vendoring" in yaml
and yaml
["vendoring"].get("flavor", None) == "rust":
23 yaml_revision
= yaml
["origin"]["revision"]
25 with
open("Cargo.lock", "r") as f
:
27 if yaml_revision
in line
:
30 return f
"Revision {yaml_revision} specified in {path} wasn't found in Cargo.lock"
33 except Exception as e
:
34 return f
"Could not load {path} according to schema in moz_yaml.py: {e}"
37 def lint(paths
, config
, **lintargs
):
38 # expand_exclusions expects a list, and will convert a string
39 # into it if it doesn't receive one
40 if not isinstance(paths
, list):
44 files
= list(expand_exclusions(paths
, config
, lintargs
["root"]))
46 m
= UpdatebotValidator()
48 message
= m
.lint_file(f
, **lintargs
)
50 errors
.append(result
.from_config(config
, path
=f
, message
=message
))