diff --git a/contrib/buildbot/server.py b/contrib/buildbot/server.py --- a/contrib/buildbot/server.py +++ b/contrib/buildbot/server.py @@ -75,6 +75,8 @@ 'panel_data': {}, # Whether the last status check of master was green 'master_is_green': True, + # Coverage panel data + 'coverage_data': {}, } # If db_file_no_ext is not None, attempt to restore old database state @@ -768,9 +770,9 @@ phab.set_text_panel_content(17, panel_content) - def update_coverage_panel(coverage_summary): - # FIXME don't harcode the permalink but pull it from some configuration - coverage_permalink = "**[[ https://build.bitcoinabc.org/viewLog.html?buildId=lastSuccessful&buildTypeId=BitcoinABC_Master_BitcoinAbcMasterCoverage&tab=report__Root_Code_Coverage&guest=1 | HTML coverage report ]]**\n\n" + def update_coverage_panel(build_type_id, project_name, coverage_summary): + coverage_permalink = "**[[ https://build.bitcoinabc.org/viewLog.html?buildId=lastSuccessful&buildTypeId={}&tab=report__Root_Code_Coverage&guest=1 | {} coverage report ]]**\n\n".format( + build_type_id, project_name) coverage_report = "| Granularity | % hit | # hit | # total |\n" coverage_report += "| ----------- | ----- | ----- | ------- |\n" @@ -800,11 +802,15 @@ match.group('total'), ) + # Cache the coverage data for this build type + coverage_data = create_server.db['coverage_data'] + coverage_data[build_type_id] = coverage_permalink + coverage_report + # Update the coverage panel with our remarkup content - phab.set_text_panel_content(21, coverage_permalink + coverage_report) + phab.set_text_panel_content(21, "\n".join(coverage_data.values())) def handle_build_result(buildName, buildTypeId, buildResult, - buildURL, branch, buildId, buildTargetPHID, **kwargs): + buildURL, branch, buildId, buildTargetPHID, projectName, **kwargs): # Do not report build status for ignored builds if phab.getIgnoreKeyword() in buildTypeId: return SUCCESS, 200 @@ -835,7 +841,8 @@ coverage_summary = None if coverage_summary: - update_coverage_panel(coverage_summary) + update_coverage_panel( + buildTypeId, projectName, coverage_summary) # If we have a buildTargetPHID, report the status. build_target = create_server.db['diff_targets'].get( diff --git a/contrib/buildbot/test/test_endpoint_status.py b/contrib/buildbot/test/test_endpoint_status.py --- a/contrib/buildbot/test/test_endpoint_status.py +++ b/contrib/buildbot/test/test_endpoint_status.py @@ -25,7 +25,7 @@ class statusRequestData(test.mocks.fixture.MockData): def __init__(self): self.buildName = 'build-name' - self.project = 'bitcoin-abc-test' + self.projectName = 'bitcoin-abc-test' self.buildId = DEFAULT_BUILD_ID self.buildTypeId = 'build-type-id' self.buildResult = 'success' @@ -1500,6 +1500,8 @@ def test_update_coverage_panel(self): panel_id = 21 + buildTypeId = 'DummyBuildType' + projectName = 'Dummy Project' self.phab.set_text_panel_content = mock.Mock() @@ -1508,6 +1510,8 @@ def call_status(status, expected_status_code=None): data = statusRequestData() data.buildResult = status.value + data.buildTypeId = buildTypeId + data.projectName = projectName response = self.app.post( '/status', headers=self.headers, json=data) @@ -1543,6 +1547,7 @@ self.phab.set_text_panel_content.assert_not_called_with( panel_id=panel_id) + # Generate coverage report for one project self.teamcity.get_coverage_summary.return_value = \ """ Reading tracefile check-extended_combined.info @@ -1554,7 +1559,7 @@ call_status(BuildStatus.Success, expected_status_code=500) assert_panel_content( - """**[[ https://build.bitcoinabc.org/viewLog.html?buildId=lastSuccessful&buildTypeId=BitcoinABC_Master_BitcoinAbcMasterCoverage&tab=report__Root_Code_Coverage&guest=1 | HTML coverage report ]]** + """**[[ https://build.bitcoinabc.org/viewLog.html?buildId=lastSuccessful&buildTypeId=DummyBuildType&tab=report__Root_Code_Coverage&guest=1 | Dummy Project coverage report ]]** | Granularity | % hit | # hit | # total | | ----------- | ----- | ----- | ------- | @@ -1564,6 +1569,72 @@ """ ) + # Generate coverage report for another project + buildTypeId = 'AnotherBuildType' + projectName = 'Another Project' + + self.teamcity.get_coverage_summary.return_value = \ + """ +Reading tracefile coverage/lcov.info +Summary coverage rate: + lines......: 20.0% (261 of 1305 lines) + functions..: 16.9% (41 of 242 functions) + branches...: 18.2% (123 of 676 branches) +""" + + call_status(BuildStatus.Success, expected_status_code=500) + assert_panel_content( + """**[[ https://build.bitcoinabc.org/viewLog.html?buildId=lastSuccessful&buildTypeId=DummyBuildType&tab=report__Root_Code_Coverage&guest=1 | Dummy Project coverage report ]]** + +| Granularity | % hit | # hit | # total | +| ----------- | ----- | ----- | ------- | +| Lines | 82.3% | 91410 | 111040 | +| Functions | 74.1% | 6686 | 9020 | +| Branches | 45.0% | 188886 | 420030 | + +**[[ https://build.bitcoinabc.org/viewLog.html?buildId=lastSuccessful&buildTypeId=AnotherBuildType&tab=report__Root_Code_Coverage&guest=1 | Another Project coverage report ]]** + +| Granularity | % hit | # hit | # total | +| ----------- | ----- | ----- | ------- | +| Lines | 20.0% | 261 | 1305 | +| Functions | 16.9% | 41 | 242 | +| Branches | 18.2% | 123 | 676 | +""" + ) + + # Update one of the existing coverage reports + buildTypeId = 'DummyBuildType' + projectName = 'Renamed Dummy Project' + + self.teamcity.get_coverage_summary.return_value = \ + """ +Reading tracefile check-extended_combined.info +Summary coverage rate: + lines......: 82.4% (91411 of 111030 lines) + functions..: 74.2% (6687 of 9010 functions) + branches...: 45.1% (188887 of 420020 branches) +""" + + call_status(BuildStatus.Success, expected_status_code=500) + assert_panel_content( + """**[[ https://build.bitcoinabc.org/viewLog.html?buildId=lastSuccessful&buildTypeId=DummyBuildType&tab=report__Root_Code_Coverage&guest=1 | Renamed Dummy Project coverage report ]]** + +| Granularity | % hit | # hit | # total | +| ----------- | ----- | ----- | ------- | +| Lines | 82.4% | 91411 | 111030 | +| Functions | 74.2% | 6687 | 9010 | +| Branches | 45.1% | 188887 | 420020 | + +**[[ https://build.bitcoinabc.org/viewLog.html?buildId=lastSuccessful&buildTypeId=AnotherBuildType&tab=report__Root_Code_Coverage&guest=1 | Another Project coverage report ]]** + +| Granularity | % hit | # hit | # total | +| ----------- | ----- | ----- | ------- | +| Lines | 20.0% | 261 | 1305 | +| Functions | 16.9% | 41 | 242 | +| Branches | 18.2% | 123 | 676 | +""" + ) + if __name__ == '__main__': unittest.main()