-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Create automatically a thread on discord when creating a reposi… #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
vassilidev
wants to merge
18
commits into
develop
Choose a base branch
from
feature/52-webhook-to-discord
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5bfc199
feat: Create automatically a thread on discord when creating a reposi…
vassilidev d26f359
Merge remote-tracking branch 'origin/master' into feature/52-webhook-…
vassilidev e3dd70d
Merge branch 'develop' into feature/52-webhook-to-discord
geeksesi 783c25b
#52 feat: add discord enviroments
geeksesi 0a778b1
fix: CI
geeksesi 2f45789
fix: CI test without --detach
geeksesi d10cc1a
Revert "fix: CI test without --detach"
geeksesi 11a4163
chor: config log channels
geeksesi a160ce4
fix: don't throw error. log me please
geeksesi 8e3f652
#fix: maybe better error handling
geeksesi 349388e
feat: handle unvalid commands by bot
geeksesi 6ba9adb
fix: should be input message
geeksesi 3fbbfb8
fix: issue about PR and discord
geeksesi a29a85b
refactor: to queue
geeksesi 21d7bf9
Merge branch 'master' into feature/52-webhook-to-discord
geeksesi a3b27a6
#52 feat: work in progress to send PR to discord
geeksesi e468d03
feat: horizon for production
geeksesi e83788d
Merge branch 'master' into feature/52-webhook-to-discord
geeksesi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/Actions/Channel/GetOrCreateAChannelByPullRequestAction.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php | ||
|
|
||
| namespace App\Actions\Channel; | ||
|
|
||
| use App\Actions\Discord\Channels\CreateChannel; | ||
| use ReflectionException; | ||
| use App\Enums\Discord\ChannelType; | ||
| use Saloon\Exceptions\PendingRequestException; | ||
| use Saloon\Exceptions\InvalidResponseClassException; | ||
| use App\Models\Channel; | ||
| use App\Models\PullRequest; | ||
|
|
||
| class GetOrCreateAChannelByPullRequestAction | ||
| { | ||
| /** | ||
| * @throws InvalidResponseClassException | ||
| * @throws ReflectionException | ||
| * @throws PendingRequestException | ||
| */ | ||
| public function execute(PullRequest $pullRequest): Channel | ||
| { | ||
| $mainLang = $pullRequest->repository->language; | ||
|
|
||
| $channel = Channel::name($mainLang)->first(); | ||
| if ($channel instanceof Channel) { | ||
| return $channel; | ||
| } | ||
| $channelData = app(CreateChannel::class) | ||
| ->execute( | ||
| name: $mainLang, | ||
| channelType: ChannelType::FORUM, | ||
| parentId: config('services.discord.channels.code_reviews') | ||
| ) | ||
| ->dtoOrFail(); | ||
|
|
||
| return Channel::create($channelData->toArray()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?php | ||
|
|
||
| namespace App\Actions\Discord\Channels; | ||
|
|
||
| use ReflectionException; | ||
| use Saloon\Contracts\Response; | ||
| use App\Enums\Discord\ChannelType; | ||
| use App\Actions\Discord\DiscordAction; | ||
| use Saloon\Exceptions\PendingRequestException; | ||
| use Saloon\Exceptions\InvalidResponseClassException; | ||
| use App\Http\Integrations\Discord\Channel\Requests\CreateGuildChannel; | ||
|
|
||
| class CreateChannel | ||
| { | ||
| use DiscordAction; | ||
|
|
||
| /** | ||
| * @throws InvalidResponseClassException | ||
| * @throws ReflectionException | ||
| * @throws PendingRequestException | ||
| */ | ||
| public function execute( | ||
| string $name, | ||
| ChannelType $channelType = ChannelType::TEXT, | ||
| ?string $parentId = null | ||
| ): Response { | ||
| $request = new CreateGuildChannel( | ||
| name: $name, | ||
| channelType: $channelType, | ||
| parentId: $parentId | ||
| ); | ||
|
|
||
| return $this->connector->send($request); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <?php | ||
|
|
||
| namespace App\Actions\Discord; | ||
|
|
||
| use App\DTO\Discord\MessageObject; | ||
| use App\Http\Integrations\Discord\Channel\Requests\CreateForumPost; | ||
| use App\Models\Channel; | ||
| use App\Models\PullRequest; | ||
| use Saloon\Contracts\Response; | ||
|
|
||
| class CreateThreadFromPullRequest | ||
| { | ||
| use DiscordAction; | ||
|
|
||
| /** | ||
| * @throws InvalidResponseClassException | ||
| * @throws ReflectionException | ||
| * @throws PendingRequestException | ||
| */ | ||
| public function execute(PullRequest $pullRequest, Channel $channel): Response | ||
| { | ||
| $repository = $pullRequest->repository; | ||
| $tags = $repository->topics; | ||
| $tags[] = $repository->language; | ||
| $message = $this->makeMessage($pullRequest); | ||
| $request = new CreateForumPost( | ||
| name: $pullRequest->title, | ||
| message: $message, | ||
| channelId: $channel->channel_id | ||
| ); | ||
|
|
||
| return $this->connector->send($request); | ||
| } | ||
|
|
||
| public function makeMessage(PullRequest $pullRequest): MessageObject | ||
| { | ||
| return new MessageObject('HELLO'); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?php | ||
|
|
||
| namespace App\Actions\Discord; | ||
|
|
||
| use App\Http\Integrations\Discord\DiscordAPIConnector; | ||
|
|
||
| trait DiscordAction | ||
| { | ||
| protected DiscordAPIConnector $connector; | ||
|
|
||
| public function __construct() | ||
| { | ||
| $this->connector = new DiscordAPIConnector; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
app/Actions/Github/Repository/CreateWebhookFromRepository.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| namespace App\Actions\Github\Repository; | ||
|
|
||
| use Exception; | ||
| use App\Models\Webhook; | ||
| use App\Models\Repository; | ||
| use App\Actions\Github\GithubAction; | ||
| use Illuminate\Support\Facades\Hash; | ||
| use Illuminate\Database\Eloquent\Model; | ||
|
|
||
| class CreateWebhookFromRepository | ||
| { | ||
| use GithubAction; | ||
|
|
||
| public function execute(Repository $repository): Model|bool | ||
| { | ||
| try { | ||
| $webhookData = app(CreateWebhook::class) | ||
| ->execute( | ||
| username: $repository->username, | ||
| repository: $repository->repository_name, | ||
| secret: Hash::make($repository->node_id) | ||
| ) | ||
| ->dtoOrFail(); | ||
|
|
||
| return $repository->webhooks()->save( | ||
| new Webhook([ | ||
| 'title' => $repository->full_name . ' hook', | ||
| 'hook_id' => $webhookData->id, | ||
| ]) | ||
| ); | ||
| } catch (Exception) { | ||
| return false; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php | ||
|
|
||
| namespace App\DTO\Discord; | ||
|
|
||
| use Spatie\LaravelData\Data; | ||
| use App\Enums\Discord\ChannelType; | ||
| use Spatie\LaravelData\Attributes\MapInputName; | ||
| use Spatie\LaravelData\Mappers\SnakeCaseMapper; | ||
| use Spatie\LaravelData\Attributes\MapOutputName; | ||
|
|
||
| #[MapInputName(SnakeCaseMapper::class)] | ||
| #[MapOutputName(SnakeCaseMapper::class)] | ||
| class ChannelData extends Data | ||
| { | ||
| public function __construct( | ||
| #[MapInputName('id')] | ||
| public string $channelId, | ||
| public ChannelType $type, | ||
| public string $name, | ||
| public ?string $parentId, | ||
| public string $guildId, | ||
| ) {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php | ||
|
|
||
| namespace App\DTO\Discord; | ||
|
|
||
| use Spatie\LaravelData\Data; | ||
| use App\Enums\Discord\ChannelType; | ||
| use Spatie\LaravelData\Attributes\MapInputName; | ||
| use Spatie\LaravelData\Mappers\SnakeCaseMapper; | ||
| use Spatie\LaravelData\Attributes\MapOutputName; | ||
|
|
||
| #[MapInputName(SnakeCaseMapper::class)] | ||
| #[MapOutputName(SnakeCaseMapper::class)] | ||
| class ForumThreadData extends Data | ||
| { | ||
| public function __construct( | ||
| #[MapInputName('id')] public string $channelId, | ||
| public ChannelType $type, | ||
| public string $name, | ||
| public ?string $parentId, | ||
| public string $guildId | ||
| ) { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <?php | ||
|
|
||
| namespace App\DTO\Discord; | ||
|
|
||
| use Spatie\LaravelData\Data; | ||
| use App\Enums\Discord\ChannelType; | ||
| use Spatie\LaravelData\Attributes\MapInputName; | ||
| use Spatie\LaravelData\Mappers\SnakeCaseMapper; | ||
| use Spatie\LaravelData\Attributes\MapOutputName; | ||
|
|
||
| #[MapInputName(SnakeCaseMapper::class)] | ||
| #[MapOutputName(SnakeCaseMapper::class)] | ||
| class MessageObject extends Data | ||
| { | ||
| public function __construct(public string $content, public ?array $embeds = null) | ||
| { | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is your opinion on union types?
I think its more readable and clear using it, like null|string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for null its ok to use "?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string|int|null ok
bcuz ?string|int not readable and may not work