|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Subscriber; |
| 4 | + |
| 5 | +use App\Event\GitHubEvent; |
| 6 | +use App\GitHubEvents; |
| 7 | +use App\Issues\CommentsApiInterface; |
| 8 | +use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
| 9 | + |
| 10 | +/** |
| 11 | + * @author Tobias Nyholm <tobias.nyholm@gmail.com> |
| 12 | + */ |
| 13 | +class WelcomeFirstTimeContributorSubscriber implements EventSubscriberInterface |
| 14 | +{ |
| 15 | + private $commentsApi; |
| 16 | + |
| 17 | + public function __construct(CommentsApiInterface $commentsApi) |
| 18 | + { |
| 19 | + $this->commentsApi = $commentsApi; |
| 20 | + } |
| 21 | + |
| 22 | + public function onPullRequest(GitHubEvent $event) |
| 23 | + { |
| 24 | + $data = $event->getData(); |
| 25 | + if ('opened' !== $data['action']) { |
| 26 | + return; |
| 27 | + } |
| 28 | + |
| 29 | + if ('NONE' !== ($data['pull_request']['author_association'] ?? '')) { |
| 30 | + return; |
| 31 | + } |
| 32 | + |
| 33 | + $repository = $event->getRepository(); |
| 34 | + $pullRequestNumber = $data['pull_request']['number']; |
| 35 | + $defaultBranch = $data['repository']['default_branch']; |
| 36 | + $this->commentsApi->commentOnIssue($repository, $pullRequestNumber, <<<TXT |
| 37 | +Hey! |
| 38 | +
|
| 39 | +I see that this is your first PR. That is great! Welcome! |
| 40 | +
|
| 41 | +Symfony has a [contribution guide](https://symfony.com/doc/current/contributing/index.html) which I suggest you to read. |
| 42 | +
|
| 43 | +In short: |
| 44 | +- Always add tests |
| 45 | +- Keep backward compatibility (see https://symfony.com/bc). |
| 46 | +- Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases) |
| 47 | +- Features and deprecations must be submitted against the $defaultBranch branch. |
| 48 | +
|
| 49 | +Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. |
| 50 | +
|
| 51 | +When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! |
| 52 | +If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days. |
| 53 | +
|
| 54 | +I am going to sit back now and wait for the reviews. |
| 55 | +
|
| 56 | +Cheers! |
| 57 | +
|
| 58 | +Carsonbot |
| 59 | +TXT |
| 60 | +); |
| 61 | + |
| 62 | + $event->setResponseData([ |
| 63 | + 'pull_request' => $pullRequestNumber, |
| 64 | + 'new_contributor' => true, |
| 65 | + ]); |
| 66 | + } |
| 67 | + |
| 68 | + public static function getSubscribedEvents() |
| 69 | + { |
| 70 | + return [ |
| 71 | + GitHubEvents::PULL_REQUEST => 'onPullRequest', |
| 72 | + ]; |
| 73 | + } |
| 74 | +} |
0 commit comments