From 76459a38b267e6b1b86cc30f80bf19cb8f307c5e Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 29 Oct 2015 21:02:48 +0100 Subject: [PATCH] [DEV] add basic system for integration --- .htaccess | 42 ++++++++++ bdd.sql | 177 +++++++++++++++++++++++++++++++++++++++ build_inject.php | 131 +++++++++++++++++++++++++++++ build_send.py | 101 ++++++++++++++++++++++ build_thumb.php | 122 +++++++++++++++++++++++++++ call.php | 0 connect.php | 6 ++ coverage_inject.php | 177 +++++++++++++++++++++++++++++++++++++++ coverage_send.py | 118 ++++++++++++++++++++++++++ coverage_thumb.php | 135 ++++++++++++++++++++++++++++++ index.html | 1 + test_inject.php | 174 ++++++++++++++++++++++++++++++++++++++ test_send.py | 184 ++++++++++++++++++++++++++++++++++++++++ test_thumb.php | 135 ++++++++++++++++++++++++++++++ warning_inject.php | 177 +++++++++++++++++++++++++++++++++++++++ warning_send.py | 198 ++++++++++++++++++++++++++++++++++++++++++++ warning_thumb.php | 131 +++++++++++++++++++++++++++++ 17 files changed, 2009 insertions(+) create mode 100644 .htaccess create mode 100644 bdd.sql create mode 100644 build_inject.php create mode 100755 build_send.py create mode 100644 build_thumb.php create mode 100644 call.php create mode 100644 connect.php create mode 100644 coverage_inject.php create mode 100755 coverage_send.py create mode 100644 coverage_thumb.php create mode 100644 index.html create mode 100644 test_inject.php create mode 100755 test_send.py create mode 100644 test_thumb.php create mode 100644 warning_inject.php create mode 100755 warning_send.py create mode 100644 warning_thumb.php diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..a8c7942 --- /dev/null +++ b/.htaccess @@ -0,0 +1,42 @@ +## make sure nobody gets the htaccess files + + Order allow,deny + Deny from all + Satisfy All + + +# option pour 1and1 +#AddType x-mapp-php5 .php +#Options +FollowSymlinks + +# autoriser le .htaccess dans sites-availlable/default.conf +# enable the mode rewrite in : "/etc/apache2/mods-available" a copier dans "/etc/apache2/mods-enabled" +# sudo cp /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/ +# redemarrer apache : "sudo /etc/init.d/apache2 restart" +# voir les logs : "cat /var/log/apache2/error.log" + +# charge la première page : the start page is the Wiki with Acceuil... +#ErrorDocument 401 erreur/401 +#ErrorDocument 403 erreur/403 +#ErrorDocument 404 erreur/404 +#ErrorDocument 414 erreur/414 + + +RewriteEngine On +# si ce n'est pas un fichier +RewriteCond %{REQUEST_FILENAME} !-f + +# constitution d'une adresse : "user-name/repository.svg" to get tag or "user-name/repository" to view lib +RewriteRule ^build/([a-zA-Z0-9\-_]*)\/([a-zA-Z0-9\-_]*).svg$ build_thumb.php?USER=$1&LIB_NAME=$2 [L,QSA] +RewriteRule ^build/inject$ build_inject.php [L,QSA] + +RewriteRule ^coverage/([a-zA-Z0-9\-_]*)\/([a-zA-Z0-9\-_]*).svg$ coverage_thumb.php?USER=$1&LIB_NAME=$2 [L,QSA] +RewriteRule ^coverage/inject$ coverage_inject.php [L,QSA] + +RewriteRule ^warning/([a-zA-Z0-9\-_]*)\/([a-zA-Z0-9\-_]*).svg$ warning_thumb.php?USER=$1&LIB_NAME=$2 [L,QSA] +RewriteRule ^warning/inject$ warning_inject.php [L,QSA] + +RewriteRule ^test/([a-zA-Z0-9\-_]*)\/([a-zA-Z0-9\-_]*).svg$ test_thumb.php?USER=$1&LIB_NAME=$2 [L,QSA] +RewriteRule ^test/inject$ test_inject.php [L,QSA] + +RewriteRule ^([a-zA-Z0-9\-_]*)\/([a-zA-Z0-9\-_]*)$ view.php?USER=$1&LIB_NAME=$2 [L,QSA] diff --git a/bdd.sql b/bdd.sql new file mode 100644 index 0000000..c8aae15 --- /dev/null +++ b/bdd.sql @@ -0,0 +1,177 @@ +-- phpMyAdmin SQL Dump +-- version 4.4.13.1 +-- http://www.phpmyadmin.net +-- +-- Client : atriasofroot.mysql.db +-- Généré le : Mar 20 Octobre 2015 à 10:26 +-- Version du serveur : 5.5.44-0+deb7u1-log +-- Version de PHP : 5.3.8 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + +-- +-- Structure de la table `CI_group` +-- + +CREATE TABLE IF NOT EXISTS `CI_group` ( + `id` int(11) NOT NULL, + `user-name` varchar(256) NOT NULL, + `lib-name` varchar(256) NOT NULL, + `lib-branch` varchar(256) NOT NULL +) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8; + +-- +-- Structure de la table `COVERAGE_list` +-- + +CREATE TABLE IF NOT EXISTS `COVERAGE_list` ( + `id` int(11) NOT NULL, + `id-group` int(11) NOT NULL, + `time` int(11) NOT NULL, + `sha1` varchar(256) NOT NULL, + `executed` int(11) NOT NULL, + `executable` int(11) NOT NULL +) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=latin1; + +-- +-- Structure de la table `COVERAGE_snapshot` +-- + +CREATE TABLE IF NOT EXISTS `COVERAGE_snapshot` ( + `id` int(11) NOT NULL, + `id-group` int(11) NOT NULL, + `id-list` int(11) NOT NULL, + `json` text NOT NULL +) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; + +-- +-- Structure de la table `TEST_list` +-- + +CREATE TABLE IF NOT EXISTS `TEST_list` ( + `id` int(11) NOT NULL, + `id-group` int(11) NOT NULL, + `time` int(11) NOT NULL, + `sha1` varchar(256) CHARACTER SET latin1 NOT NULL, + `passed` int(11) NOT NULL, + `total` int(11) NOT NULL +) ENGINE=MyISAM AUTO_INCREMENT=131 DEFAULT CHARSET=utf8; + +-- +-- Structure de la table `TEST_snapshot` +-- + +CREATE TABLE IF NOT EXISTS `TEST_snapshot` ( + `id` int(11) NOT NULL, + `id-group` int(11) NOT NULL, + `id-list` int(11) NOT NULL, + `json` text NOT NULL +) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; + +-- +-- Structure de la table `WARNING_list` +-- + +CREATE TABLE IF NOT EXISTS `WARNING_list` ( + `id` int(11) NOT NULL, + `id-group` int(11) NOT NULL, + `time` int(11) NOT NULL, + `sha1` varchar(256) CHARACTER SET latin1 NOT NULL, + `warning` int(11) NOT NULL, + `error` int(11) NOT NULL +) ENGINE=MyISAM AUTO_INCREMENT=168 DEFAULT CHARSET=utf8; + +-- +-- Structure de la table `WARNING_snapshot` +-- + +CREATE TABLE IF NOT EXISTS `WARNING_snapshot` ( + `id` int(11) NOT NULL, + `id-group` int(11) NOT NULL, + `id-list` int(11) NOT NULL, + `json` text NOT NULL +) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; + +-- +-- Index pour la table `CI_group` +-- +ALTER TABLE `CI_group` + ADD PRIMARY KEY (`id`); + +-- +-- Index pour la table `COVERAGE_list` +-- +ALTER TABLE `COVERAGE_list` + ADD PRIMARY KEY (`id`); + +-- +-- Index pour la table `COVERAGE_snapshot` +-- +ALTER TABLE `COVERAGE_snapshot` + ADD PRIMARY KEY (`id`), + ADD UNIQUE KEY `id-group` (`id-group`); + +-- +-- Index pour la table `TEST_list` +-- +ALTER TABLE `TEST_list` + ADD PRIMARY KEY (`id`); + +-- +-- Index pour la table `TEST_snapshot` +-- +ALTER TABLE `TEST_snapshot` + ADD PRIMARY KEY (`id`); + +-- +-- Index pour la table `WARNING_list` +-- +ALTER TABLE `WARNING_list` + ADD PRIMARY KEY (`id`); + +-- +-- Index pour la table `WARNING_snapshot` +-- +ALTER TABLE `WARNING_snapshot` + ADD PRIMARY KEY (`id`); + +-- +-- AUTO_INCREMENT pour les tables exportées +-- + +-- +-- AUTO_INCREMENT pour la table `CI_group` +-- +ALTER TABLE `CI_group` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=10; +-- +-- AUTO_INCREMENT pour la table `COVERAGE_list` +-- +ALTER TABLE `COVERAGE_list` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=52; +-- +-- AUTO_INCREMENT pour la table `COVERAGE_snapshot` +-- +ALTER TABLE `COVERAGE_snapshot` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=4; +-- +-- AUTO_INCREMENT pour la table `TEST_list` +-- +ALTER TABLE `TEST_list` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=131; +-- +-- AUTO_INCREMENT pour la table `TEST_snapshot` +-- +ALTER TABLE `TEST_snapshot` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2; +-- +-- AUTO_INCREMENT pour la table `WARNING_list` +-- +ALTER TABLE `WARNING_list` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=168; +-- +-- AUTO_INCREMENT pour la table `WARNING_snapshot` +-- +ALTER TABLE `WARNING_snapshot` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=2; diff --git a/build_inject.php b/build_inject.php new file mode 100644 index 0000000..9c54306 --- /dev/null +++ b/build_inject.php @@ -0,0 +1,131 @@ +query($sql); +$exist = TRUE; +if ($result == NULL) { + // no result ... + $exist = FALSE; +} +//echo("find result : ".$result); + +if ($result->num_rows > 0) { + $userGroup = $result->fetch_assoc(); + $idGroup = $userGroup['id']; +} else { + $exist = FALSE; +} +if ($exist == FALSE) { + // create a new one ... + $sql = " INSERT INTO `CI_group` (`user-name`, `lib-name`, `lib-branch`)" + ." VALUES ('".$userName."'," + ." '".$libName."'," + ." '".$_POST['LIB_BRANCH']."')"; + $result = $COVERAGE_bdd->query($sql); + if ($result == TRUE) { + $exist == TRUE; + $idGroup = $COVERAGE_bdd->insert_id; + } else { + echo "[ERROR] Can not CREATE new group ..."; + } +} + +if ($idGroup <= -1) { + echo("[ERROR] can not create or find group"); +} else { + $sql = " INSERT INTO `BUILD_list` (`time`, `id-group`, `sha1`, `tag`, `status`)" + ." VALUES ('".time()."'," + ." '".$idGroup."'," + ." '".$_POST['SHA1']."'," + ." '".$_POST['TAG']."'," + ." '".$_POST['STATUS']."')"; + //echo $sql; + $result = $COVERAGE_bdd->query($sql); + if ($result == FALSE) { + echo("[ERROR] Can not register in db ... (LIST)"); + } + $sql = "SELECT `BUILD_snapshot`.`id` " + ." FROM `BUILD_snapshot`" + ." , `CI_group`" + ." WHERE `CI_group`.`user-name` = '".$userName."'" + ." AND `CI_group`.`lib-name` = '".$libName."'" + ." AND `CI_group`.`lib-branch` = '".$_POST['LIB_BRANCH']."'" + ." AND `CI_group`.`id` = `BUILD_snapshot`.`id-group`" + ." LIMIT 1"; + $result = $COVERAGE_bdd->query($sql); + //echo("sql : ".$sql); + if ( $result == NULL + || $result->num_rows == 0) { + // simply insert: + $sql = " INSERT INTO `BUILD_snapshot` (`id-group`, `".$_POST['TAG']."`)" + ." VALUES ('".$idGroup."'," + ." '".$_POST['STATUS']."')"; + $result = $COVERAGE_bdd->query($sql); + if ($result == TRUE) { + echo("[OK] registered done (new entry)"); + } else { + echo("[ERROR] Can not register in db ... (snapshot)"); + } + } else { + // try to update the curent values: + $sql = " UPDATE `BUILD_snapshot`" + ." SET `BUILD_snapshot`.`".$_POST['TAG']."` = '".$_POST['STATUS']."'" + ." WHERE `BUILD_snapshot`.`id-group` = '".$idGroup."'"; + $result = $COVERAGE_bdd->query($sql); + if ($result == TRUE) { + echo("[OK] registered done (update)"); + } else { + echo("[ERROR] Can not register in db ... (snapshot)"); + } + } +} +// simply close link with the DB... +$COVERAGE_bdd->close(); +?> \ No newline at end of file diff --git a/build_send.py b/build_send.py new file mode 100755 index 0000000..924c329 --- /dev/null +++ b/build_send.py @@ -0,0 +1,101 @@ +#!/usr/bin/python +## +## @author Edouard DUPIN +## +## @copyright 2012, Edouard DUPIN, all right reserved +## +## @license APACHE v2.0 (see license file) +## +import urllib, urllib2 +import sys +import os +import argparse + + +parser = argparse.ArgumentParser() +parser.add_argument("-u", "--url", help="server URL", + default="http://atria-soft.com/ci/build/inject") +parser.add_argument("-r", "--repo", help="Curent repositoty (generic github name (userName/repoName)", + default="") +parser.add_argument("-s", "--sha1", help="Sha1 on the commit (git) (256 char limited)", + default="") +parser.add_argument("-b", "--branch", help="branch of the repository (default master)", + default="") +parser.add_argument("-t", "--tag", help="Tag to register the system 'Linux', 'MacOs', 'Windows', 'IOs', 'Android' ('' for exit)", + default="") +parser.add_argument("-S", "--status", help="Build status 'START', 'OK', 'ERROR' or $?", + default="") +################### +## Choice 3 ## +################### +parser.add_argument("--test", help="test value (local server ...)", + action="store_true") +args = parser.parse_args() + +if args.test == True: + args.url = 'http://127.0.0.1/build/inject.php' + args.repo = 'HeeroYui/test' + args.sha1 = '' + args.branch = 'master' + args.tag = 'Windows' + args.status = 'START' +else: + if args.tag == "": + print("[NOTE] (local) not set '--tag' parameter ==> just stop") + exit(0) + list_tag = ['Linux', 'MacOs', 'Windows', 'IOs', 'Android', 'Mingw'] + if args.tag not in list_tag: + print("[ERROR] (local) set '--tag' parameter: " + str(list_tag)) + exit(-2) + if args.status == "": + print("[ERROR] (local) set '--status' parameter") + exit(-2) + +if args.status not in ['START', 'OK', 'ERROR']: + #print("ploppp : '" + str(args.status) + "'") + if args.status == "0": + args.status = 'OK' + else: + args.status = 'ERROR' + +# todo : check if repo is contituated with a "/" ... +# if repo, sha1 and branch is not set, we try to get it with travis global environement variable : +if args.repo == "": + args.repo = os.environ.get('TRAVIS_REPO_SLUG') + if args.repo == None: + print("[ERROR] (local) missing 'repo' parameter can not get travis env variable") + exit(-2) +if args.sha1 == "": + args.sha1 = os.environ.get('TRAVIS_COMMIT') + if args.sha1 == None: + args.sha1 = "" + +if args.branch == "": + args.branch = os.environ.get('TRAVIS_BRANCH') + if args.branch == None: + args.branch = "" + +print(" url = " + args.url) +print(" repo = " + args.repo) +print(" sha1 = " + args.sha1) +print(" branch = " + args.branch) +print(" tag = " + args.tag) +print(" status = " + args.status) + +data = urllib.urlencode({'REPO':args.repo, + 'SHA1':args.sha1, + 'LIB_BRANCH':args.branch, + 'TAG':args.tag, + 'STATUS':args.status}) + +req = urllib2.Request(args.url, data) +response = urllib2.urlopen(req) +#print response.geturl() +#print response.info() +return_data = response.read() +print return_data +if return_data[:7] == "[ERROR]": + exit(-1) + +exit(0) + diff --git a/build_thumb.php b/build_thumb.php new file mode 100644 index 0000000..7cf8be5 --- /dev/null +++ b/build_thumb.php @@ -0,0 +1,122 @@ +USER = ".$_GET['USER']); +//echo("
LIB_NAME = ".$_GET['LIB_NAME']); +//echo("
branch = ".$_GET['branch']); +//die("
die"); +header("Content-Type: image/svg+xml"); +header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 +header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date dans le passé + +function errorSVG($_name) { + echo(''); + echo(' '); + echo(' '); + echo(' '); + echo(' '); + echo(' '); + echo(' '); + echo(' BUILD: '.$_name.''); + echo(' BUILD: '.$_name.''); + echo(' '); + echo(''); + exit(); +} + +include_once("connect.php"); +@include_once("connect_server.php"); + +$COVERAGE_bdd = mysqli_connect($sqlServer, $sqlLogin, $sqlPass, $sqlBDD); +// Check connection +if (mysqli_connect_errno()) { + errorSVG("SQL ERROR"); +} +// check if all is here ... +$branch = "master"; +$tag = "Linux"; +if (isset($_GET['USER']) == FALSE) { + errorSVG("USER??"); +} +if (isset($_GET['LIB_NAME']) == FALSE) { + errorSVG("LIB_NAME??"); +} +if (isset($_GET['branch']) == TRUE) { + $branch = $_GET['branch']; +} +if (isset($_GET['tag']) == TRUE) { + $tag = $_GET['tag']; +} + +//echo "register ".$_POST['JSON_FILE']; + +$sql = "SELECT `BUILD_snapshot`.`".$tag."` " + ." FROM `BUILD_snapshot`" + ." , `CI_group`" + ." WHERE `CI_group`.`user-name` = '".$_GET['USER']."'" + ." AND `CI_group`.`lib-name` = '".$_GET['LIB_NAME']."'" + ." AND `CI_group`.`lib-branch` = '".$branch."'" + ." AND `CI_group`.`id` = `BUILD_snapshot`.`id-group`" + ." LIMIT 1"; + +//echo("sql : ".$sql); +$result = $COVERAGE_bdd->query($sql); +// +if ($result == NULL) { + errorSVG("UNKNOW"); +} +//echo("find result : ".$result); + +if ($result->num_rows > 0) { + if ($result->num_rows > 1) { + errorSVG("To much value"); + } + $row = $result->fetch_assoc(); +} else { + errorSVG("No Value"); +} + +$status = $row[$tag]; + + +//some coverage value : +if ($status == "UNKNOW") { + $color = "333"; +} else if ($status == "START") { + $color = "11F"; +} else if ($status == "ERROR") { + $color = "c11"; +} else if ($status == "OK") { + $color = "4c1"; +} else { + $color = "FF0"; +} + +echo(''); +echo(' '); +echo(' '); +echo(' '); +echo(' '); +echo(' '); +echo(' '); +echo(' '); +echo(' '); +echo(' '); +echo(' build'); +echo(' Build'); +echo(' '.$tag.''); +echo(' '.$tag.''); +echo(' '.$status.''); +echo(' '.$status.''); +echo(' '); +echo(''); + +// simply close link with the DB... +$COVERAGE_bdd->close(); + +?> \ No newline at end of file diff --git a/call.php b/call.php new file mode 100644 index 0000000..e69de29 diff --git a/connect.php b/connect.php new file mode 100644 index 0000000..3277073 --- /dev/null +++ b/connect.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/coverage_inject.php b/coverage_inject.php new file mode 100644 index 0000000..e900365 --- /dev/null +++ b/coverage_inject.php @@ -0,0 +1,177 @@ + 0) { + switch (json_last_error()) { + case JSON_ERROR_NONE: + die("[ERROR] JSON parse: JSON_ERROR_NONE"); + case JSON_ERROR_DEPTH: + die("[ERROR] JSON parse: JSON_ERROR_DEPTH"); + case JSON_ERROR_STATE_MISMATCH: + die("[ERROR] JSON parse: JSON_ERROR_STATE_MISMATCH"); + case JSON_ERROR_CTRL_CHAR: + die("[ERROR] JSON parse: JSON_ERROR_CTRL_CHAR"); + case JSON_ERROR_SYNTAX: + die("[ERROR] JSON parse: JSON_ERROR_SYNTAX"); + default: + die("[ERROR] JSON parse: ???"); + } + die("[ERROR] JSON parse: ".json_last_error_msg()); +} + +if (isset($val["executed"]) == FALSE) { + die("[ERROR] Missing JSON data (root): 'executed'"); +} +if (isset($val["executable"]) == FALSE) { + die("[ERROR] Missing JSON data (root): 'executable'"); +} +$newJsonData = array(); +if (isset($val["list"]) == TRUE) { + foreach ($val["list"] as $value) { + if (isset($value['file']) == FALSE) { + die("[ERROR] Missing JSON data (list): file"); + } + if (isset($value['executed']) == FALSE) { + die("[ERROR] Missing JSON data (list): executed"); + } + if (isset($value['executable']) == FALSE) { + die("[ERROR] Missing JSON data (list): executable"); + } + array_push($newJsonData, array("file" => $value['file'], "executed" => $value['executed'], "executable" => $value['executable'])); + } +} +$dataJSON = json_encode($newJsonData); + +list($userName, $libName) = explode("/", $_POST['REPO'], 2); +//die("[ERROR] test : ".$userName." ".$libName); +if ($userName == "") { + die("[ERROR] missing the user-name in '".$_POST['REPO']."'"); +} +if ($libName == "") { + die("[ERROR] missing the lib-name in '".$_POST['REPO']."'"); +} + +include_once("connect.php"); +@include_once("connect_server.php"); + +$COVERAGE_bdd = mysqli_connect($sqlServer, $sqlLogin, $sqlPass, $sqlBDD); +/* Check connection */ +if (mysqli_connect_errno()) { + die("[ERROR] my-SQL-connection ERROR: '".mysqli_connect_error()."'"); +} + +$idGroup = -1; +// first step : check if the group exist ... +$sql = " SELECT * FROM `CI_group`" + ." WHERE `CI_group`.`user-name` = '".$userName."'" + ." AND `CI_group`.`lib-name` = '".$libName."'" + ." AND `CI_group`.`lib-branch` = '".$_POST['LIB_BRANCH']."'" + ." LIMIT 1"; +$result = $COVERAGE_bdd->query($sql); +$exist = TRUE; +if ($result == NULL) { + // no result ... + $exist = FALSE; +} +//echo("find result : ".$result); + +if ($result->num_rows > 0) { + $userGroup = $result->fetch_assoc(); + $idGroup = $userGroup['id']; +} else { + $exist = FALSE; +} +if ($exist == FALSE) { + // create a new one ... + $sql = " INSERT INTO `CI_group` (`user-name`, `lib-name`, `lib-branch`)" + ." VALUES ('".$userName."'," + ." '".$libName."'," + ." '".$_POST['LIB_BRANCH']."')"; + $result = $COVERAGE_bdd->query($sql); + if ($result == TRUE) { + $exist == TRUE; + $idGroup = $COVERAGE_bdd->insert_id; + } else { + echo "[ERROR] Can not CREATE new group ..."; + } +} + +if ($idGroup <= -1) { + echo("[ERROR] can not create or find group"); +} else { + $sql = " INSERT INTO `COVERAGE_list` (`time`, `id-group`, `sha1`, `executed`, `executable`)" + ." VALUES ('".time()."'," + ." '".$idGroup."'," + ." '".$_POST['SHA1']."'," + ." '".$val["executed"]."'," + ." '".$val["executable"]."')"; + //echo $sql; + $result = $COVERAGE_bdd->query($sql); + if ($result == FALSE) { + echo("[ERROR] Can not register in db ... (LIST)"); + } else { + // get the id inserted + $idList = $COVERAGE_bdd->insert_id; + // try to update the curent values: + $sql = " UPDATE `COVERAGE_snapshot`" + ." SET `COVERAGE_snapshot`.`id-list` = '".$idList."'" + ." , `COVERAGE_snapshot`.`json` = '".$dataJSON."'" + ." WHERE `COVERAGE_snapshot`.`id-group` = '".$idGroup."'"; + $result = $COVERAGE_bdd->query($sql); + if ($result == TRUE) { + echo("[OK] registered done"); + } else { + $sql = " INSERT INTO `COVERAGE_snapshot` (`id-group`, `id-list`, `json`)" + ." VALUES ('".$idGroup."'," + ." '".$idList."'," + ." '".$dataJSON."')"; + $result = $COVERAGE_bdd->query($sql); + if ($result == TRUE) { + echo("[OK] registered done"); + } else { + echo("[ERROR] Can not register in db ... (snapshot)"); + } + } + } +} +// simply close link with the DB... +$COVERAGE_bdd->close(); + +?> \ No newline at end of file diff --git a/coverage_send.py b/coverage_send.py new file mode 100755 index 0000000..55afd4b --- /dev/null +++ b/coverage_send.py @@ -0,0 +1,118 @@ +#!/usr/bin/python +## +## @author Edouard DUPIN +## +## @copyright 2012, Edouard DUPIN, all right reserved +## +## @license APACHE v2.0 (see license file) +## +import urllib, urllib2 +import sys +import os +import argparse + + +parser = argparse.ArgumentParser() +parser.add_argument("-u", "--url", help="server URL", + default="http://atria-soft.com/ci/coverage/inject") +parser.add_argument("-r", "--repo", help="Curent repositoty (generic github name (userName/repoName)", + default="") +parser.add_argument("-s", "--sha1", help="Sha1 on the commit (git) (256 char limited)", + default="") +parser.add_argument("-b", "--branch", help="branch of the repository (default master)", + default="") +################### +## Choice 1 ## +################### +parser.add_argument("-j", "--json", help="all data to send ... (json file NOT json data)", + default="") +################### +## Choice 2 ## +################### +parser.add_argument("--executed", help="if not use JSON file: simply generate the nb executed line in the lib/program", + default=-1, + type=int) +parser.add_argument("--executable", help="if not use JSON file: simply generate the nb executable line in the lib/program", + default=-1, + type=int) +################### +## Choice 3 ## +################### +parser.add_argument("--test", help="test value (local server ...)", + action="store_true") +args = parser.parse_args() + +if args.test == True: + args.url = 'http://127.0.0.1/coverage/inject.php' + args.repo = 'HeeroYui/test' + args.sha1 = '' + args.branch = 'master' + json_data = '{"executed":16,"executable":512,"list":[{"file":"test/plop.cpp","executed":57,"executable":75}]}' +else: + if args.json != "": + if args.executed >= 0: + print("[ERROR] (local) set 'executed' parameter with a json file") + exit(-2) + if args.executable >= 0: + print("[ERROR] (local) set 'executable' parameter with a json file") + exit(-2) + if not os.path.isfile(args.json): + print("[ERROR] (local) can not read json file" + args.json) + exit(-2) + file = open(args.json, "r") + json_data = file.read() + file.close() + if len(json_data) <= 0: + print("[ERROR] (local) json file is empty") + exit(-2) + else: + if args.executed < 0: + print("[ERROR] (local) missing 'executed' parameter with NO json file") + exit(-2) + if args.executable < 0: + print("[ERROR] (local) missing 'executable' parameter with NO json file") + exit(-2) + # create the minimal json file: + json_data = '{"executed":' + str(args.executed) + ',"executable":' + str(args.executable) + ',"list":[]}' + +print("json data: " + str(json_data)) + +# todo : check if repo is contituated wit a "/" ... +# if repo, sha1 and branch is not set, we try to get it with travis global environement variable : +if args.repo == "": + args.repo = os.environ.get('TRAVIS_REPO_SLUG') + if args.repo == None: + print("[ERROR] (local) missing 'repo' parameter can not get travis env variable") + exit(-2) +if args.sha1 == "": + args.sha1 = os.environ.get('TRAVIS_COMMIT') + if args.sha1 == None: + args.sha1 = "" + +if args.branch == "": + args.branch = os.environ.get('TRAVIS_BRANCH') + if args.branch == None: + args.branch = "" + +print(" url = " + args.url) +print(" repo = " + args.repo) +print(" sha1 = " + args.sha1) +print(" branch = " + args.branch) +print(" json_data len = " + str(len(json_data))) + +data = urllib.urlencode({'REPO':args.repo, + 'SHA1':args.sha1, + 'LIB_BRANCH':args.branch, + 'JSON_FILE':json_data}) + +req = urllib2.Request(args.url, data) +response = urllib2.urlopen(req) +#print response.geturl() +#print response.info() +return_data = response.read() +print return_data +if return_data[:7] == "[ERROR]": + exit(-1) + +exit(0) + diff --git a/coverage_thumb.php b/coverage_thumb.php new file mode 100644 index 0000000..2fcd5e5 --- /dev/null +++ b/coverage_thumb.php @@ -0,0 +1,135 @@ +USER = ".$_GET['USER']); +echo("
LIB_NAME = ".$_GET['LIB_NAME']); +echo("
branch = ".$_GET['branch']); +die("
die"); +*/ +header("Content-Type: image/svg+xml"); +header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 +header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date dans le passé +/* +header('Content-Type: image/svg+xml'); +echo ''; +$c = (int)(($x*$y)/$scaler); +$prev = 0; +foreach($rgb as $k=>$v){ + if($v > 0) { + $r = ($k >> 16) & 0xFF; + $g = ($k >> 8) & 0xFF; + $b = $k & 0xFF; + $hex = str_pad(dechex($r),2,'0',STR_PAD_LEFT).str_pad(dechex($g),2,'0',STR_PAD_LEFT).str_pad(dechex($b),2,'0',STR_PAD_LEFT); + echo ''; + echo "\n"; + $prev += (int)($v/$scaler); + } +} +echo ''; +*/ + + +function errorSVG($_name) { + echo(''); + echo(' '); + echo(' '); + echo(' '); + echo(' '); + echo(' '); + echo(' '); + echo(' COV: '.$_name.''); + echo(' COV: '.$_name.''); + echo(' '); + echo(''); + exit(); +} + +include_once("connect.php"); + +@include_once("connect_server.php"); + +$COVERAGE_bdd = mysqli_connect($sqlServer, $sqlLogin, $sqlPass, $sqlBDD); +// Check connection +if (mysqli_connect_errno()) { + errorSVG("SQL ERROR"); +} +// check if all is here ... +$branch = "master"; +if (isset($_GET['USER']) == FALSE) { + errorSVG("USER??"); +} else if (isset($_GET['LIB_NAME']) == FALSE) { + errorSVG("LIB_NAME??"); +} +if (isset($_GET['branch']) == TRUE) { + $branch = $_GET['branch']; +} + +//echo "register ".$_POST['JSON_FILE']; +$sql = "SELECT `COVERAGE_list`.`executed` " + ." , `COVERAGE_list`.`executable` " + ." FROM `COVERAGE_list`" + ." , `CI_group`" + ." WHERE `CI_group`.`user-name` = '".$_GET['USER']."'" + ." AND `CI_group`.`lib-name` = '".$_GET['LIB_NAME']."'" + ." AND `CI_group`.`lib-branch` = '".$branch."'" + ." AND `CI_group`.`id` = `COVERAGE_list`.`id-group`" + ." ORDER BY `COVERAGE_list`.`time` DESC" + ." LIMIT 1"; +$result = $COVERAGE_bdd->query($sql); +//echo("sql : ".$sql); +if ($result == NULL) { + errorSVG("UNKNOW"); +} +//echo("find result : ".$result); + +if ($result->num_rows > 0) { + if ($result->num_rows > 1) { + errorSVG("To much value"); + } + $row = $result->fetch_assoc(); +} else { + errorSVG("No Value"); +} + +if ($row['executable'] == 0) { + $coverage = 100; +} else { + $coverage = intval(100 * $row['executed'] / $row['executable']); +} + +//some coverage value : +if ($coverage < 25 ) { + $color = "c11"; +} else if ($coverage < 50 ) { + $color = "c1c"; +} else if ($coverage < 75 ) { + $color = "c71"; +} else { + $color = "4c1"; +} + +echo(''); +echo(' '); +echo(' '); +echo(' '); +echo(' '); +echo(' '); +echo(' '); +#echo(' '); +echo(' '); +echo(' '); +echo(' coverage'); +echo(' coverage'); +echo(' '.$coverage.'%'); +echo(' '.$coverage.'%'); +echo(' '); +echo(''); + +// simply close link with the DB... +$COVERAGE_bdd->close(); +?> \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..da83274 --- /dev/null +++ b/index.html @@ -0,0 +1 @@ +Coverage interface (No web interface availlable now ...) \ No newline at end of file diff --git a/test_inject.php b/test_inject.php new file mode 100644 index 0000000..e5f0954 --- /dev/null +++ b/test_inject.php @@ -0,0 +1,174 @@ + 0) { + switch (json_last_error()) { + case JSON_ERROR_NONE: + die("[ERROR] JSON parse: JSON_ERROR_NONE"); + case JSON_ERROR_DEPTH: + die("[ERROR] JSON parse: JSON_ERROR_DEPTH"); + case JSON_ERROR_STATE_MISMATCH: + die("[ERROR] JSON parse: JSON_ERROR_STATE_MISMATCH"); + case JSON_ERROR_CTRL_CHAR: + die("[ERROR] JSON parse: JSON_ERROR_CTRL_CHAR"); + case JSON_ERROR_SYNTAX: + die("[ERROR] JSON parse: JSON_ERROR_SYNTAX"); + default: + die("[ERROR] JSON parse: ???"); + } + die("[ERROR] JSON parse: ".json_last_error_msg()); +} + +if (isset($val["passed"]) == FALSE) { + die("[ERROR] Missing JSON data (root): 'passed'"); +} +if (isset($val["total"]) == FALSE) { + die("[ERROR] Missing JSON data (root): 'executable'"); +} +$newJsonData = array(); +if (isset($val["list"]) == TRUE) { + foreach ($val["list"] as $value) { + if (isset($value['test-name']) == FALSE) { + die("[ERROR] Missing JSON data (list): test-name"); + } + if (isset($value['fail']) == FALSE) { + die("[ERROR] Missing JSON data (list): fail"); + } + array_push($newJsonData, array("file" => $value['test-name'], "test-name" => $value['fail'])); + } +} +$dataJSON = json_encode($newJsonData); + +list($userName, $libName) = explode("/", $_POST['REPO'], 2); +//die("[ERROR] test : ".$userName." ".$libName); +if ($userName == "") { + die("[ERROR] missing the user-name in '".$_POST['REPO']."'"); +} +if ($libName == "") { + die("[ERROR] missing the lib-name in '".$_POST['REPO']."'"); +} + +include_once("connect.php"); +@include_once("connect_server.php"); + +$TEST_bdd = mysqli_connect($sqlServer, $sqlLogin, $sqlPass, $sqlBDD); +/* Check connection */ +if (mysqli_connect_errno()) { + die("[ERROR] my-SQL-connection ERROR: '".mysqli_connect_error()."'"); +} + +$idGroup = -1; +// first step : check if the group exist ... +$sql = " SELECT * FROM `CI_group`" + ." WHERE `CI_group`.`user-name` = '".$userName."'" + ." AND `CI_group`.`lib-name` = '".$libName."'" + ." AND `CI_group`.`lib-branch` = '".$_POST['LIB_BRANCH']."'" + ." LIMIT 1"; +$result = $TEST_bdd->query($sql); +$exist = TRUE; +if ($result == NULL) { + // no result ... + $exist = FALSE; +} +//echo("find result : ".$result); + +if ($result->num_rows > 0) { + $userGroup = $result->fetch_assoc(); + $idGroup = $userGroup['id']; +} else { + $exist = FALSE; +} +if ($exist == FALSE) { + // create a new one ... + $sql = " INSERT INTO `CI_group` (`user-name`, `lib-name`, `lib-branch`)" + ." VALUES ('".$userName."'," + ." '".$libName."'," + ." '".$_POST['LIB_BRANCH']."')"; + $result = $TEST_bdd->query($sql); + if ($result == TRUE) { + $exist == TRUE; + $idGroup = $TEST_bdd->insert_id; + } else { + echo "[ERROR] Can not CREATE new group ..."; + } +} + +if ($idGroup <= -1) { + echo("[ERROR] can not create or find group"); +} else { + $sql = " INSERT INTO `TEST_list` (`time`, `id-group`, `sha1`, `passed`, `total`)" + ." VALUES ('".time()."'," + ." '".$idGroup."'," + ." '".$_POST['SHA1']."'," + ." '".$val["passed"]."'," + ." '".$val["total"]."')"; + //echo $sql; + $result = $TEST_bdd->query($sql); + if ($result == FALSE) { + echo("[ERROR] Can not register in db ... (LIST)"); + } else { + // get the id inserted + $idList = $TEST_bdd->insert_id; + // try to update the curent values: + $sql = " UPDATE `TEST_snapshot`" + ." SET `TEST_snapshot`.`id-list` = '".$idList."'" + ." , `TEST_snapshot`.`json` = '".$dataJSON."'" + ." WHERE `TEST_snapshot`.`id-group` = '".$idGroup."'"; + $result = $TEST_bdd->query($sql); + if ($result == TRUE) { + echo("[OK] registered done"); + } else { + $sql = " INSERT INTO `TEST_snapshot` (`id-group`, `id-list`, `json`)" + ." VALUES ('".$idGroup."'," + ." '".$idList."'," + ." '".$dataJSON."')"; + $result = $TEST_bdd->query($sql); + if ($result == TRUE) { + echo("[OK] registered done"); + } else { + echo("[ERROR] Can not register in db ... (snapshot)"); + } + } + } +} +// simply close link with the DB... +$TEST_bdd->close(); + +?> \ No newline at end of file diff --git a/test_send.py b/test_send.py new file mode 100755 index 0000000..a20ec06 --- /dev/null +++ b/test_send.py @@ -0,0 +1,184 @@ +#!/usr/bin/python +## +## @author Edouard DUPIN +## +## @copyright 2012, Edouard DUPIN, all right reserved +## +## @license APACHE v2.0 (see license file) +## +import urllib, urllib2 +import sys +import os +import argparse + + +parser = argparse.ArgumentParser() +parser.add_argument("-u", "--url", help="server URL", + default="http://atria-soft.com/ci/test/inject") +parser.add_argument("-r", "--repo", help="Curent repositoty (generic github name (userName/repoName)", + default="") +parser.add_argument("-s", "--sha1", help="Sha1 on the commit (git) (256 char limited)", + default="") +parser.add_argument("-b", "--branch", help="branch of the repository (default master)", + default="") +################### +## Choice 1 ## +################### +parser.add_argument("-j", "--json", help="all data to send ... (json file NOT json data)", + default="") +################### +## Choice 2 ## +################### +parser.add_argument("--passed", help="if not use JSON file: nb Test passsed in the lib/program", + default=-1, + type=int) +parser.add_argument("--total", help="if not use JSON file: number total of test in the lib/program", + default=-1, + type=int) +################### +## Choice 3 ## +################### +parser.add_argument("--file", help="if not use JSON file: file with the 'gtest' log", + default="") +################### +## Choice 4 ## +################### +parser.add_argument("--test", help="test value (local server ...)", + action="store_true") +args = parser.parse_args() + +if args.test == True: + args.url = 'http://127.0.0.1/ci/test_inject.php' + args.repo = 'HeeroYui/test' + args.sha1 = '' + args.branch = 'master' + json_data = '{"executed":16,"executable":512,"list":[{"file":"test/plop.cpp","executed":57,"executable":75}]}' +else: + if args.json != "": + if args.passed >= 0: + print("[ERROR] (local) set 'passed' parameter with a json file") + exit(-2) + if args.total >= 0: + print("[ERROR] (local) set 'total' parameter with a json file") + exit(-2) + if args.file != "": + print("[ERROR] (local) set 'file' parameter with a json file") + exit(-2) + if not os.path.isfile(args.json): + print("[ERROR] (local) can not read json file" + args.json) + exit(-2) + file = open(args.json, "r") + json_data = file.read() + file.close() + if len(json_data) <= 0: + print("[ERROR] (local) json file is empty") + exit(-2) + elif args.passed >= 0: + if args.file != "": + print("[ERROR] (local) set 'file' parameter with 'passed'") + exit(-2) + if args.total < 0: + args.total = 0 + json_data = '{"passed":' + args.passed + ',"total":' + args.total + ',"list":[]}' + else: + if args.file == "": + print("[ERROR] (local) set 'file' parameter empty") + exit(-2) + if not os.path.isfile(args.file): + print("[ERROR] (local) can not read test file" + args.file) + exit(-2) + file = open(args.file, "r") + data = file.read() + file.close() + lines = data.split("\n") + result = [] + total_test = 0 + total_passed = 0 + # parse all lines + for line in lines: + if len(line) <= 0: + continue + if line[0] != '[': + continue + if line[:12] == "[ RUN ]": + #next line is usefull ... + continue + if line[:12] == "[ PASSED ]": + #End of test result + break + if line[:12] == "[ OK ]": + # this test is OK ... + # TestDeclaration.testBase (0 ms) + test_name = line[13:].split(" ")[0] + result.append([test_name, True]) + total_test += 1 + total_passed += 1 + continue + if line[:12] == "[ FAILED ]": + # this test failled ... + test_name = line[13:].split(" ")[0] + result.append([test_name, False]) + total_test += 1 + continue + # nothing to do ... + #print("result : " + str(result)) + + # create the minimal json file: + json_data = '{\n\t"passed":' + str(total_passed) + ',\n\t"total":' + str(total_test) + ',\n\t"list":[\n' + first = True + for elem in result: + if first == True: + first = False + json_data += '\t\t{\n' + else: + json_data += '\t\t}, {\n' + json_data += '\t\t\t"test-name":"' + elem[0] + '",\n' + if elem[1] == True: + json_data += '\t\t\t"fail":false\n' + else: + json_data += '\t\t\t"fail":true\n' + if first == False: + json_data += '\t\t}\n' + json_data += '\t]\n}' + +print("json data: " + str(json_data)) + +# todo : check if repo is contituated wit a "/" ... +# if repo, sha1 and branch is not set, we try to get it with travis global environement variable : +if args.repo == "": + args.repo = os.environ.get('TRAVIS_REPO_SLUG') + if args.repo == None: + print("[ERROR] (local) missing 'repo' parameter can not get travis env variable") + exit(-2) +if args.sha1 == "": + args.sha1 = os.environ.get('TRAVIS_COMMIT') + if args.sha1 == None: + args.sha1 = "" + +if args.branch == "": + args.branch = os.environ.get('TRAVIS_BRANCH') + if args.branch == None: + args.branch = "" + +print(" url = " + args.url) +print(" repo = " + args.repo) +print(" sha1 = " + args.sha1) +print(" branch = " + args.branch) +print(" json_data len = " + str(len(json_data))) + +data = urllib.urlencode({'REPO':args.repo, + 'SHA1':args.sha1, + 'JSON_FILE':json_data, + 'LIB_BRANCH':args.branch}) + +req = urllib2.Request(args.url, data) +response = urllib2.urlopen(req) +#print response.geturl() +#print response.info() +return_data = response.read() +print return_data +if return_data[:7] == "[ERROR]": + exit(-1) + +exit(0) + diff --git a/test_thumb.php b/test_thumb.php new file mode 100644 index 0000000..6e85cc9 --- /dev/null +++ b/test_thumb.php @@ -0,0 +1,135 @@ +USER = ".$_GET['USER']); +echo("
LIB_NAME = ".$_GET['LIB_NAME']); +echo("
branch = ".$_GET['branch']); +die("
die"); +*/ +header("Content-Type: image/svg+xml"); +header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 +header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date dans le passé +/* +header('Content-Type: image/svg+xml'); +echo ''; +$c = (int)(($x*$y)/$scaler); +$prev = 0; +foreach($rgb as $k=>$v){ + if($v > 0) { + $r = ($k >> 16) & 0xFF; + $g = ($k >> 8) & 0xFF; + $b = $k & 0xFF; + $hex = str_pad(dechex($r),2,'0',STR_PAD_LEFT).str_pad(dechex($g),2,'0',STR_PAD_LEFT).str_pad(dechex($b),2,'0',STR_PAD_LEFT); + echo ''; + echo "\n"; + $prev += (int)($v/$scaler); + } +} +echo ''; +*/ + + +function errorSVG($_name) { + echo(''); + echo(' '); + echo(' '); + echo(' '); + echo(' '); + echo(' '); + echo(' '); + echo(' TEST: '.$_name.''); + echo(' TEST: '.$_name.''); + echo(' '); + echo(''); + exit(); +} + +include_once("connect.php"); + +@include_once("connect_server.php"); + +$TEST_bdd = mysqli_connect($sqlServer, $sqlLogin, $sqlPass, $sqlBDD); +// Check connection +if (mysqli_connect_errno()) { + errorSVG("SQL ERROR"); +} +// check if all is here ... +$branch = "master"; +if (isset($_GET['USER']) == FALSE) { + errorSVG("USER??"); +} else if (isset($_GET['LIB_NAME']) == FALSE) { + errorSVG("LIB_NAME??"); +} +if (isset($_GET['branch']) == TRUE) { + $branch = $_GET['branch']; +} + +//echo "register ".$_POST['JSON_FILE']; +$sql = "SELECT `TEST_list`.`passed` " + ." , `TEST_list`.`total` " + ." FROM `TEST_list`" + ." , `CI_group`" + ." WHERE `CI_group`.`user-name` = '".$_GET['USER']."'" + ." AND `CI_group`.`lib-name` = '".$_GET['LIB_NAME']."'" + ." AND `CI_group`.`lib-branch` = '".$branch."'" + ." AND `CI_group`.`id` = `TEST_list`.`id-group`" + ." ORDER BY `TEST_list`.`time` DESC" + ." LIMIT 1"; +$result = $TEST_bdd->query($sql); +//echo("sql : ".$sql); +if ($result == NULL) { + errorSVG("UNKNOW"); +} +//echo("find result : ".$result); + +if ($result->num_rows > 0) { + if ($result->num_rows > 1) { + errorSVG("To much value"); + } + $row = $result->fetch_assoc(); +} else { + errorSVG("No Value"); +} + +if ($row['total'] == 0) { + $testRatio = 0; +} else { + $testRatio = intval(100 * $row['passed'] / $row['total']); +} + +//some testRatio value : +if ($testRatio < 25 ) { + $color = "c11"; +} else if ($testRatio < 50 ) { + $color = "c1c"; +} else if ($testRatio < 100 ) { + $color = "c71"; +} else { + $color = "4c1"; +} + +echo(''); +echo(' '); +echo(' '); +echo(' '); +echo(' '); +echo(' '); +echo(' '); +#echo(' '); +echo(' '); +echo(' '); +echo(' test'); +echo(' test'); +echo(' '.$testRatio.'%'); +echo(' '.$testRatio.'%'); +echo(' '); +echo(''); + +// simply close link with the DB... +$TEST_bdd->close(); +?> \ No newline at end of file diff --git a/warning_inject.php b/warning_inject.php new file mode 100644 index 0000000..447d078 --- /dev/null +++ b/warning_inject.php @@ -0,0 +1,177 @@ + 0) { + switch (json_last_error()) { + case JSON_ERROR_NONE: + die("[ERROR] JSON parse: JSON_ERROR_NONE"); + case JSON_ERROR_DEPTH: + die("[ERROR] JSON parse: JSON_ERROR_DEPTH"); + case JSON_ERROR_STATE_MISMATCH: + die("[ERROR] JSON parse: JSON_ERROR_STATE_MISMATCH"); + case JSON_ERROR_CTRL_CHAR: + die("[ERROR] JSON parse: JSON_ERROR_CTRL_CHAR"); + case JSON_ERROR_SYNTAX: + die("[ERROR] JSON parse: JSON_ERROR_SYNTAX"); + default: + die("[ERROR] JSON parse: ???"); + } + die("[ERROR] JSON parse: ".json_last_error_msg()); +} + +if (isset($val["warning"]) == FALSE) { + die("[ERROR] Missing JSON data (root): 'warning'"); +} +if (isset($val["error"]) == FALSE) { + die("[ERROR] Missing JSON data (root): 'error'"); +} +$newJsonData = array(); +if (isset($val["list"]) == TRUE) { + foreach ($val["list"] as $value) { + if (isset($value['file']) == FALSE) { + die("[ERROR] Missing JSON data (list): file"); + } + if (isset($value['warning']) == FALSE) { + die("[ERROR] Missing JSON data (list): warning"); + } + if (isset($value['error']) == FALSE) { + die("[ERROR] Missing JSON data (list): error"); + } + array_push($newJsonData, array("file" => $value['file'], "warning" => $value['warning'], "error" => $value['error'])); + } +} +$dataJSON = json_encode($newJsonData); + +list($userName, $libName) = explode("/", $_POST['REPO'], 2); +//die("[ERROR] test : ".$userName." ".$libName); +if ($userName == "") { + die("[ERROR] missing the user-name in '".$_POST['REPO']."'"); +} +if ($libName == "") { + die("[ERROR] missing the lib-name in '".$_POST['REPO']."'"); +} + +include_once("connect.php"); +@include_once("connect_server.php"); + +$WARNING_bdd = mysqli_connect($sqlServer, $sqlLogin, $sqlPass, $sqlBDD); +/* Check connection */ +if (mysqli_connect_errno()) { + die("[ERROR] my-SQL-connection ERROR: '".mysqli_connect_error()."'"); +} + +$idGroup = -1; +// first step : check if the group exist ... +$sql = " SELECT * FROM `CI_group`" + ." WHERE `CI_group`.`user-name` = '".$userName."'" + ." AND `CI_group`.`lib-name` = '".$libName."'" + ." AND `CI_group`.`lib-branch` = '".$_POST['LIB_BRANCH']."'" + ." LIMIT 1"; +$result = $WARNING_bdd->query($sql); +$exist = TRUE; +if ($result == NULL) { + // no result ... + $exist = FALSE; +} +//echo("find result : ".$result); + +if ($result->num_rows > 0) { + $userGroup = $result->fetch_assoc(); + $idGroup = $userGroup['id']; +} else { + $exist = FALSE; +} +if ($exist == FALSE) { + // create a new one ... + $sql = " INSERT INTO `CI_group` (`user-name`, `lib-name`, `lib-branch`)" + ." VALUES ('".$userName."'," + ." '".$libName."'," + ." '".$_POST['LIB_BRANCH']."')"; + $result = $WARNING_bdd->query($sql); + if ($result == TRUE) { + $exist == TRUE; + $idGroup = $WARNING_bdd->insert_id; + } else { + echo "[ERROR] Can not CREATE new group ..."; + } +} + +if ($idGroup <= -1) { + echo("[ERROR] can not create or find group"); +} else { + $sql = " INSERT INTO `WARNING_list` (`time`, `id-group`, `sha1`, `warning`, `error`)" + ." VALUES ('".time()."'," + ." '".$idGroup."'," + ." '".$_POST['SHA1']."'," + ." '".$val["warning"]."'," + ." '".$val["error"]."')"; + //echo $sql; + $result = $WARNING_bdd->query($sql); + if ($result == FALSE) { + echo("[ERROR] Can not register in db ... (LIST)"); + } else { + // get the id inserted + $idList = $WARNING_bdd->insert_id; + // try to update the curent values: + $sql = " UPDATE `WARNING_snapshot`" + ." SET `WARNING_snapshot`.`id-list` = '".$idList."'" + ." , `WARNING_snapshot`.`json` = '".$dataJSON."'" + ." WHERE `WARNING_snapshot`.`id-group` = '".$idGroup."'"; + $result = $WARNING_bdd->query($sql); + if ($result == TRUE) { + echo("[OK] registered done"); + } else { + $sql = " INSERT INTO `WARNING_snapshot` (`id-group`, `id-list`, `json`)" + ." VALUES ('".$idGroup."'," + ." '".$idList."'," + ." '".$dataJSON."')"; + $result = $WARNING_bdd->query($sql); + if ($result == TRUE) { + echo("[OK] registered done"); + } else { + echo("[ERROR] Can not register in db ... (snapshot)"); + } + } + } +} +// simply close link with the DB... +$WARNING_bdd->close(); + +?> \ No newline at end of file diff --git a/warning_send.py b/warning_send.py new file mode 100755 index 0000000..c5a854b --- /dev/null +++ b/warning_send.py @@ -0,0 +1,198 @@ +#!/usr/bin/python +## +## @author Edouard DUPIN +## +## @copyright 2012, Edouard DUPIN, all right reserved +## +## @license APACHE v2.0 (see license file) +## +import urllib, urllib2 +import sys +import os +import argparse +import fnmatch + + +parser = argparse.ArgumentParser() +parser.add_argument("-u", "--url", help="server URL", + default="http://atria-soft.com/ci/warning/inject") +parser.add_argument("-r", "--repo", help="Curent repositoty (generic github name (userName/repoName)", + default="") +parser.add_argument("-s", "--sha1", help="Sha1 on the commit (git) (256 char limited)", + default="") +parser.add_argument("-b", "--branch", help="branch of the repository (default master)", + default="") +################### +## Choice 1 ## +################### +parser.add_argument("-j", "--json", help="all data to send ... (json file NOT json data)", + default="") +################### +## Choice 2 ## +################### +parser.add_argument("--find-path", help="recursive path finding all file with the regex value (--regex)", + default="out/") +parser.add_argument("--extention", help="file extention where is stored the data of warnings (default : 'warning')", + default="warning") +parser.add_argument("--regex", help="Filtering the path finding element (default '*')", + default="*") +parser.add_argument("--rm-path", help="remove path in the output file name", + action="store_true") +################### +## Choice 3 ## +################### +parser.add_argument("--warning", help="if not use JSON file: simply generate the nb warning lines in the lib/program", + default=-1, + type=int) +parser.add_argument("--error", help="if not use JSON file: simply generate the nb error lines in the lib/program", + default=-1, + type=int) +################### +## Choice 4 ## +################### +parser.add_argument("--test", help="test value (local server ...)", + action="store_true") +args = parser.parse_args() + +if args.test == True: + args.url = 'http://127.0.0.1/ci/warning/inject.php' + args.repo = 'HeeroYui/test' + args.sha1 = '' + args.branch = 'master' + json_data = '{"count":5200,"list":[{"file":"test/plop.cpp","count-warning":57,"count-error":3}]}' +else: + if args.json != "": + if args.warning >= 0: + print("[ERROR] (local) set 'warning' parameter with a json file") + exit(-2) + if args.error >= 0: + print("[ERROR] (local) set 'error' parameter with a json file") + exit(-2) + if args.find_path >= 0: + print("[ERROR] (local) set 'find-path' parameter with a json file") + exit(-2) + if args.regex >= 0: + print("[ERROR] (local) set 'regex' parameter with a json file") + exit(-2) + if not os.path.isfile(args.json): + print("[ERROR] (local) can not read json file" + args.json) + exit(-2) + file = open(args.json, "r") + json_data = file.read() + file.close() + if len(json_data) <= 0: + print("[ERROR] (local) json file is empty") + exit(-2) + elif args.warning >= 0: + if args.find_path >= 0: + print("[ERROR] (local) set 'find-path' parameter with 'count'") + exit(-2) + if args.regex >= 0: + print("[ERROR] (local) set 'regex' parameter with 'count'") + exit(-2) + if args.error < 0: + args.error = 0 + json_data = '{"warning":' + args.warning + ',"error":' + args.error + ',"list":[]}' + else: + if args.find_path == "": + print("[ERROR] (local) set 'find-path' parameter empty") + exit(-2) + if args.regex == "": + print("[ERROR] (local) set 'regex' parameter empty") + exit(-2) + # get all the requested files : + all_files = [] + for root, dirnames, filenames in os.walk(args.find_path): + # filter with extention ... + filesss = fnmatch.filter(filenames, "*." + args.extention) + for filename in filesss: + file = os.path.join(root, filename) + all_files.append(file) + # filter with the regular expression + all_files = fnmatch.filter(all_files, args.regex) + all_files2 = [] + for elem in all_files: + file = elem[len(args.find_path):-len(args.extention)-1] + all_files2.append(file) + print("file : " + file); + all_files = all_files2 + result = []; + total_warning_count = 0 + total_error_count = 0 + # parse all files needed: + for elem in all_files: + file = open(args.find_path + elem + "." + args.extention, "r") + data = file.read() + file.close() + if len(data) == 0: + # no warning and no error posible + result.append([elem, 0, 0]) + else: + lines = data.split("\n") + error_count = 0 + warning_count = 0 + for line in lines: + warning_count += line.count('warning:') + error_count += line.count('error:') + total_warning_count += warning_count + total_error_count += error_count + result.append([elem, warning_count, error_count]) + print("result : " + str(result)) + + # create the minimal json file: + json_data = '{\n\t"warning":' + str(total_warning_count) + ',\n\t"error":' + str(total_error_count) + ',\n\t"list":[\n' + first = True + for elem in result: + if first == True: + first = False + json_data += '\t\t{\n' + else: + json_data += '\t\t}, {\n' + json_data += '\t\t\t"file":"' + elem[0] + '",\n' + json_data += '\t\t\t"warning":"' + str(elem[1]) + '",\n' + json_data += '\t\t\t"error":"' + str(elem[2]) + '"\n' + if first == False: + json_data += '\t\t}\n' + json_data += '\t]\n}' + +print("json data: " + str(json_data)) + +# todo : check if repo is contituated wit a "/" ... +# if repo, sha1 and branch is not set, we try to get it with travis global environement variable : +if args.repo == "": + args.repo = os.environ.get('TRAVIS_REPO_SLUG') + if args.repo == None: + print("[ERROR] (local) missing 'repo' parameter can not get travis env variable") + exit(-2) +if args.sha1 == "": + args.sha1 = os.environ.get('TRAVIS_COMMIT') + if args.sha1 == None: + args.sha1 = "" + +if args.branch == "": + args.branch = os.environ.get('TRAVIS_BRANCH') + if args.branch == None: + args.branch = "" + +print(" url = " + args.url) +print(" repo = " + args.repo) +print(" sha1 = " + args.sha1) +print(" branch = " + args.branch) +print(" json_data len = " + str(len(json_data))) + +data = urllib.urlencode({'REPO':args.repo, + 'SHA1':args.sha1, + 'LIB_BRANCH':args.branch, + 'JSON_FILE':json_data}) + +req = urllib2.Request(args.url, data) +response = urllib2.urlopen(req) +#print response.geturl() +#print response.info() +return_data = response.read() +print return_data +if return_data[:7] == "[ERROR]": + exit(-1) + +exit(0) + diff --git a/warning_thumb.php b/warning_thumb.php new file mode 100644 index 0000000..9f4155b --- /dev/null +++ b/warning_thumb.php @@ -0,0 +1,131 @@ +USER = ".$_GET['USER']); +echo("
LIB_NAME = ".$_GET['LIB_NAME']); +echo("
branch = ".$_GET['branch']); +die("
die"); +*/ +header("Content-Type: image/svg+xml"); +header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 +header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date dans le passé +/* +header('Content-Type: image/svg+xml'); +echo ''; +$c = (int)(($x*$y)/$scaler); +$prev = 0; +foreach($rgb as $k=>$v){ + if($v > 0) { + $r = ($k >> 16) & 0xFF; + $g = ($k >> 8) & 0xFF; + $b = $k & 0xFF; + $hex = str_pad(dechex($r),2,'0',STR_PAD_LEFT).str_pad(dechex($g),2,'0',STR_PAD_LEFT).str_pad(dechex($b),2,'0',STR_PAD_LEFT); + echo ''; + echo "\n"; + $prev += (int)($v/$scaler); + } +} +echo ''; +*/ + + +function errorSVG($_name) { + echo(''); + echo(' '); + echo(' '); + echo(' '); + echo(' '); + echo(' '); + echo(' '); + echo(' WAR: '.$_name.''); + echo(' WAR: '.$_name.''); + echo(' '); + echo(''); + exit(); +} + +include_once("connect.php"); + +@include_once("connect_server.php"); + +$WARNING_bdd = mysqli_connect($sqlServer, $sqlLogin, $sqlPass, $sqlBDD); +// Check connection +if (mysqli_connect_errno()) { + errorSVG("SQL ERROR"); +} +// check if all is here ... +$branch = "master"; +if (isset($_GET['USER']) == FALSE) { + errorSVG("USER??"); +} else if (isset($_GET['LIB_NAME']) == FALSE) { + errorSVG("LIB_NAME??"); +} +if (isset($_GET['branch']) == TRUE) { + $branch = $_GET['branch']; +} + +//echo "register ".$_POST['JSON_FILE']; +$sql = "SELECT `WARNING_list`.`warning` " + ." , `WARNING_list`.`error` " + ." FROM `WARNING_list`" + ." , `CI_group`" + ." WHERE `CI_group`.`user-name` = '".$_GET['USER']."'" + ." AND `CI_group`.`lib-name` = '".$_GET['LIB_NAME']."'" + ." AND `CI_group`.`lib-branch` = '".$branch."'" + ." AND `CI_group`.`id` = `WARNING_list`.`id-group`" + ." ORDER BY `WARNING_list`.`time` DESC" + ." LIMIT 1"; +$result = $WARNING_bdd->query($sql); +//echo("sql : ".$sql); +if ($result == NULL) { + errorSVG("UNKNOW"); +} +//echo("find result : ".$result); + +if ($result->num_rows > 0) { + if ($result->num_rows > 1) { + errorSVG("To much value"); + } + $row = $result->fetch_assoc(); +} else { + errorSVG("No Value"); +} + +$warningCount = $row['warning'] + $row['error']; + +//some warningCount value : +if ($warningCount < 5 ) { + $color = "4c1"; +} else if ($warningCount < 20 ) { + $color = "c71"; +} else if ($warningCount < 50 ) { + $color = "c1c"; +} else { + $color = "c11"; +} + +echo(''); +echo(' '); +echo(' '); +echo(' '); +echo(' '); +echo(' '); +echo(' '); +#echo(' '); +echo(' '); +echo(' '); +echo(' warning'); +echo(' warning'); +echo(' '.$warningCount.''); +echo(' '.$warningCount.''); +echo(' '); +echo(''); + +// simply close link with the DB... +$WARNING_bdd->close(); +?> \ No newline at end of file