@atomist/rug
Version:
TypeScript model for Atomist Rugs, see http://docs.atomist.com/
253 lines (252 loc) • 8.23 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var EventRespondable = (function () {
function EventRespondable() {
}
return EventRespondable;
}());
exports.EventRespondable = EventRespondable;
var CommandRespondable = (function () {
function CommandRespondable() {
}
return CommandRespondable;
}());
exports.CommandRespondable = CommandRespondable;
var Presentable = (function () {
function Presentable() {
}
return Presentable;
}());
exports.Presentable = Presentable;
var Identifiable = (function () {
function Identifiable() {
}
return Identifiable;
}());
exports.Identifiable = Identifiable;
/**
* Get an editor instruction to run a GitHub Pull Request
*/
var GitHubPullRequest = (function () {
function GitHubPullRequest(baseBranch) {
if (baseBranch === void 0) { baseBranch = "master"; }
this.baseBranch = baseBranch;
this.kind = "github-pull-request";
}
return GitHubPullRequest;
}());
exports.GitHubPullRequest = GitHubPullRequest;
/**
* Get an editor instruction to run on a new GitHub branch
*/
var GitHubBranch = (function () {
function GitHubBranch(baseBranch, headBranch) {
if (baseBranch === void 0) { baseBranch = "master"; }
this.baseBranch = baseBranch;
this.headBranch = headBranch;
this.kind = "github-branch";
}
return GitHubBranch;
}());
exports.GitHubBranch = GitHubBranch;
var Status;
(function (Status) {
Status[Status["failure"] = 0] = "failure";
Status[Status["success"] = 1] = "success";
})(Status = exports.Status || (exports.Status = {}));
/**
* A bunch of stuff to do asynchronously
* PlanMessages got to the bot.
* ImmediatelyRunnables are run straight away
*/
var Plan = (function () {
function Plan() {
this.instructions = [];
this.messages = [];
}
Plan.prototype.add = function (thing) {
if (thing instanceof ResponseMessage || thing instanceof DirectedMessage || thing instanceof LifecycleMessage) {
this.messages.push(thing);
}
else {
this.instructions.push(thing);
}
return this;
};
return Plan;
}());
exports.Plan = Plan;
/**
* For returning from Event Handlers
*/
var EventPlan = (function (_super) {
__extends(EventPlan, _super);
function EventPlan() {
return _super !== null && _super.apply(this, arguments) || this;
}
EventPlan.ofMessage = function (m) {
return new EventPlan().add(m);
};
EventPlan.prototype.add = function (msg) {
return _super.prototype.add.call(this, msg);
};
return EventPlan;
}(Plan));
exports.EventPlan = EventPlan;
/**
* Plans returned from Command Handlers
*/
var CommandPlan = (function (_super) {
__extends(CommandPlan, _super);
function CommandPlan() {
return _super !== null && _super.apply(this, arguments) || this;
}
CommandPlan.ofMessage = function (m) {
return new CommandPlan().add(m);
};
CommandPlan.prototype.add = function (msg) {
return _super.prototype.add.call(this, msg);
};
return CommandPlan;
}(Plan));
exports.CommandPlan = CommandPlan;
var MessageMimeTypes = (function () {
function MessageMimeTypes() {
}
MessageMimeTypes.SLACK_JSON = "application/x-atomist-slack+json";
MessageMimeTypes.PLAIN_TEXT = "text/plain";
return MessageMimeTypes;
}());
exports.MessageMimeTypes = MessageMimeTypes;
var LocallyRenderedMessage = (function () {
function LocallyRenderedMessage() {
this.usernames = [];
this.channelNames = [];
this.contentType = MessageMimeTypes.PLAIN_TEXT;
this.instructions = [];
}
LocallyRenderedMessage.prototype.addAddress = function (address) {
if (address instanceof UserAddress) {
this.usernames.push(address.username);
}
else {
this.channelNames.push(address.channelName);
}
return this;
};
LocallyRenderedMessage.prototype.addAction = function (instruction) {
this.instructions.push(instruction);
return this;
};
return LocallyRenderedMessage;
}());
exports.LocallyRenderedMessage = LocallyRenderedMessage;
/**
* Represents the response to the bot from a command
*/
var ResponseMessage = (function (_super) {
__extends(ResponseMessage, _super);
function ResponseMessage(body, contentType) {
var _this = _super.call(this) || this;
_this.kind = "response";
_this.body = body;
if (contentType) {
_this.contentType = contentType;
}
return _this;
}
return ResponseMessage;
}(LocallyRenderedMessage));
exports.ResponseMessage = ResponseMessage;
var UserAddress = (function () {
function UserAddress(username) {
this.username = username;
}
return UserAddress;
}());
exports.UserAddress = UserAddress;
var ChannelAddress = (function () {
function ChannelAddress(channelName) {
this.channelName = channelName;
}
return ChannelAddress;
}());
exports.ChannelAddress = ChannelAddress;
/**
* Uncorrelated message to the bot
*/
var DirectedMessage = (function (_super) {
__extends(DirectedMessage, _super);
function DirectedMessage(body, address, contentType) {
var _this = _super.call(this) || this;
_this.kind = "directed";
_this.body = body;
if (contentType) {
_this.contentType = contentType;
}
_this.addAddress(address);
return _this;
}
return DirectedMessage;
}(LocallyRenderedMessage));
exports.DirectedMessage = DirectedMessage;
/**
* Message that can be re-written in the bot
*/
var UpdatableMessage = (function (_super) {
__extends(UpdatableMessage, _super);
function UpdatableMessage(id, body, address, contentType) {
var _this = _super.call(this, body, address, contentType) || this;
_this.id = id;
return _this;
}
return UpdatableMessage;
}(DirectedMessage));
exports.UpdatableMessage = UpdatableMessage;
/**
* Correlated, updatable messages to the bot
*/
var LifecycleMessage = (function () {
function LifecycleMessage(node, lifecycleId) {
this.kind = "lifecycle";
this.instructions = [];
this.node = node;
this.lifecycleId = lifecycleId;
}
LifecycleMessage.prototype.addAction = function (instruction) {
this.instructions.push(instruction);
return this;
};
return LifecycleMessage;
}());
exports.LifecycleMessage = LifecycleMessage;
var MappedParameters = (function () {
function MappedParameters() {
}
MappedParameters.CORRELATION_ID = "atomist://correlation_id";
// GITHUB_REPO_OWNER is deprecated; instead use GITHUB_OWNER
MappedParameters.GITHUB_REPO_OWNER = "atomist://github/repository/owner";
MappedParameters.GITHUB_OWNER = "atomist://github/repository/owner";
MappedParameters.GITHUB_REPOSITORY = "atomist://github/repository";
MappedParameters.GITHUB_WEBHOOK_URL = "atomist://github_webhook_url";
MappedParameters.GITHUB_URL = "atomist://github_url";
MappedParameters.GITHUB_API_URL = "atomist://github_api_url";
MappedParameters.GITHUB_DEFAULT_REPO_VISIBILITY = "atomist://github/default_repo_visibility";
MappedParameters.SLACK_CHANNEL = "atomist://slack/channel";
MappedParameters.SLACK_CHANNEL_NAME = "atomist://slack/channel_name";
MappedParameters.SLACK_TEAM = "atomist://slack/team";
MappedParameters.SLACK_USER = "atomist://slack/user";
MappedParameters.SLACK_USER_NAME = "atomist://slack/user_name";
return MappedParameters;
}());
exports.MappedParameters = MappedParameters;