hubot-perforce v0.1.3
hubot-perforce
Hubot script for receiving notifications from Perforce and interacting with Perforce.
THIS PROJECT IS IN AN EARLY STATE, USE AT YOUR OWN RISK
Installation
In hubot project repo, run:
npm install hubot-perforce --save
Then add hubot-perforce to your external-scripts.json:
["hubot-perforce"]Quick Start
Configure default p4
An instance of
P4is available atrobot.p4. This instance needs to be configured for your Perforce server when Hubot starts. There are three different ways to accomplish this.If you do nothing else, the default p4 will be configured using the standard Perforce environment variables (see the Perforce Manual for the details):
P4CHARSET P4CLIENT P4HOST P4LANGUAGE P4PORT P4USERIf you wish to override the standard Perforce environment variables, you may specify any of the following custom environment variables:
HUBOT_P4CHARSET HUBOT_P4CLIENT HUBOT_P4HOST HUBOT_P4LANGUAGE HUBOT_P4PORT HUBOT_P4USERAs a final alternative, you may configure the p4 instance at runtime:
module.exports = (robot) -> # Handle all notifications robot.on 'perforce:ready', (p4) -> p4.charset = 'utf8' p4.client = 'my-client' p4.host = 'my-host' p4.port = 'perforce:1666' p4.user = 'me'NOTE: It is expected, that the configured Perforce user will already be logged in when Hubot is started. If this is not the case, use the
perforce:readyevent to execute aP4.loginas needed by your configuration.Configure Perforce trigger to notify Hubot
Use the p4 triggers command to notify hubot-perforce when a change is committed. In general, an HTTP POST to
/hubot/perforcewhich the change number needs to be made. An example usingcurlis shown here:hubot-perforce change-commit //... "curl -d 'change=%change' http://hubot.example.com/hubot/perforce"Listen for change events in your own code
hubot-perforce will emit a
perforce:changeevent whenever a change is committed. That event will contain the full details of the change (as returned byp4 describe){ inspect } = require 'util' module.exports = (robot) -> robot.on 'perforce:change', (change) -> robot.logger.info "Perforce Change: #{inspect change}"[Wed Dec 03 2014 22:13:06 GMT-0800 (PST)] INFO Perforce Change: { code: 'stat', change: 12345, user: 'user', client: 'client', time: 1410399382, desc: 'Change', status: 'submitted', changeType: 'public', path: '//depot/path/...', files: [ { depotFile: '//depot/path/file.txt', action: 'edit', type: 'text', rev: 42, fileSize: 1024, digest: 'C24816CC89E4B289F338F2FE87DC04A0' } ] }
P4 class
This section is intended to be an introduction to using robot.p4, but it has not been written yet.
All commands can be sent via
p4.commandwhich matches general p4 command line of formp4 [ options ] command [ arg ... ]opts = [ '-r', '3'] command = 'opened' args = [ '-m', 100 ] robot.p4.command options, command, args, (error, output) -> robot.logger.info error robot.logger.info outputConvenience commands
p4.describe,p4.info,p4.istat,p4.streams, etc.
- Response handling configuration
- All default on, but can be turned off if needed/desired
p4.responseInfersTypep4.responseSingleElementArrayToObjectp4.responseOrganized
p4.maxBufferdefaults to 200KB, may need to be upped for many use cases