Use the generic format of reports of code analysis

If you use a solution unsupported by Themis, whether it is open source, proprietary or developed internally by yourselves, it is permitted to synchronize your review reports with Themis via a generic format of reports.

You have to therefore do this preliminary work, that consists of transforming your existing reports towards this new format.

A generic report is with the XML format, and draws from standard formats such as Checkstyle.

Description of the XML format

The report has to follow the following format:

<?xml version="1.0" encoding="UTF-8"?>
<report>
    <file name="ProjetA/src/Foo.c">
        <error line="10" message="Local variable 'i' is never read" rule="unusedVariable" ruleDescription="http://url.to.doc.rule"/>
    </file>
    <file name="ProjetB/src/Bar.c">
        <error line="20" message="Function 'compute' is too long (400 characters)" rule="functionTooLong" ruleDescription="http://url.to.doc.rule"/> </file> </report> 

The example here is on C code, but it may be others files written in other languages. 

Here are in detail the description of the elements:

  • A report root node covers the whole of the data
  • A file node is created by analyzed file. Every node contains the following attribute:
    • name: it is question of the file path, if possible since the root of the  source code repository. A sub-path may be sufficient, but involve risks of conflicts with other files supporting the same sub-path. Minimum, the full name of the file (name+extension) is necessary.
  • For every error, we add within the file root an error root with the following attributes:
    • line: the line number of the issue in the file;
    • message: the complete and contextualized description allowing a developer to identify the cause of the problem and how to solve it;
    • rule: the unique identifier of the rule (the good practice to respect) of quality measurement concerned by the problem;
    • ruleDescription: allows to indicate to the users of Themis a description of the rule. You may indicate here a link towards an internal wiki or an other resource. This attribute is optional.

It is permitted to produce several reports if necessary. Indeed, only an archive is transmitted to Themis, this one may contain one or several reports.

Prepare a Themis source to the mailing of generic reports

In the Administration part then Projects, identify the involved source by these review reports. Add a plugin for the "Technical debt" practice, then select the Linter generic report option. 

Add the involved file extensions by your code analysis. This point is significant because it will allow Themis to only take into account on your source code repository the files concerned by the analysis.

Thus, if you indicate ".js", only the files with the . js extensions will be taken into account. If files with ".js" extensions do not appear in your reports (which arrives generally when no default is detected in this file), Themis will take them still into account by considering that there are no defaults. 

Mailing of the reports top Themis by the REST API

If you do not use Jenkins, or do not wish to use the Jenkins plugin, it is possible to use the API of Themis to synchronize the reports of analysis of code at the generic format. Here is an example of a BASH script that you may implement in an other language if you wish (the variables at first are to adapt in your context) :

#!/bin/bash

#TOCHANGE THEMIS_URL="http://mythemis.com" SOURCE_KEY="da4e11f4-5489-4b2a-a028-20d071b1c671" API_KEY="NWJjZWQ3ZmNhYTJhYzkwMWRmNGZhYTYx" GENERIC_REPORT_FILE="generic_report_themis.xml" CURRENT_COMMIT=$(git rev-parse HEAD) #Current GIT commit
#For SVN : $(svn info --show-item last-changed-revision) CURRENT_DATE=$(date +%s)"000" WORKSPACE=$(pwd) #the root directory of the source code repository REPORT_ARCHIVE="themis_report.zip" #First of all, create an archive with all generic reports REPORT_DIR=$(mktemp -d -p /tmp) find . -name $GENERIC_REPORT_FILE -exec cp --parents \{\} $REPORT_DIR \; if [ -e $REPORT_ARCHIVE ];then echo "Remove existing archive" rm $REPORT_ARCHIVE else echo "File "$REPORT_ARCHIVE" does not exist" fi #Create archive to send to Themis zip -r $REPORT_ARCHIVE $REPORT_DIR curl -i \ -H "Content-Type: multipart/form-data" \ -H "Accept: application/json,application/zip" \ -H "themis-api-key:$API_KEY" \ -X POST \ -F 'metadata={ "executionDate" : "'$CURRENT_DATE'", "dataType" : "generic-report", "commit" : "'$CURRENT_COMMIT'", "dataWorkspace" : "'$WORKSPACE'"};type=application/json' \ -F "archive=@"$REPORT_ARCHIVE";type=application/zip" \ $THEMIS_URL/api/reportFiles/$SOURCE_KEY rm -rf $REPORT_DIR
rm $REPORT_ARCHIVE

 

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.