onesignal-vue 2.1.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import Vue from 'vue';
2
2
 
3
3
  const ONESIGNAL_SDK_ID = 'onesignal-sdk';
4
- const ONE_SIGNAL_SCRIPT_SRC = "https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js";
4
+ const ONE_SIGNAL_SCRIPT_SRC =
5
+ 'https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js';
5
6
 
6
7
  // true if the script is successfully loaded from CDN.
7
8
  let isOneSignalInitialized = false;
@@ -33,7 +34,7 @@ function addSDKScript() {
33
34
  // This is important for users who may block cdn.onesignal.com w/ adblock.
34
35
  script.onerror = () => {
35
36
  handleOnError();
36
- }
37
+ };
37
38
 
38
39
  document.head.appendChild(script);
39
40
  }
@@ -61,25 +62,25 @@ declare global {
61
62
  /**
62
63
  * @PublicApi
63
64
  */
64
- const init = (options: IInitObject): Promise<void> => {
65
+ const init = (options: IInitObject): Promise<void> => {
65
66
  if (isOneSignalInitialized) {
66
67
  return Promise.reject(`OneSignal is already initialized.`);
67
68
  }
68
-
69
69
  if (!options || !options.appId) {
70
- throw new Error('You need to provide your OneSignal appId.');
70
+ return Promise.reject('You need to provide your OneSignal appId.');
71
71
  }
72
-
73
72
  if (!document) {
74
73
  return Promise.reject(`Document is not defined.`);
75
74
  }
76
75
 
77
- return new Promise<void>((resolve) => {
76
+ return new Promise<void>((resolve, reject) => {
78
77
  window.OneSignalDeferred?.push((OneSignal) => {
79
- OneSignal.init(options).then(() => {
80
- isOneSignalInitialized = true;
81
- resolve();
82
- });
78
+ OneSignal.init(options)
79
+ .then(() => {
80
+ isOneSignalInitialized = true;
81
+ resolve();
82
+ })
83
+ .catch(reject);
83
84
  });
84
85
  });
85
86
  };
@@ -97,20 +98,26 @@ function isPushNotificationsSupported() {
97
98
 
98
99
  function isMacOSSafariInIframe(): boolean {
99
100
  // Fallback detection for Safari on macOS in an iframe context
100
- return window.top !== window && // isContextIframe
101
- navigator.vendor === "Apple Computer, Inc." && // isSafari
102
- navigator.platform === "MacIntel"; // isMacOS
101
+ return (
102
+ window.top !== window && // isContextIframe
103
+ navigator.vendor === 'Apple Computer, Inc.' && // isSafari
104
+ navigator.platform === 'MacIntel'
105
+ ); // isMacOS
103
106
  }
104
107
 
105
108
  function supportsSafariPush(): boolean {
106
- return (window.safari && typeof window.safari.pushNotification !== "undefined") ||
107
- isMacOSSafariInIframe();
109
+ return (
110
+ (window.safari && typeof window.safari.pushNotification !== 'undefined') ||
111
+ isMacOSSafariInIframe()
112
+ );
108
113
  }
109
114
 
110
115
  // Does the browser support the standard Push API
111
116
  function supportsVapidPush(): boolean {
112
- return typeof PushSubscriptionOptions !== "undefined" &&
113
- PushSubscriptionOptions.prototype.hasOwnProperty("applicationServerKey");
117
+ return (
118
+ typeof PushSubscriptionOptions !== 'undefined' &&
119
+ PushSubscriptionOptions.prototype.hasOwnProperty('applicationServerKey')
120
+ );
114
121
  }
115
122
  /* E N D */
116
123
 
@@ -119,18 +126,18 @@ function supportsVapidPush(): boolean {
119
126
  */
120
127
  const isPushSupported = (): boolean => {
121
128
  return isPushNotificationsSupported();
122
- }
129
+ };
123
130
 
124
- interface AutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; slidedownPromptOptions?: IOneSignalAutoPromptOptions; }
125
- interface IOneSignalAutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; isInUpdateMode?: boolean; categoryOptions?: IOneSignalCategories; }
126
- interface IOneSignalCategories { positiveUpdateButton: string; negativeUpdateButton: string; savingButtonText: string; errorButtonText: string; updateMessage: string; tags: IOneSignalTagCategory[]; }
127
- interface IOneSignalTagCategory { tag: string; label: string; checked?: boolean; }
128
- type PushSubscriptionNamespaceProperties = { id: string | null | undefined; token: string | null | undefined; optedIn: boolean; };
129
- type SubscriptionChangeEvent = { previous: PushSubscriptionNamespaceProperties; current: PushSubscriptionNamespaceProperties; };
130
- type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';
131
- type SlidedownEventName = 'slidedownShown';
132
- type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void;
133
- interface IOSNotification {
131
+ export interface AutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; slidedownPromptOptions?: IOneSignalAutoPromptOptions; }
132
+ export interface IOneSignalAutoPromptOptions { force?: boolean; forceSlidedownOverNative?: boolean; isInUpdateMode?: boolean; categoryOptions?: IOneSignalCategories; }
133
+ export interface IOneSignalCategories { positiveUpdateButton: string; negativeUpdateButton: string; savingButtonText: string; errorButtonText: string; updateMessage: string; tags: IOneSignalTagCategory[]; }
134
+ export interface IOneSignalTagCategory { tag: string; label: string; checked?: boolean; }
135
+ export type PushSubscriptionNamespaceProperties = { id: string | null | undefined; token: string | null | undefined; optedIn: boolean; };
136
+ export type SubscriptionChangeEvent = { previous: PushSubscriptionNamespaceProperties; current: PushSubscriptionNamespaceProperties; };
137
+ export type NotificationEventName = 'click' | 'foregroundWillDisplay' | 'dismiss' | 'permissionChange' | 'permissionPromptDisplay';
138
+ export type SlidedownEventName = 'slidedownAllowClick' | 'slidedownCancelClick' | 'slidedownClosed' | 'slidedownQueued' | 'slidedownShown';
139
+ export type OneSignalDeferredLoadedCallback = (onesignal: IOneSignalOneSignal) => void;
140
+ export interface IOSNotification {
134
141
  /**
135
142
  * The OneSignal notification id;
136
143
  * - Primary id on OneSignal's REST API and dashboard
@@ -192,7 +199,7 @@ interface IOSNotification {
192
199
  readonly confirmDelivery: boolean;
193
200
  }
194
201
 
195
- interface IOSNotificationActionButton {
202
+ export interface IOSNotificationActionButton {
196
203
  /**
197
204
  * Any unique identifier to represent which button was clicked. This is typically passed back to the service worker
198
205
  * and host page through events to identify which button was clicked.
@@ -213,12 +220,12 @@ interface IOSNotificationActionButton {
213
220
  readonly launchURL?: string;
214
221
  }
215
222
 
216
- interface NotificationClickResult {
223
+ export interface NotificationClickResult {
217
224
  readonly actionId?: string;
218
225
  readonly url?: string;
219
226
  }
220
227
 
221
- type NotificationEventTypeMap = {
228
+ export type NotificationEventTypeMap = {
222
229
  'click': NotificationClickEvent;
223
230
  'foregroundWillDisplay': NotificationForegroundWillDisplayEvent;
224
231
  'dismiss': NotificationDismissEvent;
@@ -226,37 +233,219 @@ type NotificationEventTypeMap = {
226
233
  'permissionPromptDisplay': void;
227
234
  };
228
235
 
229
- interface NotificationForegroundWillDisplayEvent {
236
+ export interface NotificationForegroundWillDisplayEvent {
230
237
  readonly notification: IOSNotification;
231
238
  preventDefault(): void;
232
239
  }
233
240
 
234
- interface NotificationDismissEvent {
241
+ export interface NotificationDismissEvent {
235
242
  notification: IOSNotification;
236
243
  }
237
244
 
238
- interface NotificationClickEvent {
245
+ export interface NotificationClickEvent {
239
246
  readonly notification: IOSNotification;
240
247
  readonly result: NotificationClickResult;
241
248
  }
242
249
 
243
- type UserChangeEvent = {
250
+ export type UserChangeEvent = {
244
251
  current: UserNamespaceProperties;
245
252
  };
246
- type UserNamespaceProperties = {
253
+ export type UserNamespaceProperties = {
247
254
  onesignalId: string | undefined;
248
255
  externalId: string | undefined;
249
256
  };
250
257
 
251
- interface IInitObject {
258
+ export interface IInitObject {
252
259
  appId: string;
253
260
  subdomainName?: string;
254
261
  requiresUserPrivacyConsent?: boolean;
255
- promptOptions?: object;
256
- welcomeNotification?: object;
257
- notifyButton?: object;
262
+ promptOptions?: {
263
+ slidedown: {
264
+ prompts: {
265
+ /**
266
+ * Whether to automatically display the prompt.
267
+ * `true` will display the prompt based on the delay options.
268
+ * `false` will prevent the prompt from displaying until the Slidedowns methods are used.
269
+ */
270
+ autoPrompt: boolean;
271
+
272
+ /**
273
+ * Only available for type: category. Up to 10 categories.
274
+ * @example
275
+ * categories: [{ tag: 'local_news', label: 'Local News' }] // The user will be tagged with local_news but will see "Local News" in the prompt.
276
+ */
277
+ categories: {
278
+ /** Should identify the action. */
279
+ tag: string;
280
+
281
+ /** What the user will see. */
282
+ label: string;
283
+ }[];
284
+
285
+ /**
286
+ * The delay options for the prompt.
287
+ * @example delay: { pageViews: 3, timeDelay: 20 } // The user will not be shown the prompt until 20 seconds after the 3rd page view.
288
+ */
289
+ delay: {
290
+ /** The number of pages a user needs to visit before the prompt is displayed. */
291
+ pageViews?: number;
292
+
293
+ /** The number of seconds a user needs to wait before the prompt is displayed.Both options must be satisfied for the prompt to display */
294
+ timeDelay?: number;
295
+ };
296
+
297
+ /**
298
+ * The text to display in the prompt.
299
+ */
300
+ text?: {
301
+ /** The callout asking the user to opt-in. Up to 90 characters. */
302
+ actionMessage?: string;
303
+
304
+ /** Triggers the opt-in. Up to 15 characters. */
305
+ acceptButton?: string;
306
+
307
+ /** Cancels opt-in. Up to 15 characters. */
308
+ cancelMessage?: string;
309
+
310
+ /** The message of the confirmation prompt displayed after the email and/or phone number is provided. Up to 90 characters. */
311
+ confirmMessage?: string;
312
+
313
+ /** Identifies the email text field. Up to 15 characters. */
314
+ emailLabel?: string;
315
+
316
+ /** Cancels the category update. Up to 15 characters. */
317
+ negativeUpdateButton?: string;
318
+
319
+ /** Saves the updated category tags. Up to 15 characters. */
320
+ positiveUpdateButton?: string;
321
+
322
+ /** Identifies the phone number text field. Up to 15 characters. */
323
+ smsLabel?: string;
324
+
325
+ /** A different message shown to subscribers presented the prompt again to update categories. Up to 90 characters. */
326
+ updateMessage?: string;
327
+ };
328
+
329
+ /**
330
+ * The type of prompt to display.
331
+ * `push` which is the Slide Prompt without categories.
332
+ * `category` which is the Slide Prompt with categories.
333
+ * `sms` only asks for phone number.
334
+ * `email` only asks for email address.
335
+ * `smsAndEmail` asks for both phone number and email address.
336
+ */
337
+ type: 'push' | 'category' | 'sms' | 'email' | 'smsAndEmail';
338
+ }[];
339
+ };
340
+ };
341
+ welcomeNotification?: {
342
+ /**
343
+ * Disables sending a welcome notification to new site visitors. If you want to disable welcome notifications, this is the only option you need.
344
+ */
345
+ disabled?: boolean;
346
+
347
+ /**
348
+ * The welcome notification's message. You can localize this to your own language.
349
+ * If left blank or set to blank, the default of 'Thanks for subscribing!' will be used.
350
+ */
351
+ message: string;
352
+
353
+ /**
354
+ * The welcome notification's title. You can localize this to your own language. If not set, or left blank, the site's title will be used.
355
+ * Set to one space ' ' to clear the title, although this is not recommended.
356
+ */
357
+ title?: string;
358
+
359
+ /**
360
+ * By default, clicking the welcome notification does not open any link.
361
+ * This is recommended because the user has just visited your site and subscribed.
362
+ */
363
+ url: string;
364
+ };
365
+
366
+ /**
367
+ * Will enable customization of the notify/subscription bell button.
368
+ */
369
+ notifyButton?: {
370
+ /**
371
+ * A function you define that returns true to show the Subscription Bell, or false to hide it.
372
+ * Typically used the hide the Subscription Bell after the user is subscribed.
373
+ * This function is not re-evaluated on every state change; this function is only evaluated once when the Subscription Bell begins to show.
374
+ */
375
+ displayPredicate?: () => boolean | Promise<boolean>;
376
+
377
+ /**
378
+ * Enable the Subscription Bell. The Subscription Bell is otherwise disabled by default.
379
+ */
380
+ enable?: boolean;
381
+
382
+ /** Specify CSS-valid pixel offsets using bottom, left, and right. */
383
+ offset?: { bottom: string; left: string; right: string };
384
+
385
+ /**
386
+ * If `true`, the Subscription Bell will display an icon that there is 1 unread message.
387
+ * When hovering over the Subscription Bell, the user will see custom text set by message.prenotify.
388
+ */
389
+ prenotify: boolean;
390
+
391
+ /** Either `bottom-left` or `bottom-right`. The Subscription Bell will be fixed at this location on your page. */
392
+ position?: 'bottom-left' | 'bottom-right';
393
+
394
+ /** Set `false` to hide the 'Powered by OneSignal' text in the Subscription Bell dialog popup. */
395
+ showCredit: boolean;
396
+
397
+ /**
398
+ * The Subscription Bell will initially appear at one of these sizes, and then shrink down to size `small` after the user subscribes.
399
+ */
400
+ size?: 'small' | 'medium' | 'large';
401
+
402
+ /** Customize the Subscription Bell text. */
403
+ text: {
404
+ 'dialog.blocked.message': string;
405
+ 'dialog.blocked.title': string;
406
+ 'dialog.main.button.subscribe': string;
407
+ 'dialog.main.button.unsubscribe': string;
408
+ 'dialog.main.title': string;
409
+ 'message.action.resubscribed': string;
410
+ 'message.action.subscribed': string;
411
+ 'message.action.subscribing': string;
412
+ 'message.action.unsubscribed': string;
413
+ 'message.prenotify': string;
414
+ 'tip.state.blocked': string;
415
+ 'tip.state.subscribed': string;
416
+ 'tip.state.unsubscribed': string;
417
+ };
418
+ };
419
+
258
420
  persistNotification?: boolean;
259
- webhooks?: object;
421
+ webhooks?: {
422
+ /**
423
+ * Enable this setting only if your server has CORS enabled and supports non-simple CORS requests.
424
+ * If this setting is disabled, your webhook will not need CORS to receive data, but it will not receive the custom headers.
425
+ * The simplest option is to leave it disabled.
426
+ * @default false
427
+ */
428
+ cors: boolean;
429
+
430
+ /**
431
+ * This event occurs after a notification is clicked.
432
+ * @example https://site.com/hook
433
+ */
434
+ 'notification.clicked'?: string;
435
+
436
+ /**
437
+ * This event occurs after a notification is intentionally dismissed by the user (clicking the notification body or one of the notification action buttons does not trigger the dismissed webhook),
438
+ * after a group of notifications are all dismissed (with this notification as part of that group), or after a notification expires on its own time and disappears. This event is supported on Chrome only.
439
+ * @example https://site.com/hook
440
+ */
441
+ 'notification.dismissed'?: string;
442
+
443
+ /**
444
+ * This event occurs after a notification is displayed.
445
+ * @example https://site.com/hook
446
+ */
447
+ 'notification.willDisplay'?: string;
448
+ };
260
449
  autoResubscribe?: boolean;
261
450
  autoRegister?: boolean;
262
451
  notificationClickHandlerMatch?: string;
@@ -270,7 +459,7 @@ interface IInitObject {
270
459
  [key: string]: any;
271
460
  }
272
461
 
273
- interface IOneSignalOneSignal {
462
+ export interface IOneSignalOneSignal {
274
463
  Slidedown: IOneSignalSlidedown;
275
464
  Notifications: IOneSignalNotifications;
276
465
  Session: IOneSignalSession;
@@ -282,7 +471,7 @@ interface IOneSignalOneSignal {
282
471
  setConsentGiven(consent: boolean): Promise<void>;
283
472
  setConsentRequired(requiresConsent: boolean): Promise<void>;
284
473
  }
285
- interface IOneSignalNotifications {
474
+ export interface IOneSignalNotifications {
286
475
  permissionNative: NotificationPermission;
287
476
  permission: boolean;
288
477
  setDefaultUrl(url: string): Promise<void>;
@@ -292,7 +481,7 @@ interface IOneSignalNotifications {
292
481
  addEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
293
482
  removeEventListener<K extends NotificationEventName>(event: K, listener: (obj: NotificationEventTypeMap[K]) => void): void;
294
483
  }
295
- interface IOneSignalSlidedown {
484
+ export interface IOneSignalSlidedown {
296
485
  promptPush(options?: AutoPromptOptions): Promise<void>;
297
486
  promptPushCategories(options?: AutoPromptOptions): Promise<void>;
298
487
  promptSms(options?: AutoPromptOptions): Promise<void>;
@@ -301,14 +490,14 @@ interface IOneSignalSlidedown {
301
490
  addEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void;
302
491
  removeEventListener(event: SlidedownEventName, listener: (wasShown: boolean) => void): void;
303
492
  }
304
- interface IOneSignalDebug {
493
+ export interface IOneSignalDebug {
305
494
  setLogLevel(logLevel: string): void;
306
495
  }
307
- interface IOneSignalSession {
496
+ export interface IOneSignalSession {
308
497
  sendOutcome(outcomeName: string, outcomeWeight?: number): Promise<void>;
309
498
  sendUniqueOutcome(outcomeName: string): Promise<void>;
310
499
  }
311
- interface IOneSignalUser {
500
+ export interface IOneSignalUser {
312
501
  onesignalId: string | undefined;
313
502
  externalId: string | undefined;
314
503
  PushSubscription: IOneSignalPushSubscription;
@@ -330,7 +519,7 @@ interface IOneSignalUser {
330
519
  setLanguage(language: string): void;
331
520
  getLanguage(): string;
332
521
  }
333
- interface IOneSignalPushSubscription {
522
+ export interface IOneSignalPushSubscription {
334
523
  id: string | null | undefined;
335
524
  token: string | null | undefined;
336
525
  optedIn: boolean | undefined;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "onesignal-vue",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "Vue OneSignal Plugin: Make it easy to integrate OneSignal with your Vue App!",
5
- "author": "rgomezp",
5
+ "type": "module",
6
6
  "contributors": [
7
7
  {
8
8
  "name": "Rodrigo Gomez-Palacio"
@@ -13,9 +13,9 @@
13
13
  "main": "dist/index.js",
14
14
  "types": "dist/index.d.ts",
15
15
  "scripts": {
16
- "lint": "./node_modules/.bin/eslint . --ext .ts",
17
- "build": "yarn run lint && tsc",
18
- "prepare": "yarn run build"
16
+ "lint": "eslint . --ext .ts",
17
+ "build": "npm run lint && tsc",
18
+ "prepare": "npm run build"
19
19
  },
20
20
  "dependencies": {
21
21
  "vue": "^2.6.14"
package/tsconfig.json CHANGED
@@ -13,7 +13,6 @@
13
13
  "noImplicitThis": true,
14
14
  "noImplicitAny": false,
15
15
  "strictNullChecks": false,
16
- "suppressImplicitAnyIndexErrors": true,
17
16
  "noUnusedLocals": true,
18
17
  "noUnusedParameters": true,
19
18
  "allowSyntheticDefaultImports": true,
package/.eslintrc.js DELETED
@@ -1,44 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- env: {
4
- browser: true,
5
- es6: true,
6
- node: true,
7
- },
8
- settings: {
9
- "import/resolver": {
10
- node: {
11
- paths: ["src"],
12
- extensions: [
13
- ".js",
14
- ".ts",
15
- ],
16
- },
17
- },
18
- },
19
- globals: {
20
- Atomics: 'readonly',
21
- SharedArrayBuffer: 'readonly',
22
- },
23
- parser: '@typescript-eslint/parser',
24
- parserOptions: {
25
- ecmaVersion: 2018,
26
- sourceType: 'module',
27
- },
28
- plugins: [
29
- '@typescript-eslint',
30
- ],
31
- extends: [
32
- 'plugin:@typescript-eslint/recommended',
33
- ],
34
- rules: {
35
- "prefer-destructuring": 0,
36
- "no-param-reassign": 0,
37
- "import/extensions": 0,
38
- "dot-notation": 0,
39
- "no-continue": 0,
40
- "no-unused-vars": "off",
41
- "@typescript-eslint/no-unused-vars": ["error"],
42
- "no-prototype-builtins": "warn",
43
- },
44
- };
@@ -1,58 +0,0 @@
1
- /**
2
- * Based on probot-metadata - https://github.com/probot/metadata
3
- */
4
- const regex = /\n\n<!-- probot = (.*) -->/
5
-
6
- const { Octokit } = require("@octokit/action")
7
-
8
- const octokit = new Octokit()
9
-
10
- module.exports = (context, issue = null) => {
11
- console.log(context)
12
- const prefix = "onesignal-probot"
13
-
14
- if (!issue) issue = context.payload.issue
15
-
16
- return {
17
- async get (key = null) {
18
- let body = issue.body
19
-
20
- if (!body) {
21
- body = (await octokit.issues.get(issue)).data.body || ''
22
- }
23
-
24
- const match = body.match(regex)
25
-
26
- if (match) {
27
- const data = JSON.parse(match[1])[prefix]
28
- return key ? data && data[key] : data
29
- }
30
- },
31
-
32
- async set (key, value) {
33
- let body = issue.body
34
- let data = {}
35
-
36
- if (!body) body = (await octokit.issues.get(issue)).data.body || ''
37
-
38
- body = body.replace(regex, (_, json) => {
39
- data = JSON.parse(json)
40
- return ''
41
- })
42
-
43
- if (!data[prefix]) data[prefix] = {}
44
-
45
- if (typeof key === 'object') {
46
- Object.assign(data[prefix], key)
47
- } else {
48
- data[prefix][key] = value
49
- }
50
-
51
- body = `${body}\n\n<!-- probot = ${JSON.stringify(data)} -->`
52
-
53
- const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/")
54
- const issue_number = context.payload.issue.number
55
- return octokit.issues.update({ owner, repo, issue_number, body })
56
- }
57
- }
58
- }
@@ -1,47 +0,0 @@
1
- function calcResponseTimeForIssueCreatedAt(createdAt) {
2
- const issueOpenedDate = new Date(createdAt);
3
- const issueTriagedDate = new Date();
4
- const businessDaysResponseTime = calcBusinessDaysBetweenDates(issueOpenedDate, issueTriagedDate);
5
- return businessDaysResponseTime;
6
- }
7
-
8
- function calcBusinessDaysBetweenDates(openedDate, triagedDate) {
9
- let differenceInWeeks, responseTime;
10
- if (triagedDate < openedDate)
11
- return -1; // error code if dates transposed
12
- let openedDay = openedDate.getDay(); // day of week
13
- let triagedDay = triagedDate.getDay();
14
- openedDay = (openedDay == 0) ? 7 : openedDay; // change Sunday from 0 to 7
15
- triagedDay = (triagedDay == 0) ? 7 : triagedDay;
16
- openedDay = (openedDay > 5) ? 5 : openedDay; // only count weekdays
17
- triagedDay = (triagedDay > 5) ? 5 : triagedDay;
18
- // calculate differnece in weeks (1000mS * 60sec * 60min * 24hrs * 7 days = 604800000)
19
- differenceInWeeks = Math.floor((triagedDate.getTime() - openedDate.getTime()) / 604800000);
20
- if (openedDay < triagedDay) { //Equal to makes it reduce 5 days
21
- responseTime = (differenceInWeeks * 5) + (triagedDay - openedDay);
22
- }
23
- else if (openedDay == triagedDay) {
24
- responseTime = differenceInWeeks * 5;
25
- }
26
- else {
27
- responseTime = ((differenceInWeeks + 1) * 5) - (openedDay - triagedDay);
28
- }
29
- return (responseTime);
30
- }
31
-
32
- module.exports = async(context, osmetadata) => {
33
- const foundResponseTime = await osmetadata(context).get('response_time_in_business_days');
34
- if (foundResponseTime) {
35
- const foundString = "already found response time in business days: " + foundResponseTime
36
- console.log(foundString);
37
- return foundString;
38
- }
39
- if (context.payload.comment && context.payload.comment.author_association != "MEMBER" && context.payload.comment.author_association != "OWNER" && context.payload.comment.author_association != "CONTRIBUTOR") {
40
- return;
41
- }
42
- const businessDaysResponseTime = calcResponseTimeForIssueCreatedAt(context.payload.issue.created_at);
43
- console.log("response time in business days: " + businessDaysResponseTime);
44
- const result = osmetadata(context, context.payload.issue).set('response_time_in_business_days', businessDaysResponseTime)
45
- console.log("osmetadata update result: " + result);
46
- return "set response time in business days: " + businessDaysResponseTime;
47
- }
@@ -1,34 +0,0 @@
1
- # This is an action to close asana tasks that were generated by Github issues
2
-
3
- name: Zapier web hook
4
-
5
- # Controls when the workflow will run
6
- on:
7
- # Triggers the workflow on push or pull request events but only for the "main" branch
8
- issues:
9
- types: [closed]
10
-
11
- permissions:
12
- issues: read
13
-
14
- # A workflow run is made up of one or more jobs that can run sequentially or in parallel
15
- jobs:
16
- # This workflow contains a single job called "build"
17
- build:
18
- # The type of runner that the job will run on
19
- runs-on: ubuntu-latest
20
-
21
- # Steps represent a sequence of tasks that will be executed as part of the job
22
- steps:
23
- # Runs a set of commands using the runners shell
24
- - name: Call Zapier web hook to close Asana task
25
- if: ${{ !github.event.issue.pull_request }}
26
- env:
27
- ISSUE_TITLE: ${{ github.event.issue.title }}
28
- run: |
29
- curl --location --request POST 'https://hooks.zapier.com/hooks/catch/12728683/b7009qc/' \
30
- --header 'Content-Type: application/json' \
31
- --header 'Accept: application/json' \
32
- --data-raw '{
33
- "task_name" : "$ISSUE_TITLE"
34
- }'
@@ -1,41 +0,0 @@
1
- name: Release Drafter
2
-
3
- on:
4
- push:
5
- # branches to consider in the event; optional, defaults to all
6
- branches:
7
- - main
8
- # pull_request event is required only for autolabeler
9
- pull_request:
10
- # Only following types are handled by the action, but one can default to all as well
11
- types: [opened, reopened, synchronize]
12
- # pull_request_target event is required for autolabeler to support PRs from forks
13
- # pull_request_target:
14
- # types: [opened, reopened, synchronize]
15
-
16
- permissions:
17
- contents: read
18
-
19
- jobs:
20
- update_release_draft:
21
- permissions:
22
- # write permission is required to create a github release
23
- contents: write
24
- # write permission is required for autolabeler
25
- # otherwise, read permission is required at least
26
- pull-requests: write
27
- runs-on: ubuntu-latest
28
- steps:
29
- # (Optional) GitHub Enterprise requires GHE_HOST variable set
30
- #- name: Set GHE_HOST
31
- # run: |
32
- # echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" >> $GITHUB_ENV
33
-
34
- # Drafts your next Release notes as Pull Requests are merged into "master"
35
- - uses: release-drafter/release-drafter@v5
36
- # (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
37
- # with:
38
- # config-name: my-config.yml
39
- # disable-autolabeler: true
40
- env:
41
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}