Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: add runtime code push version API #1143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions examples/default/ios/InstabugTests/InstabugSampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 2 additions & 0 deletions ios/RNInstabug/InstabugReactBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions ios/RNInstabug/InstabugReactBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
8 changes: 8 additions & 0 deletions src/modules/Instabug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/native/NativeInstabug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions test/mocks/mockInstabug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
9 changes: 9 additions & 0 deletions test/modules/Instabug.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down