Skip to content

Commit

Permalink
Email layout
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmargolis committed Oct 6, 2011
1 parent aaf8d5f commit cf51b9d
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 12 deletions.
1 change: 1 addition & 0 deletions Zapp/ZappBuild.h
Expand Up @@ -32,6 +32,7 @@
@property (nonatomic, readonly) NSString *feedDescription;
@property (nonatomic, readonly) NSURL *buildLogURL;
@property (nonatomic, readonly) NSURL *buildVideoURL;
@property (nonatomic, readonly) NSString *abbreviatedLatestRevision;

- (void)startWithCompletionBlock:(void (^)(void))completionBlock;

Expand Down
25 changes: 13 additions & 12 deletions Zapp/ZappBuild.m
Expand Up @@ -74,17 +74,8 @@ - (NSString *)feedDescription;
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];

NSString *revision = [self.latestRevision substringToIndex:MIN(6, self.latestRevision.length)];

NSString *statusDescription = nil;
switch (self.status) {
case ZappBuildStatusPending: statusDescription = ZappLocalizedString(@"pending"); break;
case ZappBuildStatusRunning: statusDescription = ZappLocalizedString(@"running"); break;
case ZappBuildStatusFailed: statusDescription = ZappLocalizedString(@"failure"); break;
case ZappBuildStatusSucceeded: statusDescription = ZappLocalizedString(@"success"); break;
default: break;
}

NSString *revision = self.abbreviatedLatestRevision;
NSString *statusDescription = [self.statusDescription lowercaseString];

return [NSString stringWithFormat:@"Built %@ on %@: %@", revision, [dateFormatter stringFromDate:self.startDate], statusDescription];
}
Expand All @@ -100,7 +91,7 @@ - (NSString *)description;
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];

NSString *revision = [self.latestRevision substringToIndex:MIN(6, self.latestRevision.length)];
NSString *revision = self.abbreviatedLatestRevision;

if (self.status == ZappBuildStatusPending) {
return [NSString stringWithFormat:@"%@: %@", self.statusDescription, revision];
Expand Down Expand Up @@ -182,6 +173,16 @@ + (NSSet *)keyPathsForValuesAffectingStatusDescription;
return [NSSet setWithObject:@"status"];
}

- (NSString *)abbreviatedLatestRevision;
{
return [self.latestRevision substringToIndex:MIN(6, self.latestRevision.length)];
}

+ (NSSet *)keyPathsForValuesAffectingAbbreviatedLatestRevision;
{
return [NSSet setWithObject:@"latestRevision"];
}

#pragma mark ZappBuild

- (void)startWithCompletionBlock:(void (^)(void))completionBlock;
Expand Down
2 changes: 2 additions & 0 deletions Zapp/ZappMessageController.h
Expand Up @@ -10,6 +10,8 @@

@interface ZappMessageController : NSObject

+ (ZappMessageController *)sharedInstance;

- (void)sendMessageForLatestBuildInRepository:(ZappRepository *)repository;
- (void)sendMessageForBuild:(ZappBuild *)build;

Expand Down
75 changes: 75 additions & 0 deletions Zapp/ZappMessageController.m
Expand Up @@ -7,16 +7,91 @@
//

#import "ZappMessageController.h"
#import "ZappBuild.h"
#import "ZappRepository.h"


@interface ZappMessageController ()

- (BOOL)sendEmailWithSubject:(NSString *)subject headers:(NSDictionary *)headers body:(NSString *)body error:(out NSError **)error;

@end


@implementation ZappMessageController

#pragma mark Initialization

+ (id)sharedInstance;
{
static ZappMessageController *sharedInstance;

static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[ZappMessageController alloc] init];
});

return nil;
}

#pragma mark Public Methods

- (void)sendMessageForLatestBuildInRepository:(ZappRepository *)repository;
{

}

- (void)sendMessageForBuild:(ZappBuild *)build;
{
// get the long since the last build
// current sha + author

NSString *oldRevision = nil;


// since last build
// last red red-green or last green-red

NSString *delta = oldRevision ? [NSString stringWithFormat:@"%@..%@", oldRevision, build.latestRevision] : @"HEAD^..HEAD";
NSString *format = [NSString stringWithFormat:@"--format=\"%@%%h %%s (%%an)\"", build.repository.remoteURL.absoluteString];

NSArray *logCommand = [NSArray arrayWithObjects:GitCommand, @"log", delta, format, nil];

[build.repository runCommand:GitCommand withArguments:logCommand completionBlock:^(NSString *gitLogOutput) {

NSString *subject = [NSString stringWithFormat:ZappLocalizedString(@"ZAPP: Latest Build %@ %@"), build.abbreviatedLatestRevision, [build.statusDescription uppercaseString]];

NSString *beginString = ZappLocalizedString(@"===== BEGIN TRANSMISSION =====");
NSString *latestBuildString = ZappLocalizedString(@"Latest build:");
NSString *latestBuildStatusString = [NSString stringWithFormat:@"%@ %@", build.abbreviatedLatestRevision, [build.statusDescription uppercaseString]];

NSString *endString = ZappLocalizedString(@"====== END TRANSMISSION ======");

NSString *message = [[NSArray arrayWithObjects:beginString, latestBuildString, latestBuildStatusString, @"", gitLogOutput, endString, nil] componentsJoinedByString:@"\n"];

[self sendEmailWithSubject:subject headers:nil body:message error:nil];
/*
===== BEGIN TRANSMISSION =====
Latest build:
a895jf9 SUCCESS
Intermediate commits:
aaf8d5f Author: Some commit message (8 hours ago)
88486a3 Author + Author: Another commit message. (8 days ago)
19a938f Author: The same one as before (8 days ago)
21ab6e4 Author: A new commit message (8 days ago)
====== END TRANSMISSION ======
*/
}];
}

#pragma mark Private Methods

- (BOOL)sendEmailWithSubject:(NSString *)subject headers:(NSDictionary *)headers body:(NSString *)body error:(out NSError **)error;
{
return YES;
}

@end

0 comments on commit cf51b9d

Please sign in to comment.