-
Notifications
You must be signed in to change notification settings - Fork 31
Autolabel new Pull Requests #29
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,14 +58,39 @@ public function handleCommentAddedEvent($issueNumber, $comment) | |
* Adds a "Needs Review" label to new PRs. | ||
* | ||
* @param int $prNumber The number of the PR | ||
* @param int $prTitle The title of the PR | ||
* @param int $prBody The full text description of the PR | ||
* | ||
* @return string The new status | ||
*/ | ||
public function handlePullRequestCreatedEvent($prNumber) | ||
public function handlePullRequestCreatedEvent($prNumber, $prTitle, $prBody) | ||
{ | ||
$prLabels = array(); | ||
|
||
// new PRs always require review | ||
$newStatus = Status::NEEDS_REVIEW; | ||
$prLabels[] = $newStatus; | ||
|
||
$this->statusApi->setIssueStatus($prNumber, $newStatus); | ||
// the PR title usually contains one or more labels | ||
foreach ($this->extractLabels($prTitle) as $label) { | ||
$prLabels[] = $label; | ||
} | ||
|
||
// the PR body usually indicates if this is a Bug, Feature, BC Break or Deprecation | ||
if (preg_match('/^\|\s*Bug fix?\s*\|\s*yes\s*$/', $prBody, $matches)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is my reasoning. If some user writes this by mistake:
|
||
$prLabels[] = 'Bug'; | ||
} | ||
if (preg_match('/^\|\s*New feature?\s*\|\s*yes\s*$/', $prBody, $matches)) { | ||
$prLabels[] = 'Feature'; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to allow both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Here it is an example: symfony/symfony#17458 |
||
if (preg_match('/^\|\s*BC breaks?\s*\|\s*yes\s*$/', $prBody, $matches)) { | ||
$prLabels[] = 'BC Break'; | ||
} | ||
if (preg_match('/^\|\s*Deprecations?\s*\|\s*yes\s*$/', $prBody, $matches)) { | ||
$prLabels[] = 'Deprecation'; | ||
} | ||
|
||
$this->statusApi->setIssueLabels($prNumber, $prLabels); | ||
|
||
return $newStatus; | ||
} | ||
|
@@ -98,4 +123,40 @@ public function handleLabelAddedEvent($issueNumber, $label) | |
|
||
return $newStatus; | ||
} | ||
|
||
private function extractLabels($prTitle) | ||
{ | ||
$labels = array(); | ||
|
||
// e.g. "[PropertyAccess] [RFC] [WIP] Allow custom methods on property accesses" | ||
if (preg_match_all('/\[(?P<labels>.+)\]/U', $prTitle, $matches)) { | ||
foreach ($matches['labels'] as $label) { | ||
if (in_array($label, $this->getValidLabels())) { | ||
$labels[] = $label; | ||
} | ||
} | ||
} | ||
|
||
return $labels; | ||
} | ||
|
||
/** | ||
* TODO: get valid labels from the repository via GitHub API | ||
*/ | ||
private function getValidLabels() | ||
{ | ||
return array( | ||
'Asset', 'BC Break', 'BrowserKit', 'Bug', 'Cache', 'ClassLoader', | ||
'Config', 'Console', 'Critical', 'CssSelector', 'Debug', 'DebugBundle', | ||
'DependencyInjection', 'Deprecation', 'Doctrine', 'DoctrineBridge', | ||
'DomCrawler', 'Drupal related', 'DX', 'Easy Pick', 'Enhancement', | ||
'EventDispatcher', 'ExpressionLanguage', 'Feature', 'Filesystem', | ||
'Finder', 'Form', 'FrameworkBundle', 'HttpFoundation', 'HttpKernel', | ||
'Intl', 'Ldap', 'Locale', 'MonologBridge', 'OptionsResolver', | ||
'PhpUnitBridge', 'Process', 'PropertyAccess', 'PropertyInfo', 'Ready', | ||
'RFC', 'Routing', 'Security', 'SecurityBundle', 'Serializer', | ||
'Stopwatch', 'Templating', 'Translator', 'TwigBridge', 'TwigBundle', | ||
'Unconfirmed', 'Validator', 'VarDumper', 'WebProfilerBundle', 'Yaml', | ||
); | ||
} | ||
} |
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.
If we listen to this event, we should also listen for changes to the title/body after the PR was created.
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.
Probably ... but we can leave that enhancement for the future.