Skip to content
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
39 changes: 39 additions & 0 deletions app/GraphQL/Mutations/CreateRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace App\GraphQL\Mutations;

use App\Models\Project;
use App\Models\Repository;
use Illuminate\Support\Facades\Gate;

final class CreateRepository extends AbstractMutation
{
public ?Repository $repository = null;

/**
* @param array{
* projectId: int,
* url: string,
* username: string,
* password: string,
* branch: string,
* } $args
*/
public function __invoke(null $_, array $args): self
{
$project = Project::find((int) $args['projectId']);

Gate::authorize('createRepository', $project);

$this->repository = $project?->repositories()->create([
'url' => $args['url'],
'username' => $args['username'],
'password' => $args['password'],
'branch' => $args['branch'],
]);

return $this;
}
}
27 changes: 27 additions & 0 deletions app/GraphQL/Mutations/DeleteRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace App\GraphQL\Mutations;

use App\Models\Repository;
use Illuminate\Support\Facades\Gate;

final class DeleteRepository extends AbstractMutation
{
/**
* @param array{
* repositoryId: int,
* } $args
*/
public function __invoke(null $_, array $args): self
{
$repository = Repository::find((int) $args['repositoryId']);

Gate::authorize('deleteRepository', $repository?->project);

$repository?->delete();

return $this;
}
}
14 changes: 14 additions & 0 deletions app/Models/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace App\Models;

use Database\Factories\RepositoryFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* @property int $id
Expand All @@ -17,6 +20,9 @@
*/
class Repository extends Model
{
/** @use HasFactory<RepositoryFactory> */
use HasFactory;

protected $table = 'repositories';

public $timestamps = false;
Expand All @@ -31,4 +37,12 @@ class Repository extends Model
protected $casts = [
'projectid' => 'integer',
];

/**
* @return BelongsTo<Project, $this>
*/
public function project(): BelongsTo
{
return $this->belongsTo(Project::class, 'projectid');
}
}
10 changes: 10 additions & 0 deletions app/Policies/ProjectPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ public function updatePinnedTestMeasurementOrder(User $currentUser, Project $pro
return $this->update($currentUser, $project);
}

public function createRepository(User $currentUser, Project $project): bool
{
return $this->update($currentUser, $project);
}

public function deleteRepository(User $currentUser, Project $project): bool
{
return $this->update($currentUser, $project);
}

private function isLdapControlledMembership(Project $project): bool
{
// If a LDAP filter has been specified and LDAP is enabled, CDash controls the entire members list.
Expand Down
6 changes: 6 additions & 0 deletions app/cdash/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ add_feature_test_in_transaction(/Feature/GraphQL/BuildErrorTypeTest)

add_feature_test_in_transaction(/Feature/GraphQL/CommentTypeTest)

add_feature_test_in_transaction(/Feature/GraphQL/RepositoryTypeTest)

add_feature_test_in_transaction(/Feature/RouteAccessTest)

add_feature_test_in_transaction(/Feature/Monitor)
Expand Down Expand Up @@ -290,6 +292,10 @@ add_feature_test_in_transaction(/Feature/GraphQL/Mutations/DeletePinnedTestMeasu

add_feature_test_in_transaction(/Feature/GraphQL/Mutations/UpdatePinnedTestMeasurementOrderTest)

add_feature_test_in_transaction(/Feature/GraphQL/Mutations/CreateRepositoryTest)

add_feature_test_in_transaction(/Feature/GraphQL/Mutations/DeleteRepositoryTest)

add_feature_test_in_transaction(/Feature/GlobalInvitationAcceptanceTest)

add_feature_test_in_transaction(/Feature/GraphQL/GlobalInvitationTypeTest)
Expand Down
28 changes: 28 additions & 0 deletions database/factories/RepositoryFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Database\Factories;

use App\Models\Repository;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
* @extends Factory<Repository>
*/
class RepositoryFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'url' => fake()->url(),
'username' => Str::uuid()->toString(),
'password' => Str::uuid()->toString(),
'branch' => Str::uuid()->toString(),
];
}
}
54 changes: 54 additions & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ type Mutation {
previous maximum position. Only the relative order is guaranteed.
"""
updatePinnedTestMeasurementOrder(input: UpdatePinnedTestMeasurementOrderInput! @spread): UpdatePinnedTestMeasurementOrderMutationPayload! @field(resolver: "UpdatePinnedTestMeasurementOrder")

"Add a repository to a project. Cannot retrieve password once set."
createRepository(input: CreateRepositoryInput! @spread): CreateRepositoryMutationPayload! @field(resolver: "CreateRepository")

"Delete a repository by ID."
deleteRepository(input: DeleteRepositoryInput! @spread): DeleteRepositoryMutationPayload! @field(resolver: "DeleteRepository")
}


Expand Down Expand Up @@ -336,6 +342,9 @@ type Project {
alongside Test details throughout the site.
"""
pinnedTestMeasurements: [PinnedTestMeasurement!]! @hasMany(type: CONNECTION) @orderBy(column: "position")

"Repositories."
repositories: [Repository!]! @hasMany(type: CONNECTION) @orderBy(column: "id")
}


Expand Down Expand Up @@ -648,6 +657,39 @@ type UpdatePinnedTestMeasurementOrderMutationPayload implements MutationPayloadI
}


input CreateRepositoryInput {
projectId: ID!

url: Url!

username: String!

password: String!

branch: String!
}


type CreateRepositoryMutationPayload implements MutationPayloadInterface {
"Optional error message."
message: String

"The newly created repository."
repository: Repository
}


input DeleteRepositoryInput {
repositoryId: ID!
}


type DeleteRepositoryMutationPayload implements MutationPayloadInterface {
"Optional error message."
message: String
}


"Configure."
type Configure {
"Unique primary key."
Expand Down Expand Up @@ -1382,3 +1424,15 @@ type Comment {

user: User!
}


type Repository {
"Unique primary key."
id: ID!

url: Url!

username: String!

branch: String!
}
12 changes: 12 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,24 @@ parameters:
count: 1
path: app/GraphQL/Mutations/CreatePinnedTestMeasurement.php

-
rawMessage: 'Parameter #2 $args (array{projectId: int, url: string, username: string, password: string, branch: string}) of method App\GraphQL\Mutations\CreateRepository::__invoke() should be contravariant with parameter $args (array<string, mixed>) of method App\GraphQL\Mutations\AbstractMutation::__invoke()'
identifier: method.childParameterType
count: 1
path: app/GraphQL/Mutations/CreateRepository.php

-
rawMessage: 'Parameter #1 $args (array{id: int}) of method App\GraphQL\Mutations\DeletePinnedTestMeasurement::mutate() should be contravariant with parameter $args (array<string, mixed>) of method App\GraphQL\Mutations\AbstractMutation::mutate()'
identifier: method.childParameterType
count: 1
path: app/GraphQL/Mutations/DeletePinnedTestMeasurement.php

-
rawMessage: 'Parameter #2 $args (array{repositoryId: int}) of method App\GraphQL\Mutations\DeleteRepository::__invoke() should be contravariant with parameter $args (array<string, mixed>) of method App\GraphQL\Mutations\AbstractMutation::__invoke()'
identifier: method.childParameterType
count: 1
path: app/GraphQL/Mutations/DeleteRepository.php

-
rawMessage: 'Parameter #1 $args (array{email: string, projectId: int, role: App\Enums\ProjectRole}) of method App\GraphQL\Mutations\InviteToProject::mutate() should be contravariant with parameter $args (array<string, mixed>) of method App\GraphQL\Mutations\AbstractMutation::mutate()'
identifier: method.childParameterType
Expand Down
Loading