UNPKG

4.43 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) => {
57 decoratorSupport_1.declareCommandHandler(obj, description, false, intent);
58 };
59}
60exports.CommandHandler = CommandHandler;
61/**
62 * Decorator for a configurable command handler class. Implements HandleCommand
63 * @param {string} description
64 * @param {string[] | string} intent
65 * @return {(obj: any) => any}
66 * @constructor
67 */
68function ConfigurableCommandHandler(description, options) {
69 const intent = options.intent ? string_1.toStringArray(options.intent) : [];
70 const autoSubmit = options.autoSubmit ? options.autoSubmit : false;
71 return (obj) => {
72 decoratorSupport_1.declareCommandHandler(obj, description, autoSubmit, intent);
73 };
74}
75exports.ConfigurableCommandHandler = ConfigurableCommandHandler;
76/**
77 * Decorator for a parameter class that doesn't contain handler logic
78 * @return {(obj: any) => any}
79 * @constructor
80 */
81function Parameters() {
82 return (obj) => {
83 decoratorSupport_1.declareParameters(obj);
84 };
85}
86exports.Parameters = Parameters;
87function EventHandler(description, subscription) {
88 return (obj) => {
89 decoratorSupport_1.declareEventHandler(obj, description, subscription);
90 };
91}
92exports.EventHandler = EventHandler;
93/**
94 * Decorator for tags. Sets tags on the class
95 */
96function Tags(...tags) {
97 return (target) => {
98 decoratorSupport_1.declareTags(target, tags);
99 };
100}
101exports.Tags = Tags;
102exports.MappedParameters = {
103 GitHubOwner: "atomist://github/repository/owner",
104 GitHubOwnerWithUser: "atomist://github/repository/owner?user=true",
105 GitHubRepository: "atomist://github/repository",
106 GitHubAllRepositories: "atomist://github/repository?all=true",
107 GitHubRepositoryProvider: "atomist://github/repository/provider",
108 GitHubWebHookUrl: "atomist://github_webhook_url",
109 GitHubUrl: "atomist://github_url",
110 GitHubApiUrl: "atomist://github_api_url",
111 GitHubUserLogin: "atomist://github/username",
112 /** @deprecated no alternative available */
113 GitHubDefaultRepositoryVisibility: "atomist://github/default_repo_visibility",
114 SlackChannel: "atomist://slack/channel",
115 SlackChannelName: "atomist://slack/channel_name",
116 SlackTeam: "atomist://slack/team",
117 SlackUser: "atomist://slack/user",
118 SlackUserName: "atomist://slack/user_name",
119 AtomistWebhookUrlBase: "atomist://base_webhook_url",
120};
121exports.Secrets = {
122 OrgToken: "github://org_token",
123 UserToken: "github://user_token",
124 userToken: (scopeOrScopes) => {
125 const scopes = string_1.toStringArray(scopeOrScopes);
126 if (scopes && scopes.length > 0) {
127 return `${exports.Secrets.UserToken}?scopes=${scopes.join(",")}`;
128 }
129 else {
130 return exports.Secrets.UserToken;
131 }
132 },
133};
134//# sourceMappingURL=decorators.js.map
\No newline at end of file