From c82d12c1ca7038fde9a160a795e163ac6863e307 Mon Sep 17 00:00:00 2001 From: Ahmed Mahmoud Date: Tue, 20 Feb 2024 17:04:53 +0200 Subject: [PATCH 1/5] feat(android): add native runtime setCodePushVersion --- .../reactlibrary/RNInstabugReactnativeModule.java | 14 ++++++++++++++ .../RNInstabugReactnativeModuleTest.java | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java index 514b98f7d2..a618155d2b 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java @@ -160,6 +160,20 @@ public void run() { }); } + @ReactMethod + public void setCodePushVersion(@Nullable String version) { + MainThreadHandler.runOnMainThread(new Runnable() { + @Override + public void run() { + try { + Instabug.setCodePushVersion(version); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + /** * Adds tag(s) to issues before sending them diff --git a/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java b/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java index 88174949ae..26eab7e41d 100644 --- a/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java +++ b/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java @@ -199,6 +199,15 @@ public void tearDown() { Instabug.setPrimaryColor(color); } + @Test + public void testSetCodePushVersion() { + String codePushVersion = "123"; + + rnModule.setCodePushVersion(codePushVersion); + + mockInstabug.verify(() -> Instabug.setCodePushVersion(codePushVersion)); + } + @Test public void testIdentifyUserWithNoId() { // given From 46ac22fd157b51edfdb2bf1c69cc67654b303b3f Mon Sep 17 00:00:00 2001 From: Ahmed Mahmoud Date: Tue, 20 Feb 2024 18:30:45 +0200 Subject: [PATCH 2/5] feat(ios): add native runtime setCodePushVersion --- examples/default/ios/InstabugTests/InstabugSampleTests.m | 9 +++++++++ ios/RNInstabug/InstabugReactBridge.h | 2 ++ ios/RNInstabug/InstabugReactBridge.m | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/examples/default/ios/InstabugTests/InstabugSampleTests.m b/examples/default/ios/InstabugTests/InstabugSampleTests.m index 1b8183a068..6cb52c1bb9 100644 --- a/examples/default/ios/InstabugTests/InstabugSampleTests.m +++ b/examples/default/ios/InstabugTests/InstabugSampleTests.m @@ -81,6 +81,15 @@ - (void)testInit { OCMVerify([self.mRNInstabug initWithToken:appToken invocationEvents:floatingButtonInvocationEvent debugLogsLevel:sdkDebugLogsLevel useNativeNetworkInterception:useNativeNetworkInterception]); } +- (void)testSetCodePushVersion { + id mock = OCMClassMock([Instabug class]); + NSString *codePushVersion = @"123"; + + [self.instabugBridge setCodePushVersion:codePushVersion]; + + OCMVerify([mock setCodePushVersion:codePushVersion]); +} + - (void)testSetUserData { id mock = OCMClassMock([Instabug class]); NSString *userData = @"user_data"; diff --git a/ios/RNInstabug/InstabugReactBridge.h b/ios/RNInstabug/InstabugReactBridge.h index f3eb9e81a9..2b8cea1214 100644 --- a/ios/RNInstabug/InstabugReactBridge.h +++ b/ios/RNInstabug/InstabugReactBridge.h @@ -29,6 +29,8 @@ - (void)init:(NSString *)token invocationEvents:(NSArray *)invocationEventsArray debugLogsLevel:(IBGSDKDebugLogsLevel)sdkDebugLogsLevel useNativeNetworkInterception:(BOOL)useNativeNetworkInterception codePushVersion:(NSString *)codePushVersion; +- (void)setCodePushVersion:(NSString *)version; + - (void)setUserData:(NSString *)userData; - (void)setTrackUserSteps:(BOOL)isEnabled; diff --git a/ios/RNInstabug/InstabugReactBridge.m b/ios/RNInstabug/InstabugReactBridge.m index 1ba3658299..a03bdda952 100644 --- a/ios/RNInstabug/InstabugReactBridge.m +++ b/ios/RNInstabug/InstabugReactBridge.m @@ -56,6 +56,10 @@ - (dispatch_queue_t)methodQueue { useNativeNetworkInterception:useNativeNetworkInterception]; } +RCT_EXPORT_METHOD(setCodePushVersion:(NSString *)version) { + [Instabug setCodePushVersion:version]; +} + RCT_EXPORT_METHOD(setReproStepsConfig:(IBGUserStepsMode)bugMode :(IBGUserStepsMode)crashMode:(IBGUserStepsMode)sessionReplayMode) { [Instabug setReproStepsFor:IBGIssueTypeBug withMode:bugMode]; [Instabug setReproStepsFor:IBGIssueTypeCrash withMode:crashMode]; From 116439901a304f8c3f03e15899d98c8c3e54c834 Mon Sep 17 00:00:00 2001 From: Ahmed Mahmoud Date: Wed, 21 Feb 2024 11:11:04 +0200 Subject: [PATCH 3/5] feat: add runtime code push version API --- src/modules/Instabug.ts | 8 ++++++++ src/native/NativeInstabug.ts | 1 + 2 files changed, 9 insertions(+) diff --git a/src/modules/Instabug.ts b/src/modules/Instabug.ts index 781371c183..28a0ff46c5 100644 --- a/src/modules/Instabug.ts +++ b/src/modules/Instabug.ts @@ -90,6 +90,14 @@ export const init = (config: InstabugConfig) => { }, 1000); }; +/** + * Sets the Code Push version to be sent with each report. + * @param version the Code Push version. + */ +export const setCodePushVersion = (version: string) => { + NativeInstabug.setCodePushVersion(version); +}; + /** * Attaches user data to each report being sent. * Each call to this method overrides the user data to be attached. diff --git a/src/native/NativeInstabug.ts b/src/native/NativeInstabug.ts index f1adba7e9f..75145ad190 100644 --- a/src/native/NativeInstabug.ts +++ b/src/native/NativeInstabug.ts @@ -29,6 +29,7 @@ export interface InstabugNativeModule extends NativeModule { show(): void; // Misc APIs // + setCodePushVersion(version: string): void; setIBGLogPrintsToConsole(printsToConsole: boolean): void; setSessionProfilerEnabled(isEnabled: boolean): void; From b6299a07886d6416353d7b7e9325731b65fd9f32 Mon Sep 17 00:00:00 2001 From: Ahmed Mahmoud Date: Wed, 21 Feb 2024 11:13:47 +0200 Subject: [PATCH 4/5] test: add tests for runtime code push version API --- test/mocks/mockInstabug.ts | 1 + test/modules/Instabug.spec.ts | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/test/mocks/mockInstabug.ts b/test/mocks/mockInstabug.ts index 6353cf64c7..9bb04e5cf5 100644 --- a/test/mocks/mockInstabug.ts +++ b/test/mocks/mockInstabug.ts @@ -13,6 +13,7 @@ const mockInstabug: InstabugNativeModule = { removeListeners: jest.fn(), setEnabled: jest.fn(), init: jest.fn(), + setCodePushVersion: jest.fn(), setUserData: jest.fn(), setTrackUserSteps: jest.fn(), setIBGLogPrintsToConsole: jest.fn(), diff --git a/test/modules/Instabug.spec.ts b/test/modules/Instabug.spec.ts index a78e141a14..4af5cea2fe 100644 --- a/test/modules/Instabug.spec.ts +++ b/test/modules/Instabug.spec.ts @@ -257,6 +257,15 @@ describe('Instabug Module', () => { ); }); + it('setCodePushVersion should call native method setCodePushVersion', () => { + const codePushVersion = '123'; + + Instabug.setCodePushVersion(codePushVersion); + + expect(NativeInstabug.setCodePushVersion).toBeCalledTimes(1); + expect(NativeInstabug.setCodePushVersion).toBeCalledWith(codePushVersion); + }); + it('init should disable JavaScript interceptor when using native interception mode', () => { const instabugConfig = { token: 'some-token', From b71f132127c4020517fa44f1f26f0e6772a3c2d0 Mon Sep 17 00:00:00 2001 From: Ahmed Mahmoud Date: Wed, 21 Feb 2024 11:24:05 +0200 Subject: [PATCH 5/5] chore: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e614b3c0da..c52a56c412 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Adds symbol files upload script ([#1137](https://github.com/Instabug/Instabug-React-Native/pull/1137)) - Support enabling NDK crash capturing on Android ([#1132](https://github.com/Instabug/Instabug-React-Native/pull/1132)). +- Support setting the Code Push version after SDK initialization ([#1143](https://github.com/Instabug/Instabug-React-Native/pull/1143)). ## [12.7.1](https://github.com/Instabug/Instabug-React-Native/compare/v12.7.0...v12.7.1) (February 15, 2024)