Skip to content

Added support for GitHub reviews #58

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

Merged
merged 5 commits into from
Sep 28, 2017

Conversation

wouterj
Copy link
Contributor

@wouterj wouterj commented Mar 7, 2017

Currently, status: and such in a review body isn't parsed by Carson. This is a bit annoying, as it means we either have to manually assign the status label or write an issue comment with just the status:.

This PR adds a new status subscriber for GitHub reviews. Besides parsing review bodies, this subscriber does 2 more things:

  • Updating the status based on the review state (approved/changes requested)
  • Updating the status to needs review when a GitHub review is requested

@weaverryan I'm still not sure how to implement the functional testing bit, if you can do that before/after the merge, I would be very happy :)

$newStatus = null;

// Set status based on review state
switch (strtolower($data['review']['state'])) {
Copy link
Contributor Author

@wouterj wouterj Mar 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub docs are a bit vague on this: REST api docs shows state in all uppercase, while the webhooks docs show it in lowercase. Just to be sure, I've added this strtolower() call.

Copy link
Contributor

@HeahDude HeahDude left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, thanks!

}
}

$event->setResponseData(array(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about moving the beginning of the method and those line in the abstract listener too, it could call an abstract method to extract the status from the payload, wdyt?

protected function parseStatusFromText($body)
{
$triggerWord = implode('|', array_keys(static::$triggerWordToStatus));
$formatting = '[\\s\\*]*';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI you don't have to escape special characters in a character class, except - if it's not at the end and to be used as literal.

);
}

private function checkUserIsAllowedToReview(array $data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is also defined in AbstractStatusChangeSubscriber, and check implies it will throw exception or something. By Symfony conventions it should be isUserIsAllowedToReview 👍


public static function setUpBeforeClass()
{
self::$dispatcher = new EventDispatcher();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be a static property. The dispatcher instance must not be shared between tests, otherwise the listener will run several times for subsequent tests (as listeners registered by previous tests will still be here).
I faced this issue when implementing the same feature before seeing your PR, because I added a check in the subscriber to avoid changing the status if it is already the current one. (making the test fail when a previous listener was running too with the config of the previous test).

@stof
Copy link
Member

stof commented Apr 11, 2017

@weaverryan any news on it ?

@stof
Copy link
Member

stof commented Sep 27, 2017

@weaverryan ping

@weaverryan
Copy link
Contributor

I just made some changes! I would appreciate any review - it's still a bit of "guess work" when processing webhooks, and I'd like to not get it wrong :)

@stof
Copy link
Member

stof commented Sep 28, 2017

this PR should close both #50 and #59

@weaverryan weaverryan merged commit 6749593 into symfony-tools:master Sep 28, 2017
@weaverryan
Copy link
Contributor

This is merged and deployed! But, I don't know if the Pull request review webhook is checked on symfony/symfony or not. So, if this doesn't work, we need to ping fabpot about that. I just tested on weaverryan/symfony and the feature definitely works (assuming that webhook is being delivered)

@wouterj wouterj deleted the github-reviews branch September 30, 2017 08:50
@Jean85
Copy link

Jean85 commented May 3, 2018

This is definitely NOT working on symfony-docs, see symfony/symfony-docs#7296 (review)

@stof
Copy link
Member

stof commented May 3, 2018

@fabpot @nicolas-grekas can you check which webhooks are sent to carsonbot on symfony/symfony and symfony/symfony-docs ?

@fabpot
Copy link
Contributor

fabpot commented May 5, 2018

Pull request reviews was already checked on symfony/symfony, and I've just checked it on symfony/symfony-docs.

@Jean85
Copy link

Jean85 commented May 6, 2018

Can confirm that it's working now! 👍 symfony/symfony-docs#8899 (review)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

7 participants