From 53db0f13581668aaa85e8826c3fa43a4279a7515 Mon Sep 17 00:00:00 2001 From: emawby Date: Thu, 15 Sep 2022 14:30:45 -0700 Subject: [PATCH 01/11] adding 3 issue forms instead of an issue template --- .github/ISSUE_TEMPLATE/ask-question.yml | 27 ++++++++ .github/ISSUE_TEMPLATE/bug-report.yml | 72 +++++++++++++++++++++ .github/ISSUE_TEMPLATE/general-feedback.yml | 27 ++++++++ issue_template.md | 41 ------------ 4 files changed, 126 insertions(+), 41 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/ask-question.yml create mode 100644 .github/ISSUE_TEMPLATE/bug-report.yml create mode 100644 .github/ISSUE_TEMPLATE/general-feedback.yml delete mode 100644 issue_template.md diff --git a/.github/ISSUE_TEMPLATE/ask-question.yml b/.github/ISSUE_TEMPLATE/ask-question.yml new file mode 100644 index 00000000..0e11d6f0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/ask-question.yml @@ -0,0 +1,27 @@ +name: 🙋‍♂️ Ask a question +description: Tell us what's on your mind +title: "[question]: " +labels: ["question"] +# assignees: +# - OneSignal/ios-sdk +body: + - type: markdown + attributes: + value: | + Having issues integrating this SDK? + - type: textarea + id: question + attributes: + label: How can we help? + description: Specific question regarding integrating this SDK. + placeholder: How do I...? + validations: + required: true + - type: checkboxes + id: terms + attributes: + label: Code of Conduct + description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/OneSignal/OneSignal-Flutter-SDK/blob/main/CONTRIBUTING.md) + options: + - label: I agree to follow this project's Code of Conduct + required: true diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml new file mode 100644 index 00000000..6a16dd64 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -0,0 +1,72 @@ +name: 🪳 Bug report +description: File a bug report +title: "[Bug]: " +labels: ["bug", "triage"] +# assignees: +# - OneSignal/ios-sdk +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this bug report! + - type: textarea + id: what-happened + attributes: + label: What happened? + description: Provide a thorough description of whats going on. + placeholder: e.g. The latest version of the SDK causes my screen to go blank when I tap on the screen three times. + validations: + required: true + - type: textarea + id: reproduction-steps + attributes: + label: Steps to reproduce? + description: Provide as much detail as posible to reproduce the issue. + placeholder: | + 1. Install vX.Y.Z of dependency + 2. Launch the app on iOS device + 3. Tap the screen three times + 4. Note that the app crashes + render: Markdown + validations: + required: true + - type: textarea + id: what-are-expectations + attributes: + label: What did you expect to happen? + description: Also tell us, what did you expect to happen? + placeholder: I expected the app to continue running no matter how many times I tap the screen. + validations: + required: true + - type: input + id: flutter-sdk-version + attributes: + label: OneSignal Flutter SDK version + description: What version of the OneSignal Flutter SDK are you using? + placeholder: Release 3.4.1 + validations: + required: true + - type: checkboxes + id: platforms + attributes: + label: Which platform(s) are affected? + description: Indicate which mobile platforms this issue is affecting + options: + - label: iOS + required: false + - label: Android + required: false + - type: textarea + id: logs + attributes: + label: Relevant log output + description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. + render: Shell + - type: checkboxes + id: terms + attributes: + label: Code of Conduct + description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/OneSignal/OneSignal-Flutter-SDK/blob/main/CONTRIBUTING.md) + options: + - label: I agree to follow this project's Code of Conduct + required: true diff --git a/.github/ISSUE_TEMPLATE/general-feedback.yml b/.github/ISSUE_TEMPLATE/general-feedback.yml new file mode 100644 index 00000000..8a8c7e97 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/general-feedback.yml @@ -0,0 +1,27 @@ +name: 📣 General feedback +description: Tell us what's on your mind +title: "[Feedback]: " +labels: ["triage"] +# assignees: +# - OneSignal/ios-sdk +body: + - type: markdown + attributes: + value: | + Thanks for sharing your valuable feedback! + - type: textarea + id: feedback + attributes: + label: What's on your mind? + description: Feedback regarding this SDK. + placeholder: Share your feedback... + validations: + required: true + - type: checkboxes + id: terms + attributes: + label: Code of Conduct + description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/OneSignal/OneSignal-Flutter-SDK/blob/main/CONTRIBUTING.md) + options: + - label: I agree to follow this project's Code of Conduct + required: true diff --git a/issue_template.md b/issue_template.md deleted file mode 100644 index 6b1bd179..00000000 --- a/issue_template.md +++ /dev/null @@ -1,41 +0,0 @@ - - -**Description:** - - -(your description here) - -**Environment** - - - - -**Steps to Reproduce Issue:** - - -1. (your steps here) -2. -3. - -**Anything else:** - -(crash stacktraces, as well as any other information here) - - - From cb0f0012c4856b4bbe5f9af2f0d40b0445f0ae67 Mon Sep 17 00:00:00 2001 From: emawby Date: Wed, 26 Oct 2022 13:07:44 -0700 Subject: [PATCH 02/11] release 3.4.2 bumping version numbers and updating the iOS native sdk to 3.11.4 --- android/build.gradle | 2 +- ios/onesignal_flutter.podspec | 4 ++-- pubspec.yaml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 514bb374..c4e36f20 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ group 'com.onesignal.flutter' -version '3.4.1' +version '3.4.2' buildscript { repositories { diff --git a/ios/onesignal_flutter.podspec b/ios/onesignal_flutter.podspec index 41c97d04..961746cb 100644 --- a/ios/onesignal_flutter.podspec +++ b/ios/onesignal_flutter.podspec @@ -3,7 +3,7 @@ # Pod::Spec.new do |s| s.name = 'onesignal_flutter' - s.version = '3.4.1' + s.version = '3.4.2' s.summary = 'The OneSignal Flutter SDK' s.description = 'Allows you to easily add OneSignal to your flutter projects, to make sending and handling push notifications easy' s.homepage = 'https://www.onesignal.com' @@ -13,7 +13,7 @@ Pod::Spec.new do |s| s.source_files = 'Classes/**/*' s.public_header_files = 'Classes/**/*.h' s.dependency 'Flutter' - s.dependency 'OneSignalXCFramework', '3.11.2' + s.dependency 'OneSignalXCFramework', '3.11.4' s.ios.deployment_target = '9.0' s.static_framework = true end diff --git a/pubspec.yaml b/pubspec.yaml index 918fb139..6809e15d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: onesignal_flutter description: OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal -version: 3.4.1 +version: 3.4.2 author: Brad Hesse , Josh Kasten homepage: https://github.com/OneSignal/OneSignal-Flutter-SDK From 8e2d496ec4168851ce374fdb1a3cbbc5dc57d5f1 Mon Sep 17 00:00:00 2001 From: Nan Date: Thu, 24 Nov 2022 14:14:17 -0800 Subject: [PATCH 03/11] [example app] FlatButton deprecated * Replace with TextButton and migrate styles --- example/lib/main.dart | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 6413e530..ac0bc7b5 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -580,12 +580,14 @@ class OneSignalButtonState extends State { return new Table( children: [ new TableRow(children: [ - new FlatButton( - disabledColor: Color.fromARGB(180, 212, 86, 83), - disabledTextColor: Colors.white, - color: Color.fromARGB(255, 212, 86, 83), - textColor: Colors.white, - padding: EdgeInsets.all(8.0), + new TextButton( + style: TextButton.styleFrom( + foregroundColor:Colors.white, + disabledForegroundColor: Colors.white, + backgroundColor: Color.fromARGB(255, 212, 86, 83), + disabledBackgroundColor:Color.fromARGB(180, 212, 86, 83), + padding: EdgeInsets.all(8.0), + ), child: new Text(widget.title), onPressed: widget.enabled ? widget.onPressed : null, ) From 8ae9f60d9b4d401e84f5faf7cac0cd3f92d34f1a Mon Sep 17 00:00:00 2001 From: Nan Date: Tue, 29 Nov 2022 10:04:18 -0800 Subject: [PATCH 04/11] updating iOS version to '3.12.3' --- ios/onesignal_flutter.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/onesignal_flutter.podspec b/ios/onesignal_flutter.podspec index 961746cb..17bc242d 100644 --- a/ios/onesignal_flutter.podspec +++ b/ios/onesignal_flutter.podspec @@ -13,7 +13,7 @@ Pod::Spec.new do |s| s.source_files = 'Classes/**/*' s.public_header_files = 'Classes/**/*.h' s.dependency 'Flutter' - s.dependency 'OneSignalXCFramework', '3.11.4' + s.dependency 'OneSignalXCFramework', '3.12.3' s.ios.deployment_target = '9.0' s.static_framework = true end From 3891a707a1f6cb7fc73b381e891efad5686bea48 Mon Sep 17 00:00:00 2001 From: Nan Date: Tue, 29 Nov 2022 10:03:07 -0800 Subject: [PATCH 05/11] Adding bridging for live activities --- ios/Classes/OneSignalPlugin.m | 28 ++++++++++++++++++++++++++++ lib/onesignal_flutter.dart | 23 +++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/ios/Classes/OneSignalPlugin.m b/ios/Classes/OneSignalPlugin.m index fcc1aa6e..bb2d51c0 100644 --- a/ios/Classes/OneSignalPlugin.m +++ b/ios/Classes/OneSignalPlugin.m @@ -153,6 +153,10 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { [self initNotificationWillShowInForegroundHandlerParams]; else if ([@"OneSignal#completeNotification" isEqualToString:call.method]) [self completeNotification:call withResult:result]; + else if ([@"OneSignal#enterLiveActivity" isEqualToString:call.method]) + [self enterLiveActivity:call withResult:result]; + else if ([@"OneSignal#exitLiveActivity" isEqualToString:call.method]) + [self exitLiveActivity:call withResult:result]; else result(FlutterMethodNotImplemented); } @@ -403,6 +407,30 @@ - (void)completeNotification:(FlutterMethodCall *)call withResult:(FlutterResult [self.receivedNotificationCache removeObjectForKey:notificationId]; } +#pragma mark Live Activity + +- (void)enterLiveActivity:(FlutterMethodCall *)call withResult:(FlutterResult)result { + NSString *activityId = call.arguments[@"activityId"]; + NSString *token = call.arguments[@"token"]; + + [OneSignal enterLiveActivity:activityId withToken:token withSuccess:^(NSDictionary *results) { + result(results); + } withFailure:^(NSError *error) { + [OneSignal onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"enterLiveActivity Failure with error: %@", error]]; + result(error.flutterError); + }]; +} + +- (void)exitLiveActivity:(FlutterMethodCall *)call withResult:(FlutterResult)result { + NSString *activityId = call.arguments[@"activityId"]; + + [OneSignal exitLiveActivity:activityId withSuccess:^(NSDictionary *results) { + result(results); + } withFailure:^(NSError *error) { + [OneSignal onesignalLog:ONE_S_LL_VERBOSE message:[NSString stringWithFormat:@"exitLiveActivity Failure with error: %@", error]]; + result(error.flutterError); + }]; +} #pragma mark In App Message Click Handler - (void)handleInAppMessageClicked:(OSInAppMessageAction *)action { diff --git a/lib/onesignal_flutter.dart b/lib/onesignal_flutter.dart index 8911df0f..5049703d 100644 --- a/lib/onesignal_flutter.dart +++ b/lib/onesignal_flutter.dart @@ -312,6 +312,29 @@ class OneSignal { return await _channel.invokeMethod("OneSignal#clearOneSignalNotifications"); } + /// Only applies to iOS + /// Associates a temporary push token with an Activity ID on the OneSignal server. + Future enterLiveActivity(String activityId, String token) async { + if (Platform.isIOS) { + await _channel.invokeMethod("OneSignal#enterLiveActivity", {'activityId': activityId, 'token': token}); + } else { + _onesignalLog(OSLogLevel.info, + "enterLiveActivity: this function is not supported on Android"); + } + } + + /// Only applies to iOS + /// Deletes activityId associated temporary push token on the OneSignal server. + Future exitLiveActivity(String activityId) async { + if (Platform.isIOS) { + await _channel.invokeMethod("OneSignal#exitLiveActivity", + {'activityId': activityId}); + } else { + _onesignalLog(OSLogLevel.info, + "exitLiveActivity: this function is not supported on Android"); + } + } + /// Allows you to manually cancel a single OneSignal notification based on its Android notification integer ID void removeNotification(int notificationId) { _channel.invokeMethod("OneSignal#removeNotification", From 1eeed19337691ff64de33a0b6273e21320a6d21e Mon Sep 17 00:00:00 2001 From: Nan Date: Wed, 30 Nov 2022 10:58:16 -0800 Subject: [PATCH 06/11] release commit 3.5.0 * Bump version to 3.5.0 * iOS has been bumped to 3.12.3 already in a prior PR --- android/build.gradle | 2 +- ios/onesignal_flutter.podspec | 2 +- pubspec.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index c4e36f20..10002eff 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ group 'com.onesignal.flutter' -version '3.4.2' +version '3.5.0' buildscript { repositories { diff --git a/ios/onesignal_flutter.podspec b/ios/onesignal_flutter.podspec index 17bc242d..f7438eab 100644 --- a/ios/onesignal_flutter.podspec +++ b/ios/onesignal_flutter.podspec @@ -3,7 +3,7 @@ # Pod::Spec.new do |s| s.name = 'onesignal_flutter' - s.version = '3.4.2' + s.version = '3.5.0' s.summary = 'The OneSignal Flutter SDK' s.description = 'Allows you to easily add OneSignal to your flutter projects, to make sending and handling push notifications easy' s.homepage = 'https://www.onesignal.com' diff --git a/pubspec.yaml b/pubspec.yaml index 6809e15d..07d9a5e4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: onesignal_flutter description: OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal -version: 3.4.2 +version: 3.5.0 author: Brad Hesse , Josh Kasten homepage: https://github.com/OneSignal/OneSignal-Flutter-SDK From eaa2bd3093abdc5b77a678c136d804e5c786b8dc Mon Sep 17 00:00:00 2001 From: Elliot Mawby Date: Thu, 29 Dec 2022 12:50:42 -0800 Subject: [PATCH 07/11] add Zapier action Closes Asana tasks that are generated from Github issues --- .github/workflows/Zapier.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/Zapier.yml diff --git a/.github/workflows/Zapier.yml b/.github/workflows/Zapier.yml new file mode 100644 index 00000000..4eb356b3 --- /dev/null +++ b/.github/workflows/Zapier.yml @@ -0,0 +1,29 @@ +# This is an action to close asana tasks that were generated by Github issues + +name: Zapier web hook + +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the "main" branch + issues: + types: [closed] + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Runs a set of commands using the runners shell + - name: Call Zapier web hook to close Asana task + if: ${{ !github.event.issue.pull_request }} + run: | + curl --location --request POST 'https://hooks.zapier.com/hooks/catch/12728683/b7009qc/' \ + --header 'Content-Type: application/json' \ + --header 'Accept: application/json' \ + --data-raw '{ + "task_name" : "${{ github.event.issue.title }}" + }' From b4e711f6001fc715598a9f1ec2e34ea89dc1090c Mon Sep 17 00:00:00 2001 From: emawby Date: Wed, 4 Jan 2023 11:27:06 -0800 Subject: [PATCH 08/11] Adding the release drafter action this is the same release template as native SDKs with an added Dependency section where we can mention iOS and Android native SDK updates --- .github/release-drafter.yml | 27 +++++++++++++++++ .github/workflows/release-drafter.yml | 42 +++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/release-drafter.yml diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 00000000..a7a42bde --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,27 @@ +name-template: $RESOLVED_VERSION +tag-template: $RESOLVED_VERSION +categories: + - title: 🚀 Features + label: Enhancement / Feature + - title: 🐛 Bug Fixes + label: Bug + - title: 🧰 Improvements + label: Improvement + - title: down arrow Dependency Updates + label: Dependencies +change-template: '- $TITLE (#$NUMBER)' +version-resolver: + major: + labels: + - 'major' + minor: + labels: + - 'minor' + patch: + labels: + - 'patch' + default: patch +template: | + ## Other Changes + + $CHANGES diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 00000000..a64b3721 --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,42 @@ + +name: Release Drafter + +on: + push: + # branches to consider in the event; optional, defaults to all + branches: + - main + # pull_request event is required only for autolabeler + pull_request: + # Only following types are handled by the action, but one can default to all as well + types: [opened, reopened, synchronize] + # pull_request_target event is required for autolabeler to support PRs from forks + # pull_request_target: + # types: [opened, reopened, synchronize] + +permissions: + contents: read + +jobs: + update_release_draft: + permissions: + # write permission is required to create a github release + contents: write + # write permission is required for autolabeler + # otherwise, read permission is required at least + pull-requests: write + runs-on: ubuntu-latest + steps: + # (Optional) GitHub Enterprise requires GHE_HOST variable set + #- name: Set GHE_HOST + # run: | + # echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" >> $GITHUB_ENV + + # Drafts your next Release notes as Pull Requests are merged into "master" + - uses: release-drafter/release-drafter@v5 + # (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml + # with: + # config-name: my-config.yml + # disable-autolabeler: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From b8f8a1f9571e1d240011f380cf5aff3cc605f1e6 Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Fri, 10 Mar 2023 12:21:04 -0800 Subject: [PATCH 09/11] Update Zapier.yml --- .github/workflows/Zapier.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Zapier.yml b/.github/workflows/Zapier.yml index 4eb356b3..3665dd58 100644 --- a/.github/workflows/Zapier.yml +++ b/.github/workflows/Zapier.yml @@ -7,6 +7,9 @@ on: # Triggers the workflow on push or pull request events but only for the "main" branch issues: types: [closed] + +permissions: + issues: read # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: @@ -20,10 +23,12 @@ jobs: # Runs a set of commands using the runners shell - name: Call Zapier web hook to close Asana task if: ${{ !github.event.issue.pull_request }} + env: + ISSUE_TITLE: ${{ github.event.issue.title }} run: | curl --location --request POST 'https://hooks.zapier.com/hooks/catch/12728683/b7009qc/' \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --data-raw '{ - "task_name" : "${{ github.event.issue.title }}" + "task_name" : "$ISSUE_TITLE" }' From aa93b18b8e44b3af40007ce7881bb2987daa94a1 Mon Sep 17 00:00:00 2001 From: Nan Date: Thu, 16 Mar 2023 16:42:46 -0700 Subject: [PATCH 10/11] release commit 3.5.1 --- android/build.gradle | 4 ++-- ios/onesignal_flutter.podspec | 4 ++-- pubspec.yaml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 10002eff..054eeb10 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ group 'com.onesignal.flutter' -version '3.5.0' +version '3.5.1' buildscript { repositories { @@ -34,5 +34,5 @@ android { } dependencies { - api 'com.onesignal:OneSignal:4.8.2' + api 'com.onesignal:OneSignal:4.8.5' } diff --git a/ios/onesignal_flutter.podspec b/ios/onesignal_flutter.podspec index f7438eab..ae4cd460 100644 --- a/ios/onesignal_flutter.podspec +++ b/ios/onesignal_flutter.podspec @@ -3,7 +3,7 @@ # Pod::Spec.new do |s| s.name = 'onesignal_flutter' - s.version = '3.5.0' + s.version = '3.5.1' s.summary = 'The OneSignal Flutter SDK' s.description = 'Allows you to easily add OneSignal to your flutter projects, to make sending and handling push notifications easy' s.homepage = 'https://www.onesignal.com' @@ -13,7 +13,7 @@ Pod::Spec.new do |s| s.source_files = 'Classes/**/*' s.public_header_files = 'Classes/**/*.h' s.dependency 'Flutter' - s.dependency 'OneSignalXCFramework', '3.12.3' + s.dependency 'OneSignalXCFramework', '3.12.4' s.ios.deployment_target = '9.0' s.static_framework = true end diff --git a/pubspec.yaml b/pubspec.yaml index 07d9a5e4..1bb79f58 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: onesignal_flutter description: OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal -version: 3.5.0 +version: 3.5.1 author: Brad Hesse , Josh Kasten homepage: https://github.com/OneSignal/OneSignal-Flutter-SDK From 5217b634441c180d52f17ed50974305cafdeb673 Mon Sep 17 00:00:00 2001 From: emawby Date: Fri, 24 Mar 2023 13:19:30 -0700 Subject: [PATCH 11/11] Setting issue response time when an issue is closed or commented on by a OneSignal team member The action is triggered when an issue is closed or it is commented on by a OneSignal employee. This action sets the response time in business days for that issue inside the issue html as a comment. This is based on https://github.com/probot/metadata This PR does not include the script to calculate the response time --- .github/os_probot_metadata.js | 58 +++++++++++++++++++++++++ .github/set_response_times.js | 47 ++++++++++++++++++++ .github/workflows/set_response_time.yml | 32 ++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 .github/os_probot_metadata.js create mode 100644 .github/set_response_times.js create mode 100644 .github/workflows/set_response_time.yml diff --git a/.github/os_probot_metadata.js b/.github/os_probot_metadata.js new file mode 100644 index 00000000..9708a592 --- /dev/null +++ b/.github/os_probot_metadata.js @@ -0,0 +1,58 @@ +/** + * Based on probot-metadata - https://github.com/probot/metadata + */ +const regex = /\n\n/ + +const { Octokit } = require("@octokit/action") + +const octokit = new Octokit() + +module.exports = (context, issue = null) => { + console.log(context) + const prefix = "onesignal-probot" + + if (!issue) issue = context.payload.issue + + return { + async get (key = null) { + let body = issue.body + + if (!body) { + body = (await octokit.issues.get(issue)).data.body || '' + } + + const match = body.match(regex) + + if (match) { + const data = JSON.parse(match[1])[prefix] + return key ? data && data[key] : data + } + }, + + async set (key, value) { + let body = issue.body + let data = {} + + if (!body) body = (await octokit.issues.get(issue)).data.body || '' + + body = body.replace(regex, (_, json) => { + data = JSON.parse(json) + return '' + }) + + if (!data[prefix]) data[prefix] = {} + + if (typeof key === 'object') { + Object.assign(data[prefix], key) + } else { + data[prefix][key] = value + } + + body = `${body}\n\n` + + const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/") + const issue_number = context.payload.issue.number + return octokit.issues.update({ owner, repo, issue_number, body }) + } + } +} diff --git a/.github/set_response_times.js b/.github/set_response_times.js new file mode 100644 index 00000000..5bcac449 --- /dev/null +++ b/.github/set_response_times.js @@ -0,0 +1,47 @@ +function calcResponseTimeForIssueCreatedAt(createdAt) { + const issueOpenedDate = new Date(createdAt); + const issueTriagedDate = new Date(); + const businessDaysResponseTime = calcBusinessDaysBetweenDates(issueOpenedDate, issueTriagedDate); + return businessDaysResponseTime; +} + +function calcBusinessDaysBetweenDates(openedDate, triagedDate) { + let differenceInWeeks, responseTime; + if (triagedDate < openedDate) + return -1; // error code if dates transposed + let openedDay = openedDate.getDay(); // day of week + let triagedDay = triagedDate.getDay(); + openedDay = (openedDay == 0) ? 7 : openedDay; // change Sunday from 0 to 7 + triagedDay = (triagedDay == 0) ? 7 : triagedDay; + openedDay = (openedDay > 5) ? 5 : openedDay; // only count weekdays + triagedDay = (triagedDay > 5) ? 5 : triagedDay; + // calculate differnece in weeks (1000mS * 60sec * 60min * 24hrs * 7 days = 604800000) + differenceInWeeks = Math.floor((triagedDate.getTime() - openedDate.getTime()) / 604800000); + if (openedDay < triagedDay) { //Equal to makes it reduce 5 days + responseTime = (differenceInWeeks * 5) + (triagedDay - openedDay); + } + else if (openedDay == triagedDay) { + responseTime = differenceInWeeks * 5; + } + else { + responseTime = ((differenceInWeeks + 1) * 5) - (openedDay - triagedDay); + } + return (responseTime); +} + +module.exports = async(context, osmetadata) => { + const foundResponseTime = await osmetadata(context).get('response_time_in_business_days'); + if (foundResponseTime) { + const foundString = "already found response time in business days: " + foundResponseTime + console.log(foundString); + return foundString; + } + if (context.payload.comment && context.payload.comment.author_association != "MEMBER" && context.payload.comment.author_association != "OWNER" && context.payload.comment.author_association != "CONTRIBUTOR") { + return; + } + const businessDaysResponseTime = calcResponseTimeForIssueCreatedAt(context.payload.issue.created_at); + console.log("response time in business days: " + businessDaysResponseTime); + const result = osmetadata(context, context.payload.issue).set('response_time_in_business_days', businessDaysResponseTime) + console.log("osmetadata update result: " + result); + return "set response time in business days: " + businessDaysResponseTime; +} diff --git a/.github/workflows/set_response_time.yml b/.github/workflows/set_response_time.yml new file mode 100644 index 00000000..e77fc84d --- /dev/null +++ b/.github/workflows/set_response_time.yml @@ -0,0 +1,32 @@ +name: Set Response Time +on: + issue_comment: + types: + - created + issues: + types: + - closed +jobs: + calculate: + name: set reponse time for the issue + if: github.event.issue.pull_request == null + runs-on: ubuntu-latest + permissions: + issues: write + steps: + - uses: actions/checkout@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - run: npm install @octokit/action + - uses: actions/github-script@v6 + id: set-time + with: + result-encoding: string + script: | + const os_probot_metadata = require('./.github/os_probot_metadata.js') + const set_response_time = require('./.github/set_response_times.js') + return await set_response_time(context, os_probot_metadata) + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Get result + run: echo "${{steps.set-time.outputs.result}}" >> $GITHUB_STEP_SUMMARY