Skip to content
This repository was archived by the owner on Feb 19, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ We have php5-curl dependency, if you have issues related to curl_init() please i
sudo apt-get install php5-curl
```

## Alternative Installation (using phar)

Setup codacy-coverage as phar, you can simply download a pre-compiled and ready-to-use version as a phar to any directory. Simply download the latest `codacy-coverage.phar` file from our [releases page](https://github.com/codacy/php-codacy-coverage/releases):

[Latest release](https://github.com/codacy/php-codacy-coverage/releases/latest)

That's it already.

## Updating Codacy

To update Codacy, you will need your project API token. You can find the token in Project -> Settings -> Integrations -> Project API.
Expand Down
9 changes: 9 additions & 0 deletions box.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"directories": [
"src",
"vendor"
],
"main": "bin/codacycoverage",
"output": "build/codacy-coverage.phar",
"stub": true
}
10 changes: 10 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ dependencies:
pre:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install -n
- go get github.com/aktau/github-release
- wget -O box.phar https://github.com/box-project/box2/releases/download/2.7.5/box-2.7.5.phar

test:
post:
- php vendor/bin/phpunit --coverage-clover build/coverage/xml tests
- php bin/codacycoverage clover build/coverage/xml

deployment:
release:
tag: /[0-9]+(\.[0-9]+)*/
commands:
- php -d phar.readonly=0 box.phar build
- git config user.name $CIRCLE_PROJECT_USERNAME
- github-release upload --user $CIRCLE_PROJECT_USERNAME --repo $CIRCLE_PROJECT_REPONAME --tag $CIRCLE_TAG --name codacy-coverage.phar --file build/codacy-coverage.phar
21 changes: 20 additions & 1 deletion src/Codacy/Coverage/Util/CodacyApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ function __construct($baseUrl, $projectToken)
*/
public function sendCoverage($commit, $data)
{
$tempCertFile = $this->dumpCertificateBundle();

$url = $this->baseUrl . "/2.0/coverage/" . $commit . "/php";

$curl = curl_init($url);

curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
Expand All @@ -37,12 +40,14 @@ public function sendCoverage($commit, $data)
"project_token: " . $this->projectToken
)
);
curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
curl_setopt($curl, CURLOPT_CAINFO, $tempCertFile);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

$json_response = curl_exec($curl);

unlink($tempCertFile);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ($status < 200 || $status > 201) {
Expand All @@ -63,4 +68,18 @@ public function sendCoverage($commit, $data)
return $json['error'];
}
}

/**
* Store certificate bundle to temporary file to be available when used within phar context
*
* @return string Full qualified path to temporary file
*/
protected function dumpCertificateBundle()
{
$tempCertFile = tempnam(sys_get_temp_dir(), 'cacert');

copy(dirname(__FILE__) . '/cacert.pem', $tempCertFile);

return $tempCertFile;
}
}