From a5a6de630c0f9bea855c75c13821dc25805ab58f Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Fri, 27 Mar 2020 16:57:58 +0000 Subject: [PATCH 1/2] feat: rename notifyReleaseStages to enabledReleaseStages --- CHANGELOG.md | 3 +++ Source/BugsnagConfiguration.h | 2 +- Source/BugsnagConfiguration.m | 22 +++++++++---------- Source/BugsnagEvent.m | 10 ++++----- Source/BugsnagKeys.h | 2 +- Source/BugsnagSink.m | 10 ++++----- Tests/BugsnagConfigurationTests.m | 22 +++++++++---------- Tests/BugsnagEventTests.m | 8 +++---- UPGRADING.md | 5 ++++- .../scenarios/ReleaseStageScenarios.swift | 12 +++++----- .../BugsnagEventFromKSCrashReportTest.m | 8 +++---- 11 files changed, 55 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5cf3be48..ed33e472f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ Bugsnag Notifiers on other platforms. ## Enhancements +* Rename `notifyReleaseStages` to `enabledReleaseStages` + [#509](https://github.com/bugsnag/bugsnag-cocoa/pull/509) + * Rename setUser/user interface on `Bugsnag` and `BugsnagConfiguration` [#505](https://github.com/bugsnag/bugsnag-cocoa/pull/505) diff --git a/Source/BugsnagConfiguration.h b/Source/BugsnagConfiguration.h index e961cc71b..7b47363c1 100644 --- a/Source/BugsnagConfiguration.h +++ b/Source/BugsnagConfiguration.h @@ -94,7 +94,7 @@ typedef NS_OPTIONS(NSUInteger, BSGErrorType) { /** * Release stages which are allowed to notify Bugsnag */ -@property(readwrite, retain, nullable) NSArray *notifyReleaseStages; +@property(readwrite, retain, nullable) NSArray *enabledReleaseStages; /** * A general summary of what was occuring in the application */ diff --git a/Source/BugsnagConfiguration.m b/Source/BugsnagConfiguration.m index 2deb079f3..8f1852077 100644 --- a/Source/BugsnagConfiguration.m +++ b/Source/BugsnagConfiguration.m @@ -139,7 +139,7 @@ - (instancetype _Nonnull)initWithApiKey:(NSString *_Nonnull)apiKey _onSendBlocks = [NSMutableArray new]; _onSessionBlocks = [NSMutableArray new]; _plugins = [NSMutableSet new]; - _notifyReleaseStages = nil; + _enabledReleaseStages = nil; _breadcrumbs = [BugsnagBreadcrumbs new]; _autoTrackSessions = YES; // Default to recording all error types @@ -184,8 +184,8 @@ - (instancetype _Nonnull)initWithApiKey:(NSString *_Nonnull)apiKey * @return YES if reports should be sent based on this configuration */ - (BOOL)shouldSendReports { - return self.notifyReleaseStages.count == 0 || - [self.notifyReleaseStages containsObject:self.releaseStage]; + return self.enabledReleaseStages.count == 0 || + [self.enabledReleaseStages containsObject:self.releaseStage]; } - (void)setUser:(NSString *_Nullable)userId @@ -457,21 +457,21 @@ - (void)setAutoNotify:(BOOL)autoNotify { // MARK: - -@synthesize notifyReleaseStages = _notifyReleaseStages; +@synthesize enabledReleaseStages = _enabledReleaseStages; -- (NSArray *)notifyReleaseStages { +- (NSArray *)enabledReleaseStages { @synchronized (self) { - return _notifyReleaseStages; + return _enabledReleaseStages; } } -- (void)setNotifyReleaseStages:(NSArray *)newNotifyReleaseStages; +- (void)setEnabledReleaseStages:(NSArray *)newReleaseStages; { @synchronized (self) { - NSArray *notifyReleaseStagesCopy = [newNotifyReleaseStages copy]; - _notifyReleaseStages = notifyReleaseStagesCopy; - [self.config addAttribute:BSGKeyNotifyReleaseStages - withValue:notifyReleaseStagesCopy + NSArray *releaseStagesCopy = [newReleaseStages copy]; + _enabledReleaseStages = releaseStagesCopy; + [self.config addAttribute:BSGKeyEnabledReleaseStages + withValue:releaseStagesCopy toTabWithName:BSGKeyConfig]; } } diff --git a/Source/BugsnagEvent.m b/Source/BugsnagEvent.m index dac3341ad..0b737d84d 100644 --- a/Source/BugsnagEvent.m +++ b/Source/BugsnagEvent.m @@ -266,7 +266,7 @@ - (BOOL)shouldBeSent; /** * The release stages used to notify at the time this report is captured */ -@property(readwrite, copy, nullable) NSArray *notifyReleaseStages; +@property(readwrite, copy, nullable) NSArray *enabledReleaseStages; /** * Property overrides @@ -319,7 +319,7 @@ - (instancetype)initWithKSReport:(NSDictionary *)report { } } } else { - _notifyReleaseStages = BSGLoadConfigValue(report, @"notifyReleaseStages"); + _enabledReleaseStages = BSGLoadConfigValue(report, @"notifyReleaseStages"); _releaseStage = BSGParseReleaseStage(report); _threads = [report valueForKeyPath:@"crash.threads"]; RegisterErrorData *data = [RegisterErrorData errorDataFromThreads:_threads]; @@ -392,7 +392,7 @@ - (instancetype)initWithKSReport:(NSDictionary *)report { _overrides = [NSDictionary new]; _metadata = metadata ?: [NSDictionary new]; _releaseStage = config.releaseStage; - _notifyReleaseStages = config.notifyReleaseStages; + _enabledReleaseStages = config.enabledReleaseStages; // Set context based on current values. May be nil. _context = metadata[BSGKeyContext] ?: [[Bugsnag configuration] context]; NSMutableArray *crumbs = [NSMutableArray new]; @@ -524,8 +524,8 @@ - (void)setApiKey:(NSString *)apiKey { } - (BOOL)shouldBeSent { - return [self.notifyReleaseStages containsObject:self.releaseStage] || - (self.notifyReleaseStages.count == 0 && + return [self.enabledReleaseStages containsObject:self.releaseStage] || + (self.enabledReleaseStages.count == 0 && [[Bugsnag configuration] shouldSendReports]); } diff --git a/Source/BugsnagKeys.h b/Source/BugsnagKeys.h index da39ba3b0..5af422432 100644 --- a/Source/BugsnagKeys.h +++ b/Source/BugsnagKeys.h @@ -29,7 +29,7 @@ static NSString *const BSGKeyReleaseStage = @"releaseStage"; static NSString *const BSGKeyConfig = @"config"; static NSString *const BSGKeyContext = @"context"; static NSString *const BSGKeyAppVersion = @"appVersion"; -static NSString *const BSGKeyNotifyReleaseStages = @"notifyReleaseStages"; +static NSString *const BSGKeyEnabledReleaseStages = @"notifyReleaseStages"; static NSString *const BSGKeyApiKey = @"apiKey"; static NSString *const BSGKeyNotifier = @"notifier"; static NSString *const BSGKeyEvents = @"events"; diff --git a/Source/BugsnagSink.m b/Source/BugsnagSink.m index b676d7dd7..7fa26e16c 100644 --- a/Source/BugsnagSink.m +++ b/Source/BugsnagSink.m @@ -63,13 +63,13 @@ - (instancetype)initWithApiClient:(BugsnagErrorReportApiClient *)apiClient { // Entry point called by BSG_KSCrash when a report needs to be sent. Handles // report filtering based on the configuration options for -// `notifyReleaseStages`. Removes all reports not meeting at least one of the +// `enabledReleaseStages`. Removes all reports not meeting at least one of the // following conditions: -// - the report-specific config specifies the `notifyReleaseStages` property and +// - the report-specific config specifies the `enabledReleaseStages` property and // it contains the current stage -// - the report-specific and global `notifyReleaseStages` properties are unset -// - the report-specific `notifyReleaseStages` property is unset and the global -// `notifyReleaseStages` property +// - the report-specific and global `enabledReleaseStages` properties are unset +// - the report-specific `enabledReleaseStages` property is unset and the global +// `enabledReleaseStages` property // and it contains the current stage - (void)filterReports:(NSDictionary *)reports onCompletion:(BSG_KSCrashReportFilterCompletion)onCompletion { diff --git a/Tests/BugsnagConfigurationTests.m b/Tests/BugsnagConfigurationTests.m index babfec355..14ef39f09 100644 --- a/Tests/BugsnagConfigurationTests.m +++ b/Tests/BugsnagConfigurationTests.m @@ -246,43 +246,43 @@ - (void)testRemoveNonexistentOnSessionBlocks { // MARK: - Release stage-related // ============================================================================= -- (void)testNotifyReleaseStagesDefaultSends { +- (void)testEnabledReleaseStagesDefaultSends { BugsnagConfiguration *config = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1]; XCTAssertTrue([config shouldSendReports]); } -- (void)testNotifyReleaseStagesNilSends { +- (void)testEnabledReleaseStagesNilSends { BugsnagConfiguration *config = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1]; config.releaseStage = @"beta"; - config.notifyReleaseStages = nil; + config.enabledReleaseStages = nil; XCTAssertTrue([config shouldSendReports]); } -- (void)testNotifyReleaseStagesEmptySends { +- (void)testEnabledReleaseStagesEmptySends { BugsnagConfiguration *config = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1]; config.releaseStage = @"beta"; - config.notifyReleaseStages = @[]; + config.enabledReleaseStages = @[]; XCTAssertTrue([config shouldSendReports]); } -- (void)testNotifyReleaseStagesIncludedSends { +- (void)testEnabledReleaseStagesIncludedSends { BugsnagConfiguration *config = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1]; config.releaseStage = @"beta"; - config.notifyReleaseStages = @[ @"beta" ]; + config.enabledReleaseStages = @[ @"beta" ]; XCTAssertTrue([config shouldSendReports]); } -- (void)testNotifyReleaseStagesIncludedInManySends { +- (void)testEnabledReleaseStagesIncludedInManySends { BugsnagConfiguration *config = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1]; config.releaseStage = @"beta"; - config.notifyReleaseStages = @[ @"beta", @"production" ]; + config.enabledReleaseStages = @[ @"beta", @"production" ]; XCTAssertTrue([config shouldSendReports]); } -- (void)testNotifyReleaseStagesExcludedSkipsSending { +- (void)testEnabledReleaseStagesExcludedSkipsSending { BugsnagConfiguration *config = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1]; config.releaseStage = @"beta"; - config.notifyReleaseStages = @[ @"production" ]; + config.enabledReleaseStages = @[ @"production" ]; XCTAssertFalse([config shouldSendReports]); } diff --git a/Tests/BugsnagEventTests.m b/Tests/BugsnagEventTests.m index d0a26c47a..a6eda8b7c 100644 --- a/Tests/BugsnagEventTests.m +++ b/Tests/BugsnagEventTests.m @@ -36,9 +36,9 @@ @interface BugsnagEventTests : BugsnagBaseUnitTest @implementation BugsnagEventTests -- (void)testNotifyReleaseStagesSendsFromConfig { +- (void)testEnabledReleaseStagesSendsFromConfig { BugsnagConfiguration *config = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1]; - config.notifyReleaseStages = @[ @"foo" ]; + config.enabledReleaseStages = @[ @"foo" ]; config.releaseStage = @"foo"; BugsnagHandledState *state = [BugsnagHandledState handledStateWithSeverityReason:HandledException]; @@ -52,9 +52,9 @@ - (void)testNotifyReleaseStagesSendsFromConfig { XCTAssertTrue([event shouldBeSent]); } -- (void)testNotifyReleaseStagesSkipsSendFromConfig { +- (void)testEnabledReleaseStagesSkipsSendFromConfig { BugsnagConfiguration *config = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1]; - config.notifyReleaseStages = @[ @"foo", @"bar" ]; + config.enabledReleaseStages = @[ @"foo", @"bar" ]; config.releaseStage = @"not foo or bar"; BugsnagHandledState *state = diff --git a/UPGRADING.md b/UPGRADING.md index 87020135f..f9f9fb8c7 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -65,6 +65,9 @@ The exact error is available using the `BSGConfigurationErrorDomain` and - config.notifierType + config.appType + +- config.notifyReleaseStages ++ config.enabledReleaseStages ``` #### Removals @@ -221,7 +224,7 @@ of the removed `addAttribute`: - [event shouldBeSent:] - [event toJson:] - [event enhancedErrorMessageForThread:] -- event.notifyReleaseStages +- event.enabledReleaseStages - event.handledState - event.overrides - event.depth diff --git a/features/fixtures/ios-swift-cocoapods/iOSTestApp/scenarios/ReleaseStageScenarios.swift b/features/fixtures/ios-swift-cocoapods/iOSTestApp/scenarios/ReleaseStageScenarios.swift index 21b34f6ef..51c375bc4 100644 --- a/features/fixtures/ios-swift-cocoapods/iOSTestApp/scenarios/ReleaseStageScenarios.swift +++ b/features/fixtures/ios-swift-cocoapods/iOSTestApp/scenarios/ReleaseStageScenarios.swift @@ -7,7 +7,7 @@ class NotifyWhenReleaseStageInNotifyReleaseStages : Scenario { override func startBugsnag() { self.config.autoTrackSessions = false; self.config.releaseStage = "prod" - self.config.notifyReleaseStages = ["dev", "prod"] + self.config.enabledReleaseStages = ["dev", "prod"] super.startBugsnag() } @@ -23,7 +23,7 @@ class CrashWhenReleaseStageInNotifyReleaseStages : Scenario { override func startBugsnag() { self.config.autoTrackSessions = false; self.config.releaseStage = "prod" - self.config.notifyReleaseStages = ["dev", "prod"] + self.config.enabledReleaseStages = ["dev", "prod"] super.startBugsnag() } @@ -43,7 +43,7 @@ class CrashWhenReleaseStageInNotifyReleaseStagesChanges : Scenario { // A crash will occur self.config.releaseStage = "prod" } - self.config.notifyReleaseStages = ["dev", "prod"] + self.config.enabledReleaseStages = ["dev", "prod"] super.startBugsnag() } @@ -63,7 +63,7 @@ class CrashWhenReleaseStageNotInNotifyReleaseStagesChanges : Scenario { // A crash will occur self.config.releaseStage = "test" } - self.config.notifyReleaseStages = ["dev", "prod"] + self.config.enabledReleaseStages = ["dev", "prod"] super.startBugsnag() } @@ -77,7 +77,7 @@ class NotifyWhenReleaseStageNotInNotifyReleaseStages : Scenario { override func startBugsnag() { self.config.autoTrackSessions = false; self.config.releaseStage = "dev" - self.config.notifyReleaseStages = ["prod"] + self.config.enabledReleaseStages = ["prod"] super.startBugsnag() } @@ -93,7 +93,7 @@ class CrashWhenReleaseStageNotInNotifyReleaseStages : Scenario { override func startBugsnag() { self.config.autoTrackSessions = false; self.config.releaseStage = "dev" - self.config.notifyReleaseStages = ["prod"] + self.config.enabledReleaseStages = ["prod"] super.startBugsnag() } diff --git a/iOS/BugsnagTests/BugsnagEventFromKSCrashReportTest.m b/iOS/BugsnagTests/BugsnagEventFromKSCrashReportTest.m index 4e3be64ed..45d5101a1 100644 --- a/iOS/BugsnagTests/BugsnagEventFromKSCrashReportTest.m +++ b/iOS/BugsnagTests/BugsnagEventFromKSCrashReportTest.m @@ -16,7 +16,7 @@ @interface BugsnagEventFromKSCrashReportTest : XCTestCase @interface BugsnagEvent () - (NSDictionary *_Nonnull)toJson; - (BOOL)shouldBeSent; -@property(readwrite, copy, nullable) NSArray *notifyReleaseStages; +@property(readwrite, copy, nullable) NSArray *enabledReleaseStages; @property(readwrite) NSUInteger depth; @end @@ -49,12 +49,12 @@ - (void)testReadReleaseStage { XCTAssertEqualObjects(self.report.releaseStage, @"production"); } -- (void)testReadNotifyReleaseStages { - XCTAssertEqualObjects(self.report.notifyReleaseStages, +- (void)testReadEnabledReleaseStages { + XCTAssertEqualObjects(self.report.enabledReleaseStages, (@[ @"production", @"development" ])); } -- (void)testReadNotifyReleaseStagesSends { +- (void)testReadEnabledReleaseStagesSends { XCTAssertTrue([self.report shouldBeSent]); } From 1d6de5654e46575101b2afde47d08d302299220c Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Mon, 30 Mar 2020 12:13:58 +0100 Subject: [PATCH 2/2] address review feedback --- Source/BugsnagEvent.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/BugsnagEvent.m b/Source/BugsnagEvent.m index 0b737d84d..f011ec4cb 100644 --- a/Source/BugsnagEvent.m +++ b/Source/BugsnagEvent.m @@ -24,6 +24,7 @@ #import "Private.h" #import "BSG_RFC3339DateTool.h" #import "Private.h" +#import "BugsnagKeys.h" @interface BugsnagBreadcrumb () + (instancetype _Nullable)breadcrumbWithBlock: @@ -319,7 +320,7 @@ - (instancetype)initWithKSReport:(NSDictionary *)report { } } } else { - _enabledReleaseStages = BSGLoadConfigValue(report, @"notifyReleaseStages"); + _enabledReleaseStages = BSGLoadConfigValue(report, BSGKeyEnabledReleaseStages); _releaseStage = BSGParseReleaseStage(report); _threads = [report valueForKeyPath:@"crash.threads"]; RegisterErrorData *data = [RegisterErrorData errorDataFromThreads:_threads];