Skip to content

Instantly share code, notes, and snippets.

@camshaft
Created November 8, 2012 22:37
Show Gist options
  • Save camshaft/4042308 to your computer and use it in GitHub Desktop.
Save camshaft/4042308 to your computer and use it in GitHub Desktop.
CI Panel

CI Panel

Requirements

  • Easy to get started
  • Easy to install/write a plugin

Plugin Interface

###
#Initializes plugin

##Parameters
webhookURL  - URL at which the plugin recieves notifications
config      - Environment variables for the plugin

done(error, pluginName, pluginState)
###
exports.init = (webhookURL, config, done)->
  # Maybe go and register the hook with our provider?
  done null, config


###
#Register the plugin's properties

These properties are exposed to the client. They can have the
following parameters:

  name      - The key of the property
  value     - Default value
  prompt    - A human-readable form of the name
  options   - An array of available options for a property

##Parameters
state     - State for the plugin

done(error, array_of_properties)
###
exports.properties = (state, done)->
  properties = [
    name: "status", prompt: "Status", options: [
      value: "passing", prompt: "Passing"
    ,
      value: "failing", prompt: "Failing"
    ]
  ,
    name: "hasErrors", prompt: "Has Errors?"
  ]
  done null, properties


###
#Register the plugin's links

These links are exposed to the client. They can have the
following parameters:

  rel       - The key of the link
  value     - Default value
  prompt    - A human-readable form of the name
  render    - Optional: "image" to instruct the client to embed the link

##Parameters
state     - State for the plugin

done(error, array_of_links)
###
exports.links = (state, done)->
  links = [
    rel: "thumbnail", prompt: "Thumbnail", render: "image"
  ,
    rel: "project", prompt: "Project"
  ]
  done null, properties


###
#Register commands

This callback should return an array of available commands for
a collection. These commands will be exposed to the client for
driving state in our plugin. They can have the following parameters:

  name      - The name of the command
  prompt    - A human-readable form of the name
  handler   - Function that will be called when the command is executed
  data      - An array of available options the command

##Parameters
state     - State for the plugin

done(error, array_of_commands)
###
exports.commands = (state, done)->
  commands = [
    name: "restart", prompt: "Restart Server", handler: restart
  ,
    name: "enable-experiment", prompt: "Enable Experiment", handler: enableExperiment, data: [
      name: "experiment-name", prompt: "Experiment Name"
    ,
      name: "experiment-value", prompt: "Experiment Value"
    ]
  ]
  done null, commands


###
#Handle WebHook

This will be called any time this plugins webhook is fired. Use
the `feed` object to emit any events the webhook caused

##Parameters
state       - State for the plugin
hookData    - the body passed from the webhook
feed        - used to emit events that occured because of this webhook

done(error)
###
exports.webhook = (state, hookData, feed, done)->
  item =
    data:
      status: hookData.status
    links:
      thumbnail: hookData.thumbnail

  feed.publish hookData.url, item, (error)->
    # done publishing
    done error


###
#Closes plugin

Called to shut down the plugin

###
exports.close = (state, done)->
  done()

#Command Handlers

###
#Restart the server

##Parameters
state       - State for the plugin
commandData - the options passed to the command from the client
feed        - used to emit events that occured because of this command

done(error)
###
restart = (state, commandData, feed, done)->
  # Go off and try to restart the server however you want
  done()

###
#Enables an experiment

##Parameters
state       - State for the plugin
commandData - the options passed to the command from the client
feed        - used to emit events that occured because of this command

done(error)
###
enableExperiment = (state, commandData, feed, done)->
  # Edit the settings for the experiment on server
  done()

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