fix: env vars handled via conf file, add: functional tests

This commit is contained in:
Michael 2024-08-17 18:06:06 +02:00
parent 3d08b14f11
commit 21c4330f16
39 changed files with 416 additions and 172 deletions

View file

@ -3,6 +3,7 @@
namespace App\Http\Controllers\GiteaApiController;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Config;
use Illuminate\Http\Request;
class GiteaApiController extends Controller
@ -16,7 +17,7 @@ class GiteaApiController extends Controller
public function export_closed_issues(Request $req)
{
if ($req->input('token') != getenv('GITEA_TOKEN')) {
if ($req->input('token') != config('app.gitea_token')) {
return redirect('/');
}
$from = $req->input('from_year') . '-' . $req->input('from_month') . '-01';
@ -24,7 +25,7 @@ class GiteaApiController extends Controller
$res = $this->gitea_export->export_issues($from, $to, ['state' => $req->input('issues_type')]);
return view('backend', [
'token' => getenv('GITEA_TOKEN'),
'token' => config('app.gitea_token'),
'download' => $res
]);
}

View file

@ -8,6 +8,8 @@ use App\Http\Controllers\CsvController\CsvCostCalc\CsvCostCalc;
use App\Http\Controllers\IssueValidationController;
use App\Http\Controllers\ThirdPartyServices\ThirdPartyServices;
use OwenVoke\Gitea\Client;
use Illuminate\Support\Facades\Config;
class GiteaExport extends Controller
{
@ -25,23 +27,33 @@ class GiteaExport extends Controller
private $third_party_services;
private $email_send_allow;
public function __construct()
public function __construct(
$calculate_agent_cost = false,
$third_party_integrations_allow = false,
$third_party_integrations_nextcloud = false,
$third_party_integrations_open_project = false,
$email_send_allow = false
)
{
$this->third_party_integrations_allow = env('THIRD_PARTY_INTEGRATIONS_ALLOW', false);
$this->calculate_agent_cost = env('GITEA_CALCULATE_AGENT_COST', false);
$this->email_send_allow = env('EMAIL_SEND_ALLOW', false);
$this->email_address = env('EMAIL_ADDRESS', false);
$this->email_prefix_subject = env('EMAIL_PREFIX_SUBJECT', false);
$this->giteaClient = new Client(null, null, getenv('GITEA_URL'));
$this->giteaClient->authenticate(getenv('GITEA_TOKEN'), null, Client::AUTH_ACCESS_TOKEN);
$this->third_party_integrations_allow = $third_party_integrations_allow || config('app.third_party_integrations_allow', false);
$this->calculate_agent_cost = $calculate_agent_cost || config('app.gitea_calculate_agent_cost', false);
$this->email_address = config('email.email_address', false);
$this->email_prefix_subject = config('email.email_prefix_subject', false);
$gitea_url = config('app.gitea_url');
$gitea_token = config('app.gitea_token');
$this->giteaClient = new Client(null, null, $gitea_url);
$this->giteaClient->authenticate($gitea_token, null, Client::AUTH_ACCESS_TOKEN);
$this->issue_validation_controller = new IssueValidationController();
$this->csv_controller = new CsvController();
$this->csv_controller = new CsvController($this->calculate_agent_cost);
$this->gitea_fetch = new GiteaFetch();
$this->csv_cost_calc = new CsvCostCalc();
$this->third_party_services = new ThirdPartyServices();
$this->csv_cost_calc = new CsvCostCalc($this->calculate_agent_cost);
$this->third_party_services = new ThirdPartyServices($third_party_integrations_nextcloud, $third_party_integrations_open_project, $email_send_allow);
}
private function handle_repos(string $from_date, string $to_date, array $repositories, array $issues_params){
private function handle_repos(string $from_date, string $to_date, array $repositories, array $issues_params)
{
$data = [];
foreach ($repositories as $repository) {
$issues = $this->gitea_fetch->get_issues($repository['name'], $issues_params);
@ -61,15 +73,15 @@ class GiteaExport extends Controller
function export_issues(string $from_date, string $to_date, array $issues_params)
{
$repositories = $this->gitea_fetch->get_repositories();
$data = $this->handle_repos($from_date, $to_date, $repositories, $issues_params);
$data = $this->handle_repos($from_date, $to_date, $repositories, $issues_params);
if (count($data) > 0) {
$company_agents = $this->calculate_agent_cost ? $this->gitea_fetch->get_company_agents() : [];
$data = $this->csv_cost_calc->sum_costs($data, $company_agents);
$csv_file = $this->csv_controller->create_csv($issues_params['state'], $from_date, $to_date, $data);
if($this->third_party_integrations_allow) {
if ($this->third_party_integrations_allow) {
$this->third_party_services->handle_third_party_services($csv_file['file_name'], $csv_file['file_path'], $data, $company_agents, $from_date, $to_date);
}
isset($csv_file['file_path']) ?? unlink($csv_file['file_path']);
isset($csv_file['file_path']) ?? unlink($csv_file['file_path']);
readfile($csv_file['file_path']);
unlink($csv_file['file_path']);
return true;

View file

@ -19,10 +19,10 @@ class GiteaFetch extends Controller
public function __construct()
{
$this->main_company_organization = getenv('GITEA_MAIN_COMPANY_ORGANIZATION');
$this->partner_organization = getenv('GITEA_PARTNER_ORGANIZATION');
$this->gitea_url = getenv('GITEA_URL');
$this->gitea_token = getenv('GITEA_TOKEN');
$this->main_company_organization = config('app.gitea_main_company_organization');
$this->partner_organization = config('app.gitea_partner_organization');
$this->gitea_url = config('app.gitea_url');
$this->gitea_token = config('app.gitea_token');
$this->giteaClient = new Client(null, null, $this->gitea_url);
$this->giteaClient->authenticate($this->gitea_token, null, Client::AUTH_ACCESS_TOKEN);
}