A nitcorn listener for Github hooks.

Introduced properties

fun api: GithubAPI

github :: HookListener :: api

Api client used to perform Github API requests.
protected fun api=(api: GithubAPI)

github :: HookListener :: api=

Api client used to perform Github API requests.
abstract fun apply_event(event: GithubEvent)

github :: HookListener :: apply_event

What to do when we receive an event from a hook?
init defaultinit(api: GithubAPI, host: String, port: Int)

github :: HookListener :: defaultinit

fun event_factory(kind: String, json: String): nullable GithubEvent

github :: HookListener :: event_factory

How to build events from received json objects.
fun host: String

github :: HookListener :: host

Host to listen.
protected fun host=(host: String)

github :: HookListener :: host=

Host to listen.
fun listen

github :: HookListener :: listen

Start listening and responding to event.
fun message(lvl: Int, message: String)

github :: HookListener :: message

Print message if lvl <= verbosity
fun port: Int

github :: HookListener :: port

Port to listen.
protected fun port=(port: Int)

github :: HookListener :: port=

Port to listen.
fun verbosity: Int

github :: HookListener :: verbosity

Verbosity level (0: quiet, 1: debug).
protected fun verbosity=(verbosity: Int)

github :: HookListener :: verbosity=

Verbosity level (0: quiet, 1: debug).

Redefined properties

redef type SELF: HookListener

github $ HookListener :: SELF

Type of this instance, automatically specialized in every class
redef init init

github $ HookListener :: init

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun api: GithubAPI

github :: HookListener :: api

Api client used to perform Github API requests.
protected fun api=(api: GithubAPI)

github :: HookListener :: api=

Api client used to perform Github API requests.
abstract fun apply_event(event: GithubEvent)

github :: HookListener :: apply_event

What to do when we receive an event from a hook?
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
init defaultinit(api: GithubAPI, host: String, port: Int)

github :: HookListener :: defaultinit

fun event_factory(kind: String, json: String): nullable GithubEvent

github :: HookListener :: event_factory

How to build events from received json objects.
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun host: String

github :: HookListener :: host

Host to listen.
protected fun host=(host: String)

github :: HookListener :: host=

Host to listen.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun listen

github :: HookListener :: listen

Start listening and responding to event.
fun message(lvl: Int, message: String)

github :: HookListener :: message

Print message if lvl <= verbosity
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun port: Int

github :: HookListener :: port

Port to listen.
protected fun port=(port: Int)

github :: HookListener :: port=

Port to listen.
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun verbosity: Int

github :: HookListener :: verbosity

Verbosity level (0: quiet, 1: debug).
protected fun verbosity=(verbosity: Int)

github :: HookListener :: verbosity=

Verbosity level (0: quiet, 1: debug).
package_diagram github::HookListener HookListener core::Object Object github::HookListener->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

github $ HookListener
# A nitcorn listener for Github hooks.
abstract class HookListener

	# Api client used to perform Github API requests.
	var api: GithubAPI

	# Host to listen.
	var host: String

	# Port to listen.
	var port: Int

	# VirtualHost listened
	private var vh: VirtualHost is noinit

	init do
		vh = new VirtualHost("{host}:{port}")
		vh.routes.add new Route("/", new HookAction(self))
	end

	# Verbosity level (0: quiet, 1: debug).
	# Default: 0
	var verbosity = 0

	# Print `message` if `lvl` <= `verbosity`
	fun message(lvl: Int, message: String) do
		if lvl <= verbosity then print message
	end

	# Start listening and responding to event.
	fun listen do
		message(1, "Hook listening on {host}:{port}")
		var factory = new HttpFactory.and_libevent
		factory.config.virtual_hosts.add vh
		factory.run
	end

	# How to build events from received json objects.
	fun event_factory(kind: String, json: String): nullable GithubEvent do
		if kind == "commit_comment" then
			return api.deserialize(json).as(CommitCommentEvent)
		else if kind == "create" then
			return api.deserialize(json).as(CreateEvent)
		else if kind == "delete" then
			return api.deserialize(json).as(DeleteEvent)
		else if kind == "deployment" then
			return api.deserialize(json).as(DeploymentEvent)
		else if kind == "deployment_status" then
			return api.deserialize(json).as(DeploymentStatusEvent)
		else if kind == "fork" then
			return api.deserialize(json).as(ForkEvent)
		else if kind == "issues" then
			return api.deserialize(json).as(IssuesEvent)
		else if kind == "issue_comment" then
			return api.deserialize(json).as(IssueCommentEvent)
		else if kind == "member" then
			return api.deserialize(json).as(MemberEvent)
		else if kind == "pull_request" then
			return api.deserialize(json).as(PullRequestEvent)
		else if kind == "pull_request_review_comment" then
			return api.deserialize(json).as(PullRequestPullCommentEvent)
		else if kind == "push" then
			return api.deserialize(json).as(PushEvent)
		else if kind == "status" then
			return api.deserialize(json).as(StatusEvent)
		end
		return null
	end

	# What to do when we receive an event from a hook?
	fun apply_event(event: GithubEvent) is abstract
end
lib/github/hooks.nit:53,1--124,3