UNPKG

4.6 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const decoratorSupport_1 = require("./internal/metadata/decoratorSupport");
4const string_1 = require("./internal/util/string");
5/**
6 * Decorator for parameters. Adds to object properties
7 */
8function Parameter(details = {}) {
9 return (target, propertyKey) => {
10 decoratorSupport_1.declareParameter(target, propertyKey, details);
11 };
12}
13exports.Parameter = Parameter;
14/**
15 * Map a local field to some other configuration item in a different system
16 */
17function MappedParameter(uri, required = true) {
18 return (target, name) => {
19 decoratorSupport_1.declareMappedParameter(target, name, uri, required);
20 };
21}
22exports.MappedParameter = MappedParameter;
23/**
24 * Declare a secret an automation wants to use
25 */
26function Secret(uri) {
27 return (target, name) => {
28 decoratorSupport_1.declareSecret(target, name, uri);
29 };
30}
31exports.Secret = Secret;
32/**
33 * Inject a config value from the automation-client configuration
34 */
35function Value(pathOrValue) {
36 return (target, name) => {
37 if (typeof pathOrValue === "string") {
38 decoratorSupport_1.declareValue(target, name, {
39 path: pathOrValue,
40 });
41 }
42 else {
43 decoratorSupport_1.declareValue(target, name, pathOrValue);
44 }
45 };
46}
47exports.Value = Value;
48/**
49 * Decorator for a command handler class. Implements HandleCommand
50 * @param {string} description
51 * @param {string[] | string} intent
52 * @return {(obj: any) => any}
53 * @constructor
54 */
55function CommandHandler(description, ...intent) {
56 return (obj) => { decoratorSupport_1.declareCommandHandler(obj, description, null, intent); };
57}
58exports.CommandHandler = CommandHandler;
59/**
60 * Decorator for a configurable command handler class. Implements HandleCommand
61 * @param {string} description
62 * @param {string[] | string} intent
63 * @return {(obj: any) => any}
64 * @constructor
65 */
66function ConfigurableCommandHandler(description, options) {
67 const intent = options.intent ? string_1.toStringArray(options.intent) : [];
68 const autoSubmit = options.autoSubmit ? options.autoSubmit : false;
69 return (obj) => { decoratorSupport_1.declareCommandHandler(obj, description, autoSubmit, intent); };
70}
71exports.ConfigurableCommandHandler = ConfigurableCommandHandler;
72/**
73 * Decorator for a parameter class that doesn't contain handler logic
74 * @return {(obj: any) => any}
75 * @constructor
76 */
77function Parameters() {
78 return (obj) => { decoratorSupport_1.declareParameters(obj); };
79}
80exports.Parameters = Parameters;
81function EventHandler(description, subscription) {
82 return (obj) => {
83 decoratorSupport_1.declareEventHandler(obj, description, subscription);
84 };
85}
86exports.EventHandler = EventHandler;
87/**
88 * Decorator for tags. Sets tags on the class
89 */
90function Tags(...tags) {
91 return (target) => {
92 decoratorSupport_1.declareTags(target, tags);
93 };
94}
95exports.Tags = Tags;
96class MappedParameters {
97}
98MappedParameters.GitHubOwner = "atomist://github/repository/owner";
99MappedParameters.GitHubOwnerWithUser = "atomist://github/repository/owner?user=true";
100MappedParameters.GitHubRepository = "atomist://github/repository";
101MappedParameters.GitHubAllRepositories = "atomist://github/repository?all=true";
102MappedParameters.GitHubRepositoryProvider = "atomist://github/repository/provider";
103MappedParameters.GitHubWebHookUrl = "atomist://github_webhook_url";
104MappedParameters.GitHubUrl = "atomist://github_url";
105MappedParameters.GitHubApiUrl = "atomist://github_api_url";
106MappedParameters.GitHubDefaultRepositoryVisibility = "atomist://github/default_repo_visibility";
107MappedParameters.GitHubUserLogin = "atomist://github/username";
108MappedParameters.SlackChannel = "atomist://slack/channel";
109MappedParameters.SlackChannelName = "atomist://slack/channel_name";
110MappedParameters.SlackTeam = "atomist://slack/team";
111MappedParameters.SlackUser = "atomist://slack/user";
112MappedParameters.SlackUserName = "atomist://slack/user_name";
113MappedParameters.AtomistWebhookUrlBase = "atomist://base_webhook_url";
114exports.MappedParameters = MappedParameters;
115class Secrets {
116 static userToken(scopes) {
117 scopes = string_1.toStringArray(scopes);
118 if (scopes && scopes.length > 0) {
119 return `${this.UserToken}?scopes=${scopes.join(",")}`;
120 }
121 else {
122 return this.UserToken;
123 }
124 }
125}
126Secrets.OrgToken = "github://org_token";
127Secrets.UserToken = "github://user_token";
128exports.Secrets = Secrets;
129//# sourceMappingURL=decorators.js.map
\No newline at end of file