-
Notifications
You must be signed in to change notification settings - Fork 78
[Dev] Support loading Emission from AppHub #541
Changes from 4 commits
df608ec
717cbac
fc3a438
401fd2c
e5784f9
0dbefdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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 |
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 |
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 |
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)]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: missing whitespace |
||
|
||
} else { | ||
NSInteger diff = round(time / 60 / 60 / 24 / 7); | ||
if (diff == 1) return @"last week"; | ||
|
||
return [NSString stringWithFormat:@"%@ weeks ago", @(diff)]; | ||
} | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good fix 👍 |
||
|
||
# Native UI tweaks | ||
pod 'FLKAutoLayout' | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair 👍 |
||
end | ||
|
||
post_install do |installer| | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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` | ||
# This'll break when we hit 1k PRs, but that's still a while away and an easy fix | ||
PR_NUM=`git log --format=%B -n 1 $SHA | grep -o '#[0-9][0-9][0-9]' | tail -n 1` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason you can’t use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If that works - even better :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, the |
||
|
||
# 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you use
ifdef
in the file above but preferif
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might switch the app entirely to just debug and release, I don't think a third schema is useful as release will not ever be used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use release sometimes to test on a device.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright - I'll keep it around 👍