<commit_before><?php
/*
 * Creates a Github API release using the changelog contents. Attaches ebay-sdk-php.zip
 * and ebay-sdk-php.phar to the release.
 *
 * The OAUTH_TOKEN environment variable is required.
 *
 *     Usage: php gh-release.php X.Y.Z
 */

require __DIR__ . '/../vendor/autoload.php';

use Guzzle\Http\Client;
use Guzzle\Http\Url;
use Guzzle\Stream;

$owner = 'davidtsadler';
$repo = 'ebay-sdk-php';
$token = getenv('OAUTH_TOKEN') or die('An OAUTH_TOKEN environment variable is required');
isset($argv[1]) or die('Usage php gh-release.php X.Y.Z');
$tag = $argv[1];

assert(file_exists(__DIR__ . '/artifacts/ebay-sdk-php.zip'));
assert(file_exists(__DIR__ . '/artifacts/ebay-sdk-php.phar'));

// Grab and validate the tag annotation
chdir(dirname(__DIR__));
$message = `chag contents --tag "$tag"` or die('Chag could not find or parse the tag');

// Create a GitHub client.
$client = new Client('https://api.github.com/');
$client->setDefaultOption('headers/Authorization', "token $token");

// Create the release
$response = $client->post(
    "repos/${owner}/${repo}/releases",
    array('Content-Type' => 'application/json'),
    json_encode(array(
        'tag_name'   => $tag,
        'name'       => "Version {$tag}",
        'body'       => $message,
        'prerelease' => false
    ))
)->send();

// Grab the location of the new release
$url = (string) $response->getHeader('Location');
// Uploads go to uploads.github.com
$uploadUrl = Url::factory($url);
$uploadUrl->setHost('uploads.github.com');

$client->post(
    $uploadUrl . '/assets?name=ebay-sdk-php.zip',
    array('Content-Type' => 'application/zip'),
    fopen(__DIR__ . '/artifacts/ebay-sdk-php.zip', 'r')
)->send();

$client->post(
    $uploadUrl . '/assets?name=ebay-sdk-php.phar',
    array('Content-Type' => 'application/phar'),
    fopen(__DIR__ . '/artifacts/ebay-sdk-php.phar', 'r')
)->send();

echo "Release successfully published to: $url\n";<commit_msg>update: improve git hub release process<commit_after><?php
/*
 * Creates a Github API release using the changelog contents. Attaches ebay-sdk-php.zip
 * and ebay-sdk-php.phar to the release.
 *
 * The OAUTH_TOKEN environment variable is required.
 *
 *     Usage: php gh-release.php X.Y.Z
 */

require __DIR__ . '/../vendor/autoload.php';

use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Uri;
use GuzzleHttp\Psr7;

$owner = 'davidtsadler';
$repo = 'ebay-sdk-php';
$token = getenv('OAUTH_TOKEN') or die('An OAUTH_TOKEN environment variable is required');
isset($argv[1]) or die('Usage php gh-release.php X.Y.Z');
$tag = $argv[1];

assert(file_exists(__DIR__ . '/artifacts/ebay-sdk-php.zip'));
assert(file_exists(__DIR__ . '/artifacts/ebay-sdk-php.phar'));

// Grab and validate the tag annotation
chdir(dirname(__DIR__));
$message = `chag contents --tag "$tag"` or die('Chag could not find or parse the tag');

// Create a GitHub client
$client = new GuzzleHttp\Client([
    'base_uri' => 'https://api.github.com/',
    'headers'  => ['Authorization' => "token $token"],
]);

// Create the release
$response = $client->post("repos/${owner}/${repo}/releases", [
    'json' => [
        'tag_name' => $tag,
        'name'     => "Version {$tag}",
        'body'     => $message,
    ]
]);

// Grab the location of the new release
$url = $response->getHeaderLine('Location');
echo "Release successfully published to: $url\n";

// Uploads go to uploads.github.com
$uploadUrl = new Uri($url);
$uploadUrl = $uploadUrl->withHost('uploads.github.com');

// Upload ebay-sdk-php.zip
$response = $client->post($uploadUrl . '/assets?name=ebay-sdk-php.zip', [
    'headers' => ['Content-Type' => 'application/zip'],
    'body'    => Psr7\try_fopen(__DIR__ . '/artifacts/ebay-sdk-php.zip', 'r')
]);
echo "ebay-sdk-php.zip uploaded to: " . json_decode($response->getBody(), true)['browser_download_url'] . "\n";

// Upload ebay-sdk-php.phar
$response = $client->post($uploadUrl . '/assets?name=ebay-sdk-php.phar', [
    'headers' => ['Content-Type' => 'application/phar'],
    'body'    => Psr7\try_fopen(__DIR__ . '/artifacts/ebay-sdk-php.phar', 'r')
]);
echo "ebay-sdk-php.phar uploaded to: " . json_decode($response->getBody(), true)['browser_download_url'] . "\n";
{'fraction_non_alphanumeric': 0.1896715849595431, 'fraction_numerical': 0.0019038553069966682, 'mean_word_length': 3.8758700696055683, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4470766', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1457, 'n_words': 326}