onesignal-expo-plugin 2.0.1 → 2.0.3-beta.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.
@@ -0,0 +1,58 @@
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
+ }
@@ -0,0 +1,47 @@
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
+ }
@@ -0,0 +1,32 @@
1
+ name: Set Response Time
2
+ on:
3
+ issue_comment:
4
+ types:
5
+ - created
6
+ issues:
7
+ types:
8
+ - closed
9
+ jobs:
10
+ calculate:
11
+ name: set reponse time for the issue
12
+ if: github.event.issue.pull_request == null
13
+ runs-on: ubuntu-latest
14
+ permissions:
15
+ issues: write
16
+ steps:
17
+ - uses: actions/checkout@v3
18
+ with:
19
+ token: ${{ secrets.GITHUB_TOKEN }}
20
+ - run: npm install @octokit/action@6.0.6
21
+ - uses: actions/github-script@v6
22
+ id: set-time
23
+ with:
24
+ result-encoding: string
25
+ script: |
26
+ const os_probot_metadata = require('./.github/os_probot_metadata.js')
27
+ const set_response_time = require('./.github/set_response_times.js')
28
+ return await set_response_time(context, os_probot_metadata)
29
+ env:
30
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31
+ - name: Get result
32
+ run: echo "${{steps.set-time.outputs.result}}" >> $GITHUB_STEP_SUMMARY
package/README.md CHANGED
@@ -105,7 +105,7 @@ Add your OneSignal App ID to your [Expo constants via the `extra` param](https:/
105
105
  You can then access the value to pass to the `initialize` function:
106
106
 
107
107
  ```js
108
- import OneSignal from 'react-native-onesignal';
108
+ import { OneSignal } from 'react-native-onesignal';
109
109
  import Constants from "expo-constants";
110
110
  OneSignal.initialize(Constants.expoConfig.extra.oneSignalAppId);
111
111
  ```
@@ -141,13 +141,17 @@ const withOneSignalXcodeProject = (config, props) => {
141
141
  return (0, config_plugins_1.withXcodeProject)(config, newConfig => {
142
142
  var _a, _b;
143
143
  const xcodeProject = newConfig.modResults;
144
+ if (!!xcodeProject.pbxTargetByName(iosConstants_1.NSE_TARGET_NAME)) {
145
+ OneSignalLog_1.OneSignalLog.log(`${iosConstants_1.NSE_TARGET_NAME} already exists in project. Skipping...`);
146
+ return newConfig;
147
+ }
144
148
  // Create new PBXGroup for the extension
145
149
  const extGroup = xcodeProject.addPbxGroup([...iosConstants_1.NSE_EXT_FILES, iosConstants_1.NSE_SOURCE_FILE], iosConstants_1.NSE_TARGET_NAME, iosConstants_1.NSE_TARGET_NAME);
146
150
  // Add the new PBXGroup to the top level group. This makes the
147
151
  // files / folder appear in the file explorer in Xcode.
148
152
  const groups = xcodeProject.hash.project.objects["PBXGroup"];
149
153
  Object.keys(groups).forEach(function (key) {
150
- if (groups[key].name === undefined) {
154
+ if (typeof groups[key] === "object" && groups[key].name === undefined && groups[key].path === undefined) {
151
155
  xcodeProject.addToPbxGroup(extGroup.uuid, key);
152
156
  }
153
157
  });
@@ -158,10 +162,6 @@ const withOneSignalXcodeProject = (config, props) => {
158
162
  const projObjects = xcodeProject.hash.project.objects;
159
163
  projObjects['PBXTargetDependency'] = projObjects['PBXTargetDependency'] || {};
160
164
  projObjects['PBXContainerItemProxy'] = projObjects['PBXTargetDependency'] || {};
161
- if (!!xcodeProject.pbxTargetByName(iosConstants_1.NSE_TARGET_NAME)) {
162
- OneSignalLog_1.OneSignalLog.log(`${iosConstants_1.NSE_TARGET_NAME} already exists in project. Skipping...`);
163
- return newConfig;
164
- }
165
165
  // Add the NSE target
166
166
  // This adds PBXTargetDependency and PBXContainerItemProxy for you
167
167
  const nseTarget = xcodeProject.addTarget(iosConstants_1.NSE_TARGET_NAME, "app_extension", iosConstants_1.NSE_TARGET_NAME, `${(_a = config.ios) === null || _a === void 0 ? void 0 : _a.bundleIdentifier}.${iosConstants_1.NSE_TARGET_NAME}`);
@@ -154,14 +154,19 @@ const withOneSignalXcodeProject: ConfigPlugin<OneSignalPluginProps> = (config, p
154
154
  return withXcodeProject(config, newConfig => {
155
155
  const xcodeProject = newConfig.modResults
156
156
 
157
+ if (!!xcodeProject.pbxTargetByName(NSE_TARGET_NAME)) {
158
+ OneSignalLog.log(`${NSE_TARGET_NAME} already exists in project. Skipping...`);
159
+ return newConfig;
160
+ }
161
+
157
162
  // Create new PBXGroup for the extension
158
163
  const extGroup = xcodeProject.addPbxGroup([...NSE_EXT_FILES, NSE_SOURCE_FILE], NSE_TARGET_NAME, NSE_TARGET_NAME);
159
-
164
+
160
165
  // Add the new PBXGroup to the top level group. This makes the
161
166
  // files / folder appear in the file explorer in Xcode.
162
167
  const groups = xcodeProject.hash.project.objects["PBXGroup"];
163
168
  Object.keys(groups).forEach(function(key) {
164
- if (groups[key].name === undefined) {
169
+ if (typeof groups[key] === "object" && groups[key].name === undefined && groups[key].path === undefined) {
165
170
  xcodeProject.addToPbxGroup(extGroup.uuid, key);
166
171
  }
167
172
  });
@@ -174,11 +179,6 @@ const withOneSignalXcodeProject: ConfigPlugin<OneSignalPluginProps> = (config, p
174
179
  projObjects['PBXTargetDependency'] = projObjects['PBXTargetDependency'] || {};
175
180
  projObjects['PBXContainerItemProxy'] = projObjects['PBXTargetDependency'] || {};
176
181
 
177
- if (!!xcodeProject.pbxTargetByName(NSE_TARGET_NAME)) {
178
- OneSignalLog.log(`${NSE_TARGET_NAME} already exists in project. Skipping...`);
179
- return newConfig;
180
- }
181
-
182
182
  // Add the NSE target
183
183
  // This adds PBXTargetDependency and PBXContainerItemProxy for you
184
184
  const nseTarget = xcodeProject.addTarget(NSE_TARGET_NAME, "app_extension", NSE_TARGET_NAME, `${config.ios?.bundleIdentifier}.${NSE_TARGET_NAME}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "onesignal-expo-plugin",
3
- "version": "2.0.1",
3
+ "version": "2.0.3-beta.0",
4
4
  "description": "The OneSignal Expo plugin allows you to use OneSignal without leaving the managed workflow. Developed in collaboration with SweetGreen.",
5
5
  "main": "./app.plugin.js",
6
6
  "scripts": {