EventClassifier: learn more types

This commit is contained in:
Graham Christensen 2017-10-31 04:07:07 -04:00
parent fd7ec20a6a
commit 3f0fcfbc4b
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C

View file

@ -44,6 +44,22 @@ class EventClassifier {
return "fork"; return "fork";
} }
if (self::isCreateEvent($payload)) {
return "create";
}
if (self::isDeleteEvent($payload)) {
return "delete";
}
if (self::isProjectCardEvent($payload)) {
return "project_card";
}
if (self::isProjectColumnEvent($payload)) {
return "project_column";
}
throw new EventClassifierUnknownException(); throw new EventClassifierUnknownException();
} }
@ -112,10 +128,8 @@ class EventClassifier {
} }
public static function isPushEvent($payload) { public static function isPushEvent($payload) {
return isset($payload->head_commit) return isset($payload->before)
&& isset($payload->commits) && isset($payload->after);
&& isset($payload->compare)
&& isset($payload->forced);
} }
public static function isWatchEvent($payload) { public static function isWatchEvent($payload) {
@ -127,6 +141,27 @@ class EventClassifier {
return isset($payload->forkee); return isset($payload->forkee);
} }
public static function isCreateEvent($payload) {
return isset($payload->ref_type)
&& isset($payload->ref)
&& isset($payload->master_branch);
}
public static function isDeleteEvent($payload) {
return isset($payload->ref_type)
&& isset($payload->ref)
&& !isset($payload->master_branch);
}
public static function isProjectCardEvent($payload) {
return isset($payload->project_card);
}
public static function isProjectColumnEvent($payload) {
return isset($payload->project_column);
}
} }
class EventClassifierUnknownException extends \Exception{}; class EventClassifierUnknownException extends \Exception{};