Skip to content

Commit

Permalink
Record gitlab host scheme, update frontend to use and show detected host
Browse files Browse the repository at this point in the history
  • Loading branch information
bobvandevijver committed Nov 24, 2021
1 parent 992ca5c commit 191b54a
Show file tree
Hide file tree
Showing 16 changed files with 204 additions and 120 deletions.
1 change: 1 addition & 0 deletions assets/shims-tsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ declare global {
interface Window {
SENTRY_DSN: string;
SENTRY_RELEASE: string;
HAS_MULTIPLE_HOSTS: boolean;
}

interface Array<T> {
Expand Down
54 changes: 35 additions & 19 deletions assets/vue/pages/dashboard/cards/OutdatedProjectsCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@
<a
v-b-tooltip.hover.topleft
class="pointer text-secondary"
:title="'outdated-project.button.show-diff'|trans"
@click="showDiff(row.item)">
:href="row.item.gitlab_diff_url"
target="_blank"
:title="'outdated-project.button.show-diff'|trans">
<font-awesome-icon icon="search"/>
</a>

Expand Down Expand Up @@ -175,10 +176,6 @@
}
}
protected showDiff(project: OutdatedProject): void {
window.open(project.gitlab_diff_url, '_blank');
}
private async loadOutdatedProjects(): Promise<void> {
const response: AxiosResponse<OutdatedProject[]> =
await this.$http.get(this.$sfRouter.generate('app_api_project_outdated'));
Expand All @@ -190,26 +187,45 @@
}
protected get fields(): BvTableFieldArray {
return [
const fields: BvTableFieldArray = [
{
key: 'project.name',
label: this.$translator.trans('project.field.name'),
sortable: true,
class: 'project-name',
}, {
key: 'master_sha',
label: this.$translator.trans('outdated-project.field.master-sha'),
class: 'project-sha',
}, {
key: 'production_sha',
label: this.$translator.trans('outdated-project.field.production-sha'),
class: 'project-sha',
}, {
key: '_actions',
label: this.$translator.trans('general.actions'),
class: 'project-action',
},
];
if (window.HAS_MULTIPLE_HOSTS) {
fields.push({
key: 'project.host',
label: this.$translator.trans('project.field.host'),
sortable: true,
class: 'project-host',
formatter: (value: string) => {
return value
? value
: this.$translator.trans('general.unknown');
},
});
}
fields.push(...[{
key: 'master_sha',
label: this.$translator.trans('outdated-project.field.master-sha'),
class: 'project-sha',
}, {
key: 'production_sha',
label: this.$translator.trans('outdated-project.field.production-sha'),
class: 'project-sha',
}, {
key: '_actions',
label: this.$translator.trans('general.actions'),
class: 'project-action',
}]);
return fields;
}
protected get isBusy(): boolean {
Expand Down
46 changes: 32 additions & 14 deletions assets/vue/pages/dashboard/cards/ProjectCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
} catch (e) {
const error = e as AxiosError;
if (error.response && error.response.status === 400) {
this.errorMessage = (error.response.data as {reason: string}).reason;
this.errorMessage = (error.response.data as { reason: string }).reason;
return;
}
throw e;
Expand Down Expand Up @@ -460,7 +460,7 @@
}
protected get fields(): BvTableFieldArray {
return [
const fields: BvTableFieldArray = [
{
key: 'current_state',
label: this.$translator.trans('project.field.current-state'),
Expand All @@ -471,22 +471,40 @@
label: this.$translator.trans('project.field.name'),
sortable: true,
class: 'project-name',
}, {
key: 'last_event',
label: this.$translator.trans('project.field.last-event'),
},
];
if (window.HAS_MULTIPLE_HOSTS) {
fields.push({
key: 'host',
label: this.$translator.trans('project.field.host'),
sortable: true,
formatter: (value) => {
class: 'project-host',
formatter: (value: string) => {
return value
? this.$moment(value).format('YYYY-MM-DD HH:mm:ss')
: '-';
? value
: this.$translator.trans('general.unknown');
},
class: 'project-last-event',
}, {
key: '_actions',
label: this.$translator.trans('general.actions'),
class: 'project-action',
});
}
fields.push(...[{
key: 'last_event',
label: this.$translator.trans('project.field.last-event'),
sortable: true,
formatter: (value: string) => {
return value
? this.$moment(value).format('YYYY-MM-DD HH:mm:ss')
: '-';
},
];
class: 'project-last-event',
}, {
key: '_actions',
label: this.$translator.trans('general.actions'),
class: 'project-action',
}]);
return fields;
}
protected get environmentFields(): BvTableFieldArray {
Expand Down
8 changes: 4 additions & 4 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ services:
$gitlabUrl: '%gitlab.url%'
$gitlabToken: '%gitlab.token%'

App\Provider\Gitlab\ProjectPathService:
arguments:
$gitlabUrl: '%gitlab.url%'

App\Provider\Irker\EventHandlers\OutgoingIrcMessageEventHandler:
arguments:
$irkerServer: '%irker.server%'
Expand Down Expand Up @@ -115,10 +119,6 @@ services:
$jwtSecret: "%env(string:key:jwt_secret:json:file:resolve:SECRETS_FILE)%"
$tokenValidity: '%env(TOKEN_VALIDITY)%'

App\Serializer\Entity\ProjectSerializer:
arguments:
$gitlabUrl: '%gitlab.url%'

App\Service\ProjectService:
arguments:
$remoteConfigurationServices: !tagged_locator { tag: 'remote_configuration_service' }
Expand Down
36 changes: 36 additions & 0 deletions migrations/2021/11/Version20211120173119.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20211120173119 extends AbstractMigration
{
public function getDescription(): string
{
return 'Also store project scheme';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE project ADD host_scheme VARCHAR(255) DEFAULT NULL AFTER host');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE project DROP host_scheme');
}

public function isTransactional(): bool
{
return false;
}
}
3 changes: 2 additions & 1 deletion src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class DefaultController extends AbstractController
{
/**
* @Route("/", name="index", options={"expose"=true})
*/
public function index()
public function index(): Response
{
// Create the response and disable all forms of caching for it
$response = ($this->render('base.html.twig'))
Expand Down
21 changes: 21 additions & 0 deletions src/Entity/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ class Project
*/
private ?string $host = null;

/**
* The last detected gitlab host scheme for this project
*
* @var string|null
*
* @ORM\Column(type="string", nullable=true)
*/
private ?string $hostScheme = null;

/**
* The last event recorded for this project
*
Expand Down Expand Up @@ -90,6 +99,18 @@ public function setHost(?string $host): self
return $this;
}

public function getHostScheme(): ?string
{
return $this->hostScheme;
}

public function setHostScheme(?string $hostScheme): self
{
$this->hostScheme = $hostScheme;

return $this;
}

public function getLastEvent(): ?DateTimeImmutable
{
return $this->lastEvent;
Expand Down
9 changes: 6 additions & 3 deletions src/EventHandlers/ProjectEventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ public function onEvent(ProjectEvent $event)
if (!$project = $this->projectRepository->findOneByNameAndHost($event->getProjectName(), $event->getProjectHost())) {
$project = (new Project())
->setName($event->getProjectName())
->setHost($event->getProjectHost());
->setHost($event->getProjectHost())
->setHostScheme($event->getProjectHostScheme());
}

// Update last event
$project->setLastEvent($this->dateTimeProvider->utcNow());
// Update last event and host scheme
$project
->setLastEvent($this->dateTimeProvider->utcNow())
->setHostScheme($event->getProjectHostScheme());

if ($project->getHost() === NULL) {
$project->setHost($event->getProjectHost());
Expand Down
11 changes: 9 additions & 2 deletions src/Events/Project/AbstractProjectEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
abstract class AbstractProjectEvent
{
private string $projectHost;
private string $projectHostScheme;

/**
* AbstractProjectEvent constructor.
Expand All @@ -18,13 +19,14 @@ abstract class AbstractProjectEvent
*/
public function __construct(
private string $projectName,
string $projectHost,
string $projectHost,
private string $user,
private string $iid,
private string $url,
private string $action)
{
$this->projectHost = parse_url($projectHost, PHP_URL_HOST);
$this->projectHost = parse_url($projectHost, PHP_URL_HOST);
$this->projectHostScheme = parse_url($projectHost, PHP_URL_SCHEME);
}

public function getProjectName(): string
Expand All @@ -37,6 +39,11 @@ public function getProjectHost(): string
return $this->projectHost;
}

public function getProjectHostScheme(): string
{
return $this->projectHostScheme;
}

public function getUser(): string
{
return $this->user;
Expand Down
2 changes: 2 additions & 0 deletions src/Events/Project/ProjectEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ interface ProjectEvent
public function getProjectName(): string;

public function getProjectHost(): string;

public function getProjectHostScheme(): string;
}
27 changes: 6 additions & 21 deletions src/Provider/Gitlab/GitlabApiConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,14 @@ class GitlabApiConnector
{
private const API_BASE = 'api/v4';

/**
* @var string
*/
private $gitlabUrl;
/**
* @var HttpClientInterface
*/
private $httpClient;
/**
* @var SerializerInterface
*/
private $serializer;
private HttpClientInterface $httpClient;

public function __construct(SerializerInterface $serializer, string $gitlabUrl, string $gitlabToken)
public function __construct(
private SerializerInterface $serializer,
private ProjectPathService $projectPathService,
private string $gitlabUrl,
string $gitlabToken)
{
$this->serializer = $serializer;
$this->gitlabUrl = $gitlabUrl;

$this->httpClient = HttpClient::createForBaseUri($gitlabUrl, [
'auth_bearer' => $gitlabToken,
]);
Expand Down Expand Up @@ -80,9 +70,4 @@ public function projectApi(?Project $project, string $method, string $endpoint,
throw new GitlabRemoteCallFailedException(NULL, $e);
}
}

public function projectDiffUrl(Project $project, string $source, string $target): string
{
return sprintf('%s/%s/-/compare/%s...%s', $this->gitlabUrl, $project->getName(), $target, $source);
}
}
Loading

0 comments on commit 191b54a

Please sign in to comment.