Skip to content

Commit 50ab70e

Browse files
authored
Check path is supported and not 3rd party before sending a warning, fixes #200 (#201)
1 parent 8f1ee56 commit 50ab70e

File tree

7 files changed

+123
-21
lines changed

7 files changed

+123
-21
lines changed

backend/code_coverage_backend/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import structlog
77
from flask import abort
88

9-
from code_coverage_backend.config import COVERAGE_EXTENSIONS
109
from code_coverage_backend.gcp import load_cache
1110
from code_coverage_backend.report import DEFAULT_FILTER
11+
from code_coverage_tools import COVERAGE_EXTENSIONS
1212

1313
DEFAULT_REPOSITORY = "mozilla-central"
1414
logger = structlog.get_logger(__name__)

backend/code_coverage_backend/config.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,3 @@
77

88
PROJECT_NAME = "code-coverage-backend"
99
APP_NAME = "code_coverage_backend"
10-
COVERAGE_EXTENSIONS = [
11-
# C
12-
"c",
13-
"h",
14-
# C++
15-
"cpp",
16-
"cc",
17-
"cxx",
18-
"hh",
19-
"hpp",
20-
"hxx",
21-
# JavaScript
22-
"js",
23-
"jsm",
24-
"xul",
25-
"xml",
26-
"html",
27-
"xhtml",
28-
]

backend/tests/test_coverage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def test_coverage_supported_extensions_api(client):
2323
"hxx",
2424
"js",
2525
"jsm",
26+
"rs",
2627
"xul",
2728
"xml",
2829
"html",

bot/code_coverage_bot/phabricator.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3+
import os
34
import re
45

56
import structlog
@@ -9,6 +10,7 @@
910

1011
from code_coverage_bot import hgmo
1112
from code_coverage_bot.secrets import secrets
13+
from code_coverage_tools import COVERAGE_EXTENSIONS
1214

1315
logger = structlog.get_logger(__name__)
1416

@@ -29,6 +31,16 @@ def __init__(self, repo_dir, revision):
2931
self.repo_dir = repo_dir
3032
self.revision = revision
3133

34+
# Read third party exclusion lists from repo
35+
third_parties = os.path.join(
36+
self.repo_dir, "tools/rewriting/ThirdPartyPaths.txt"
37+
)
38+
if os.path.exists(third_parties):
39+
self.third_parties = [line.rstrip() for line in open(third_parties)]
40+
else:
41+
self.third_parties = []
42+
logger.warn("Missing third party exclusion list", path=third_parties)
43+
3244
def _find_coverage(self, report, path):
3345
"""
3446
Find coverage value in a covdir report
@@ -38,7 +50,15 @@ def _find_coverage(self, report, path):
3850
parts = path.split("/")
3951
for part in filter(None, parts):
4052
if part not in report["children"]:
41-
logger.warn("Path {} not found in report".format(path))
53+
# Only send warning for non 3rd party + supported extensions
54+
if self.is_third_party(path):
55+
logger.info("Path not found in report for third party", path=path)
56+
elif not self.is_supported_extension(path):
57+
logger.info(
58+
"Path not found in report for unsupported extension", path=path
59+
)
60+
else:
61+
logger.warn("Path not found in report", path=path)
4262
return
4363
report = report["children"][part]
4464

@@ -95,6 +115,24 @@ def _apply_coverage_map(self, annotate, coverage_map):
95115

96116
return phab_coverage_data
97117

118+
def is_third_party(self, path):
119+
"""
120+
Check a file against known list of third party paths
121+
"""
122+
for third_party in self.third_parties:
123+
if path.startswith(third_party):
124+
return True
125+
return False
126+
127+
def is_supported_extension(self, path):
128+
"""
129+
Check a file has a supported extension
130+
"""
131+
_, ext = os.path.splitext(path)
132+
if not ext:
133+
return False
134+
return ext[1:] in COVERAGE_EXTENSIONS
135+
98136
def generate(self, report, changesets):
99137
results = {}
100138

bot/tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def copy_pushlog_database(remote, local):
2525

2626
def add_file(hg, repo_dir, name, contents):
2727
path = os.path.join(repo_dir, name)
28+
os.makedirs(os.path.dirname(path), exist_ok=True)
2829

2930
with open(path, "w") as f:
3031
f.write(contents)

bot/tests/test_phabricator.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,61 @@ def test_backout_removed_file(mock_secrets, fake_hg_repo):
317317
1: {"file": {"coverage": "NUCCCCU", "lines_added": 7, "lines_covered": 5}},
318318
2: {},
319319
}
320+
321+
322+
def test_third_party(mock_secrets, fake_hg_repo):
323+
hg, local, remote = fake_hg_repo
324+
325+
add_file(hg, local, "tools/rewriting/ThirdPartyPaths.txt", "third_party\nsome/path")
326+
revision = commit(hg, 1)
327+
328+
phabricator = PhabricatorUploader(local, revision)
329+
330+
assert phabricator.third_parties == ["third_party", "some/path"]
331+
332+
assert phabricator.is_third_party("js/src/xx.cpp") is False
333+
assert phabricator.is_third_party("dom/media/yyy.h") is False
334+
assert phabricator.is_third_party("third_party/test.cpp") is True
335+
assert phabricator.is_third_party("some/test.cpp") is False
336+
assert phabricator.is_third_party("some/path/test.cpp") is True
337+
338+
339+
def test_supported_extensions(mock_secrets, fake_hg_repo):
340+
hg, local, remote = fake_hg_repo
341+
342+
add_file(hg, local, "file", "1\n2\n3\n4\n5\n6\n7\n")
343+
revision = commit(hg, 1)
344+
345+
phabricator = PhabricatorUploader(local, revision)
346+
347+
assert phabricator.is_supported_extension("README") is False
348+
assert phabricator.is_supported_extension("requirements.txt") is False
349+
assert phabricator.is_supported_extension("tools/Cargo.toml") is False
350+
assert phabricator.is_supported_extension("tools/Cargo.lock") is False
351+
assert phabricator.is_supported_extension("dom/feature.idl") is False
352+
assert phabricator.is_supported_extension("dom/feature.webidl") is False
353+
assert phabricator.is_supported_extension("xpcom/moz.build") is False
354+
assert phabricator.is_supported_extension("payload.json") is False
355+
assert phabricator.is_supported_extension("inline.patch") is False
356+
assert phabricator.is_supported_extension("README.mozilla") is False
357+
assert phabricator.is_supported_extension("config.yml") is False
358+
assert phabricator.is_supported_extension("config.yaml") is False
359+
assert phabricator.is_supported_extension("config.ini") is False
360+
assert phabricator.is_supported_extension("tooling.py") is False
361+
362+
assert phabricator.is_supported_extension("test.cpp") is True
363+
assert phabricator.is_supported_extension("some/path/to/test.cpp") is True
364+
assert phabricator.is_supported_extension("xxxYYY.h") is True
365+
assert phabricator.is_supported_extension("test.c") is True
366+
assert phabricator.is_supported_extension("test.cc") is True
367+
assert phabricator.is_supported_extension("test.cxx") is True
368+
assert phabricator.is_supported_extension("test.hh") is True
369+
assert phabricator.is_supported_extension("test.hpp") is True
370+
assert phabricator.is_supported_extension("test.hxx") is True
371+
assert phabricator.is_supported_extension("test.js") is True
372+
assert phabricator.is_supported_extension("test.jsm") is True
373+
assert phabricator.is_supported_extension("test.xul") is True
374+
assert phabricator.is_supported_extension("test.xml") is True
375+
assert phabricator.is_supported_extension("test.html") is True
376+
assert phabricator.is_supported_extension("test.xhtml") is True
377+
assert phabricator.is_supported_extension("test.rs") is True

tools/code_coverage_tools/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
3+
COVERAGE_EXTENSIONS = [
4+
# C
5+
"c",
6+
"h",
7+
# C++
8+
"cpp",
9+
"cc",
10+
"cxx",
11+
"hh",
12+
"hpp",
13+
"hxx",
14+
# JavaScript
15+
"js",
16+
"jsm",
17+
"xul",
18+
"xml",
19+
"html",
20+
"xhtml",
21+
# Rust
22+
"rs",
23+
]

0 commit comments

Comments
 (0)