PrestaShop / prestashop-retro

Retrospectives from the Core and Product teams
0 stars 1 forks source link

Process release modules #52

Closed Progi1984 closed 4 years ago

matks commented 4 years ago

We need to build a tool that is able to

I started a POC like this:

<?php

// This file is generated by Composer
require_once __DIR__ . '/vendor/autoload.php';

$client = new \Github\Client();
$client->authenticate($githubToken, null, Github\Client::AUTH_HTTP_TOKEN);

$organizationApi = $client->api('organization');

$paginator  = new Github\ResultPager($client);
$parameters = array('prestashop');
$repos = $paginator->fetchAll($organizationApi, 'repositories', $parameters);

$reporting = [];
foreach ($repos as $repoID => $repoData) {
    $repositoryName = $repoData['name'];

    // check for a 'dev' or 'develop' branch
    $isThereADevBranch = false;
    $devBranchName = null;
    $devBranchData = null;
    $masterBranchData = null;

    $branches = $client->api('repo')->branches('prestashop', $repositoryName);
    foreach ($branches as $branchID => $branchData) {
        $branchName = $branchData['name'];

        if ($branchName === 'dev') {
            $isThereADevBranch = true;
            $devBranchName = 'dev';
            $devBranchData = $branchData;
        }
        if ($branchName === 'develop') {
            $isThereADevBranch = true;
            $devBranchName = 'develop';
            $devBranchData = $branchData;
        }
        if ($branchName === 'master') {
            $masterBranchData = $branchData;
        }
    }

    if ($isThereADevBranch === false) {
        $reporting[$repositoryName] = 'no branch dev';
        continue;
    }

    $masterLastCommitSha = $masterBranchData['commit']['sha'];
    $devLastCommitSha = $devBranchData['commit']['sha'];

    if ($masterLastCommitSha === $devLastCommitSha) {
        $reporting[$repositoryName] = 'master and dev are sync';
        continue;
    }

    $commits = $client->api('repo')->commits()->compare(
        'prestashop',
        $repositoryName,
        $masterLastCommitSha,
        $devLastCommitSha
    );
    $reporting[$repositoryName] = 'master and dev have a difference of '.$commits['total_commits'].' commits !!!';
}

foreach ($reporting as $repoName => $status) {
    echo ' - '.$repoName.' : '.$status.PHP_EOL;
}

/*
$pullRequest = $client->api('pull_request')->create('prestashop', 'gsitemap', array(
    'base'  => 'master',
    'head'  => 'dev',
    'title' => 'Release PR',
    'body'  => 'Release'
));*/
matks commented 4 years ago

(it uses knplabs/github-api)

PierreRambaud commented 4 years ago

@matks FYI this test will never be true

    if ($masterLastCommitSha === $devLastCommitSha) {
        $reporting[$repositoryName] = 'master and dev are sync';
        continue;
    }

Example: https://github.com/PrestaShop/ps_linklist/commits/dev https://github.com/PrestaShop/ps_linklist/commits/master the latest on the master branch should always be a Merge commit

matks commented 4 years ago

PR done https://github.com/PrestaShop/prestashop-retro/projects/1