Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Commit

Permalink
Merge pull request #541 from artsy/apphub_switcher
Browse files Browse the repository at this point in the history
[Dev] Support loading Emission from AppHub
  • Loading branch information
alloy authored May 29, 2017
2 parents 27e4b58 + 0dbefdb commit b86a16d
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 132 deletions.
135 changes: 27 additions & 108 deletions Example/Emission.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions Example/Emission/ARRootViewController+AppHub.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import "ARRootViewController.h"

@class ARSectionData;
@interface ARRootViewController(AppHub)

- (ARSectionData *)appHubSectionData;

@end
79 changes: 79 additions & 0 deletions Example/Emission/ARRootViewController+AppHub.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#import "ARRootViewController+AppHub.h"
#import "NSDateFormatter+TimeAgo.h"

#import <AppHub/AppHub.h>
#import <ARGenericTableViewController/ARGenericTableViewController.h>

@implementation ARRootViewController(AppHub)

- (ARSectionData *)appHubSectionData;
{
ARSectionData *section = [[ARSectionData alloc] initWithCellDataArray: @[
[self appHubBuildChooser],
[self appHubMetadata],
[self showPRForBuild]
]];
section.headerTitle = [@"AppHub" uppercaseString];
return section;
}

- (ARCellData *)appHubMetadata
{
ARCellData *cellData = [[ARCellData alloc] initWithIdentifier:AROptionCell];
cellData.cellConfigurationBlock = ^(UITableViewCell *cell) {
AHBuild *build = [[AppHub buildManager] currentBuild];
if (!build) {
cell.textLabel.text = @"Not downloaded yet";
} if (build && !build.creationDate) {
cell.textLabel.text = @"Current Build: Bundled with Emission";
} else {

NSString *timeString = [NSDateFormatter timeAgoFromDate:build.creationDate];
cell.textLabel.text = [NSString stringWithFormat:@"Current Build: From %@", timeString];
}
};
return cellData;
}

- (ARCellData *)showPRForBuild
{
ARCellData *cellData = [[ARCellData alloc] initWithIdentifier:AROptionCell];
AHBuild *build = [[AppHub buildManager] currentBuild];
NSString *pr = nil;

if (build && build.buildDescription) {
pr = [[build.buildDescription componentsSeparatedByString:@"- #"] lastObject];
}

cellData.cellConfigurationBlock = ^(UITableViewCell *cell) {
if (!pr) {
cell.textLabel.text = @"Not on an AppHub build...";
} else {
cell.textLabel.text = [NSString stringWithFormat:@"Link to PR %@", pr];
}
};

cellData.cellSelectionBlock = ^(UITableView *tableView, NSIndexPath *indexPath) {
if(pr) {
NSString *prAddresss = [NSString stringWithFormat:@"https://github.com/artsy/emission/pull/%@", pr];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:prAddresss]];
}
};
return cellData;
}

- (ARCellData *)appHubBuildChooser
{
ARCellData *cellData = [[ARCellData alloc] initWithIdentifier:AROptionCell];
cellData.cellConfigurationBlock = ^(UITableViewCell *cell) {
cell.textLabel.text = @"Choose an RN build";
};
cellData.cellSelectionBlock = ^(UITableView *tableView, NSIndexPath *indexPath) {
[AppHub presentSelectorOnViewController:self withBuildHandler:^(AHBuild *build, NSError *error) {
[self.tableView reloadData];
}];
};
return cellData;
}

@end
6 changes: 6 additions & 0 deletions Example/Emission/ARRootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// See https://github.com/artsy/eigen/blob/master/Artsy/View_Controllers/Admin/ARAdminSettingsViewController.m
// for examples of how to work with this.

#import "ARRootViewController+AppHub.h"
#import <Emission/ARArtistComponentViewController.h>
#import <Emission/ARHomeComponentViewController.h>
#import <Emission/ARGeneComponentViewController.h>
Expand Down Expand Up @@ -42,6 +43,11 @@ - (void)viewDidLoad
[tableViewData addSectionData:developerSection];
#endif

#if defined(DEPLOY)
ARSectionData *appHubSection = [self appHubSectionData];
[tableViewData addSectionData:appHubSection];
#endif

self.tableViewData = tableViewData;
}

Expand Down
6 changes: 3 additions & 3 deletions Example/Emission/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#import <TargetConditionals.h>
#import "AuthenticationManager.h"

#ifdef DEPLOY
#if defined(DEPLOY)
#import <AppHub/AppHub.h>
#endif

Expand Down Expand Up @@ -64,7 +64,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];

#ifdef DEPLOY
#if defined(DEPLOY)
// [AppHub setLogLevel: AHLogLevelDebug];
[AppHub setApplicationID: @"Z6IwqK52JBXrKLI4kpvJ"];
[[AppHub buildManager] setDebugBuildsEnabled:YES];
Expand Down Expand Up @@ -103,7 +103,7 @@ - (void)setupEmissionWithUserID:(NSString *)userID accessToken:(NSString *)acces
useStagingEnvironment:useStaging
sentryDSN:nil];
#else
#ifdef DEPLOY
#if DEPLOY
AHBuild *build = [[AppHub buildManager] currentBuild];
NSURL *jsCodeLocation = [build.bundle URLForResource:@"main" withExtension:@"jsbundle"];
#else
Expand Down
10 changes: 10 additions & 0 deletions Example/Emission/NSDateFormatter+TimeAgo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#import <Foundation/Foundation.h>

// Based on an implmentation in
// http://stackoverflow.com/questions/902950/iphone-convert-date-string-to-a-relative-time-stamp

@interface NSDateFormatter (Extras)

+ (NSString *)timeAgoFromDate:(NSDate *)date;

@end
45 changes: 45 additions & 0 deletions Example/Emission/NSDateFormatter+TimeAgo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#import "NSDateFormatter+TimeAgo.h"

@implementation NSDateFormatter (Extras)

+ (NSString *)timeAgoFromDate:(NSDate *)date
{
NSDate *now = [NSDate date];

NSTimeInterval time = [date timeIntervalSinceDate:now];
time *= -1;

if(time < 1) {
return @"-";

} else if (time < 60) {
return @"less than a minute ago";

} else if (time < 3600) {
NSInteger diff = round(time / 60);
if (diff == 1) return @"1 minute ago";

return [NSString stringWithFormat:@"%@ minutes ago", @(diff)];

} else if (time < 86400) {
NSInteger diff = round(time / 60 / 60);
if (diff == 1) return @"1 hour ago";

return [NSString stringWithFormat:@"%@ hours ago", @(diff)];

} else if (time < 604800) {
NSInteger diff = round(time / 60 / 60 / 24);
if (diff == 1) return @"yesterday";
if (diff == 7) return @"last week";

return [NSString stringWithFormat:@"%@ days ago", @(diff)];

} else {
NSInteger diff = round(time / 60 / 60 / 24 / 7);
if (diff == 1) return @"last week";

return [NSString stringWithFormat:@"%@ weeks ago", @(diff)];
}
}

@end
18 changes: 9 additions & 9 deletions Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ target 'Emission' do
pod 'Artsy+UIFonts'

# For easy updating of the JS
pod 'AppHub'
pod 'AppHub', :git => 'https://github.com/orta/apphub.git', :branch => "build_list"

# Native UI tweaks
pod 'FLKAutoLayout'
Expand All @@ -40,14 +40,14 @@ target 'Emission' do
:git => 'https://github.com/artsy/Artsy-Authentication.git',
:branch => 'fetch-user-details'

target 'EmissionTests' do
inherit! :search_paths

pod 'React', :path => react_path, :subspecs => %w(RCTTest)

pod 'Specta'
# pod 'Expecta'
end
# target 'EmissionTests' do
# inherit! :search_paths
#
# pod 'React', :path => react_path, :subspecs => %w(Core RCTTest)
#
# pod 'Specta'
# pod 'Expecta'
# end
end

post_install do |installer|
Expand Down
20 changes: 10 additions & 10 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- AppHub (0.5.1):
- React
- React/Core
- ARGenericTableViewController (1.0.2)
- Artsy+Authentication/email (1.5.0):
- ISO8601DateFormatter
Expand Down Expand Up @@ -125,8 +125,6 @@ PODS:
- React/RCTNetwork
- React/RCTNetwork (0.42.0):
- React/Core
- React/RCTTest (0.42.0):
- React/Core
- React/RCTText (0.42.0):
- React/Core
- React/RCTWebSocket (0.42.0):
Expand All @@ -142,25 +140,25 @@ PODS:
- React
- RSSwizzle (~> 0.1.0)
- Sentry (~> 2.1.9)
- Specta (1.0.5)
- UIView+BooleanAnimations (1.0.2)
- Yoga (0.42.0.React)

DEPENDENCIES:
- AppHub
- AppHub (from `https://github.com/orta/apphub.git`, branch `build_list`)
- ARGenericTableViewController
- Artsy+Authentication/email (from `https://github.com/artsy/Artsy-Authentication.git`, branch `fetch-user-details`)
- Artsy+UIFonts
- Emission (from `../`)
- FLKAutoLayout
- React/RCTTest (from `../node_modules/react-native`)
- React/RCTWebSocket (from `../node_modules/react-native`)
- SAMKeychain
- SentryReactNative (from `../node_modules/react-native-sentry`)
- Specta
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

EXTERNAL SOURCES:
AppHub:
:branch: build_list
:git: https://github.com/orta/apphub.git
Artsy+Authentication:
:branch: fetch-user-details
:git: https://github.com/artsy/Artsy-Authentication.git
Expand All @@ -174,12 +172,15 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/yoga"

CHECKOUT OPTIONS:
AppHub:
:commit: 2659ddef3d63f17902e7a8786cc889c428769ab4
:git: https://github.com/orta/apphub.git
Artsy+Authentication:
:commit: 1b582675598c999726d9edacd3b8559e01cf7c48
:git: https://github.com/artsy/Artsy-Authentication.git

SPEC CHECKSUMS:
AppHub: f073cd229f87afe1a27200670e1adab24ebda2b8
AppHub: '03788112dd48c42b60d51321c0ffff4ef15a4432'
ARGenericTableViewController: 61a0897ba66c35111b5d1cc3b44884282bd3c1a5
Artsy+Authentication: 3bf11ceca61c52e9e31490535bf5798f625406fa
Artsy+UIColors: 31c03c4146f5e6618a9b950f37dfe02dd9ac09a6
Expand All @@ -198,10 +199,9 @@ SPEC CHECKSUMS:
SDWebImage: 69c6303e3348fba97e03f65d65d4fbc26740f461
Sentry: 0025c374b2f9fb0da8185a45199de985408a40b2
SentryReactNative: 3de8c386dfebb9f42c5e989adb7060b3f2dc4878
Specta: ac94d110b865115fe60ff2c6d7281053c6f8e8a2
UIView+BooleanAnimations: a760be9a066036e55f298b7b7350a6cb14cfcd97
Yoga: 4183cc70cae189d73f996b1e40c3078aca9f96ef

PODFILE CHECKSUM: f5d89b564529ea868668555a1fd91a7bcfc038ce
PODFILE CHECKSUM: d6a15664ed36c307019c8bfb134a27637ae5ee02

COCOAPODS: 1.2.1
11 changes: 9 additions & 2 deletions scripts/deploy_apphub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ npm install --global apphubdeploy
# Create a .apphub credentials file
echo "{\"appHubId\":\"Z6IwqK52JBXrKLI4kpvJ\",\"appHubSecret\":\"$APP_HUB_SECRET\"}" > .apphub

# Get the most recent PR commit
SHA=`git rev-list --min-parents=2 --max-count=1 HEAD`
# Pull the name of the PR out of the auto-generated commit description
PR_DESC=`git log --format=%B -n 1 $SHA | tail -1`
# Get the PR number out of the merge commit title
PR_NUM=`git log --format=%B -n 1 $SHA | grep -Eo '#[0-9]+' | tail -n 1`

# Ship a debug build of our current RN
apphubdeploy --plist-file ./Example/Emission/Info.plist --target all
apphubdeploy --plist-file ./Example/Emission/Info.plist --target all --build-description "$PR_DESC - ${PR_NUM}"

# To avoid build failures, kill the node_modules folder
# e.g. https://travis-ci.org/artsy/emission/builds/158175879
rm -rf node_modules
rm -rf node_modules

0 comments on commit b86a16d

Please sign in to comment.