Skip to content

Commit

Permalink
Merge pull request #432 from lindegroup/v1.3.1-rc1
Browse files Browse the repository at this point in the history
V1.3.1 rc1
  • Loading branch information
homebysix committed Aug 19, 2015
2 parents aaebb72 + 1795cd8 commit 7364d59
Show file tree
Hide file tree
Showing 54 changed files with 1,512 additions and 812 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ DerivedData
*.xcuserstate
mailcore2/unittest/data
*.orig

# Markdown preview
README.html
CHANGELOG.html
8 changes: 8 additions & 0 deletions AutoPkgr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@
BEC1258B19F04703006696C4 /* LGRepoTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A0BABE8196E560000A136BB /* LGRepoTableViewController.m */; };
BEC1258C19F049A1006696C4 /* LGTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = BE32178D19EDA15400A92E5A /* LGTableView.m */; };
BEC2024B1B600FF100F3BC2A /* LocalizableJSSImporter.strings in Resources */ = {isa = PBXBuildFile; fileRef = BEC202491B600FF100F3BC2A /* LocalizableJSSImporter.strings */; };
BEC949791B63FDA3005641EB /* LGTwoFactorAuthAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = BEC949781B63FDA3005641EB /* LGTwoFactorAuthAlert.m */; };
BEC9497A1B63FDA3005641EB /* LGTwoFactorAuthAlert.m in Sources */ = {isa = PBXBuildFile; fileRef = BEC949781B63FDA3005641EB /* LGTwoFactorAuthAlert.m */; };
BECDAB8C1B249C0400544388 /* NSButton+colored.m in Sources */ = {isa = PBXBuildFile; fileRef = BECDAB891B249A2900544388 /* NSButton+colored.m */; };
BECDAB8D1B249C0B00544388 /* NSButton+colored.m in Sources */ = {isa = PBXBuildFile; fileRef = BECDAB891B249A2900544388 /* NSButton+colored.m */; };
BECDAB951B24C29600544388 /* LGMunkiIntegrationView.m in Sources */ = {isa = PBXBuildFile; fileRef = BECDAB931B24C29600544388 /* LGMunkiIntegrationView.m */; };
Expand Down Expand Up @@ -488,6 +490,8 @@
BEBF7B151A4894AC00E9967F /* LGVersioner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGVersioner.h; sourceTree = "<group>"; };
BEBF7B161A4894AC00E9967F /* LGVersioner.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGVersioner.m; sourceTree = "<group>"; };
BEC2024A1B600FF100F3BC2A /* en */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/LocalizableJSSImporter.strings; sourceTree = "<group>"; };
BEC949771B63FDA3005641EB /* LGTwoFactorAuthAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGTwoFactorAuthAlert.h; sourceTree = "<group>"; };
BEC949781B63FDA3005641EB /* LGTwoFactorAuthAlert.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LGTwoFactorAuthAlert.m; sourceTree = "<group>"; };
BECDAB881B249A2900544388 /* NSButton+colored.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSButton+colored.h"; sourceTree = "<group>"; };
BECDAB891B249A2900544388 /* NSButton+colored.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSButton+colored.m"; sourceTree = "<group>"; };
BECDAB921B24C29600544388 /* LGMunkiIntegrationView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LGMunkiIntegrationView.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1023,6 +1027,8 @@
BE81F2411B22C211007D16C4 /* LGViewWindowController.xib */,
BE32178C19EDA15400A92E5A /* LGTableView.h */,
BE32178D19EDA15400A92E5A /* LGTableView.m */,
BEC949771B63FDA3005641EB /* LGTwoFactorAuthAlert.h */,
BEC949781B63FDA3005641EB /* LGTwoFactorAuthAlert.m */,
BE4DD5451B126E2800854FD8 /* LGSchedulePickerMenu.h */,
BE4DD5461B126E2800854FD8 /* LGSchedulePickerMenu.m */,
BE5E559F1B1B59D50025CFD3 /* LGTableCellViews.h */,
Expand Down Expand Up @@ -1545,6 +1551,7 @@
BEC1258C19F049A1006696C4 /* LGTableView.m in Sources */,
6A53625D1988BE59008A949C /* LGTestPort.m in Sources */,
BEFC931D1995F0710074C938 /* LGError.m in Sources */,
BEC949791B63FDA3005641EB /* LGTwoFactorAuthAlert.m in Sources */,
BEEFE6C21AEBCC7C00882C89 /* LGIntegrationManager.m in Sources */,
BEEFE6CE1AEC761F00882C89 /* LGJSSImporterIntegration.m in Sources */,
BE05CE8219DAF6320089068B /* LGAutoPkgrAuthorizer.m in Sources */,
Expand Down Expand Up @@ -1635,6 +1642,7 @@
BE38EA9D1B0CFEA6009FCBEB /* LGScheduleViewController.m in Sources */,
BEFC3C8B1A3DF16700C789E9 /* NSString+cleaned.m in Sources */,
BEEFE6CB1AEC760900882C89 /* LGAutoPkgIntegration.m in Sources */,
BEC9497A1B63FDA3005641EB /* LGTwoFactorAuthAlert.m in Sources */,
BEFC3C8C1A3DF16700C789E9 /* NSTextField+safeStringValue.m in Sources */,
BEFC3C8E1A3DF16700C789E9 /* NSArray+filtered.m in Sources */,
BEB9AF2C1B41A01900016D98 /* LGSlackNotificationView.m in Sources */,
Expand Down
10 changes: 5 additions & 5 deletions AutoPkgr/Custom Categories/NSData+taskData.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ - (NSDictionary *)taskData_serializedDictionary
}

- (BOOL)taskData_isInteractive {
NSArray *defaultMatches = @[@"[y/n]:",
@"[YES/NO]:",
@"Password:",
@"Password",
NSArray *defaultMatches = @[@" [y/n]:",
@" [YES/NO]:",
@" Password:",
];

return [self taskData_isInteractiveWithStrings:defaultMatches];
}
}

- (BOOL)taskData_isInteractiveWithStrings:(NSArray *)interactiveStrings {
NSString *message = [[[NSString alloc] initWithData:self encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
Expand Down
23 changes: 15 additions & 8 deletions AutoPkgr/Models/AutoPkg Task/LGAutoPkgErrorHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ typedef NS_ENUM(NSInteger, LGAutoPkgErrorCodes) {
kLGAutoPkgErrorNoRecipes = 255,

kLGAutoPkgErrorRepoModification = -2,
kLGAutoPkgErrorNeedsRepair = -1
kLGAutoPkgErrorNeedsRepair = -1,
};

typedef NS_ENUM(NSInteger, LGAutoPkgGitHubAPIError) {
kLGAutoPkgErrorGHApi2FAAuthRequired = 1000,
kLGAutoPkgErrorAPITokenNotOnRemote,
};

typedef NS_OPTIONS(NSInteger, LGAutoPkgVerb) {
Expand All @@ -43,17 +48,17 @@ typedef NS_OPTIONS(NSInteger, LGAutoPkgVerb) {
kLGAutoPkgInfo = 1 << 4,

// repo verbs
kLGAutoPkgRepoAdd = 1 << 10,
kLGAutoPkgRepoDelete = 1 << 11,
kLGAutoPkgRepoUpdate = 1 << 12,
kLGAutoPkgRepoList = 1 << 13,
kLGAutoPkgRepoAdd = 1 << 5,
kLGAutoPkgRepoDelete = 1 << 6,
kLGAutoPkgRepoUpdate = 1 << 7,
kLGAutoPkgRepoList = 1 << 8,

// processor verbs
kLGAutoPkgProcessorInfo = 1 << 20,
kLGAutoPkgListProcessors = 1 << 21,
kLGAutoPkgProcessorInfo = 1 << 9,
kLGAutoPkgListProcessors = 1 << 10,

// other verbs
kLGAutoPkgVersion = 1 << 30,
kLGAutoPkgVersion = 1 << 11,
};

@interface LGAutoPkgErrorHandler : NSObject
Expand All @@ -64,4 +69,6 @@ typedef NS_OPTIONS(NSInteger, LGAutoPkgVerb) {
- (instancetype)initWithVerb:(LGAutoPkgVerb)verb;
- (NSError *)errorWithExitCode:(NSInteger)exitCode;

+ (NSError *)errorWithGitHubAPIErrorCode:(LGAutoPkgGitHubAPIError)statusCode;

@end
72 changes: 51 additions & 21 deletions AutoPkgr/Models/AutoPkg Task/LGAutoPkgErrorHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#import "LGAutoPkgErrorHandler.h"
#import "LGLogger.h"

NSString * LGAutoPkgLocalizedString(NSString *key, NSString *comment)
NSString *LGAutoPkgLocalizedString(NSString *key, NSString *comment)
{
return [[NSBundle mainBundle] localizedStringForKey:key
value:key
Expand All @@ -34,41 +34,62 @@

switch (verb) {
case kLGAutoPkgRun:
message = NSLocalizedStringFromTable(@"Error running recipes", @"LocalizableAutoPkg", nil);
message = NSLocalizedStringFromTable(@"Error running recipes", @"LocalizableAutoPkg", nil);
break;
case kLGAutoPkgListRecipes:
message = NSLocalizedStringFromTable(@"Error encountered listing recipes", @"LocalizableAutoPkg", nil);
message = NSLocalizedStringFromTable(@"Error encountered listing recipes", @"LocalizableAutoPkg", nil);
break;
case kLGAutoPkgMakeOverride:
message = NSLocalizedStringFromTable(@"Error creating recipe override file", @"LocalizableAutoPkg", nil);
message = NSLocalizedStringFromTable(@"Error creating recipe override file", @"LocalizableAutoPkg", nil);
break;
case kLGAutoPkgSearch:
message = NSLocalizedStringFromTable(@"Error encountered searching for recipe", @"LocalizableAutoPkg", nil);
message = NSLocalizedStringFromTable(@"Error encountered searching for recipe", @"LocalizableAutoPkg", nil);
break;
case kLGAutoPkgRepoAdd:
message = NSLocalizedStringFromTable(@"Error adding repo", @"LocalizableAutoPkg", nil);
message = NSLocalizedStringFromTable(@"Error adding repo", @"LocalizableAutoPkg", nil);
break;
case kLGAutoPkgRepoDelete:
message = NSLocalizedStringFromTable(@"Error removing repo", @"LocalizableAutoPkg", nil);
message = NSLocalizedStringFromTable(@"Error removing repo", @"LocalizableAutoPkg", nil);
break;
case kLGAutoPkgRepoUpdate:
message = NSLocalizedStringFromTable(@"Error updating repo", @"LocalizableAutoPkg", nil);
message = NSLocalizedStringFromTable(@"Error updating repo", @"LocalizableAutoPkg", nil);
break;
case kLGAutoPkgRepoList:
message = NSLocalizedStringFromTable(@"Error encountered listing repos", @"LocalizableAutoPkg", nil);
message = NSLocalizedStringFromTable(@"Error encountered listing repos", @"LocalizableAutoPkg", nil);
break;
case kLGAutoPkgVersion:
message = NSLocalizedStringFromTable(@"Error getting AutoPkg version", @"LocalizableAutoPkg", nil);
message = NSLocalizedStringFromTable(@"Error getting AutoPkg version", @"LocalizableAutoPkg", nil);
break;
case kLGAutoPkgUndefinedVerb:
default:
message = NSLocalizedStringFromTable(@"AutoPkgr encountered an error", @"LocalizableAutoPkg", nil);
message = NSLocalizedStringFromTable(@"AutoPkgr encountered an error", @"LocalizableAutoPkg", nil);
break;
}

return message;
}

static NSDictionary *errorFromAutoPkgGitHubAPICode(LGAutoPkgGitHubAPIError code)
{
NSDictionary *userInfo = nil;
switch (code) {
case kLGAutoPkgErrorGHApi2FAAuthRequired: {
userInfo = @{ NSLocalizedDescriptionKey : NSLocalizedStringFromTable(@"Two factor authentication is required", @"LocalizableAutoPkg", nil),
NSLocalizedRecoverySuggestionErrorKey : NSLocalizedStringFromTable(@"Your GitHub account has two factor authentication enabled. If you did not recieve a code on your mobile device, check your account's security settings and confirm the information there is correct.", @"LocalizableAutoPkg", nil) };
break;
}
case kLGAutoPkgErrorAPITokenNotOnRemote: {
userInfo = @{ NSLocalizedDescriptionKey : NSLocalizedStringFromTable(@"API Token not found.", @"LocalizableAutoPkg", nil),
NSLocalizedRecoverySuggestionErrorKey : NSLocalizedStringFromTable(@"A GitHub API token matching the local one was not found on the remote. You may need to remove it manually. If you've just added the token, you may need to wait a minute to delete it.", @"LocalizableAutoPkg", nil) };
} break;
default: {
userInfo = @{ NSLocalizedDescriptionKey : NSLocalizedStringFromTable(@"There was a problem communicating with GitHub", @"LocalizableAutoPkg", nil) };
break;
}
}
return userInfo;
}

NSString *maskPasswordInString(NSString *string)
{
NSError *error;
Expand Down Expand Up @@ -117,16 +138,16 @@ - (instancetype)initWithVerb:(LGAutoPkgVerb)verb
_pipe = pipe;

[pipe.fileHandleForReading setReadabilityHandler:^(NSFileHandle *fh) {
NSData *data = fh.availableData;
if (data) {
NSString *str = [[NSMutableString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSData *data = fh.availableData;
if (data) {
NSString *str = [[NSMutableString alloc] initWithData:data encoding:NSUTF8StringEncoding];

if (!_errorStrings) {
_errorStrings = [[NSMutableOrderedSet alloc] init];
}
[_errorStrings addObject:str];
}
if (!_errorStrings) {
_errorStrings = [[NSMutableOrderedSet alloc] init];
}

[_errorStrings addObject:str];
}
}];
}
return self;
Expand Down Expand Up @@ -197,7 +218,7 @@ - (NSError *)errorWithExitCode:(NSInteger)exitCode
}
// autopkg run exits 255 if no recipe specified
else if (_verb == kLGAutoPkgRun && exitCode == kLGAutoPkgErrorNoRecipes) {
errorDetails = LGAutoPkgLocalizedString(@"No recipes specified.", nil) ;
errorDetails = LGAutoPkgLocalizedString(@"No recipes specified.", nil);
}
}

Expand All @@ -218,4 +239,13 @@ - (NSError *)errorWithExitCode:(NSInteger)exitCode
return error;
}

+ (NSError *)errorWithGitHubAPIErrorCode:(LGAutoPkgGitHubAPIError)statusCode
{
NSDictionary *userInfo = errorFromAutoPkgGitHubAPICode(statusCode);
NSError *error = [NSError errorWithDomain:[[NSBundle mainBundle] bundleIdentifier] ?: @"autopkg"
code:statusCode
userInfo:userInfo];
return error;
}

@end
5 changes: 3 additions & 2 deletions AutoPkgr/Models/AutoPkg Task/LGAutoPkgRecipe.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ - (instancetype)initWithRecipeFile:(NSURL *)recipeFile isOverride:(BOOL)isOverri
_enabledInitialized = -1;

[_identifierURLStore setObject:_recipeFileURL forKey:_Identifier];
return self;
}
return self;
return nil;
}

- (NSString *)Description
Expand Down Expand Up @@ -416,7 +417,7 @@ + (BOOL)removeRecipeFromRecipeList:(NSString *)recipe

NSString *recipe_list = [recipes.array componentsJoinedByString:@"\n"];
if (![recipe_list writeToFile:[self defaultRecipeList] atomically:YES encoding:NSUTF8StringEncoding error:&error]) {
NSLog(@"%@", error);
NSLog(@"Error writing file: %@", error.localizedDescription);
return NO;
}
return YES;
Expand Down
9 changes: 9 additions & 0 deletions AutoPkgr/Models/AutoPkg Task/LGAutoPkgRepo.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ typedef NS_ENUM(OSStatus, LGAutoPkgRepoStatus) {
@property (assign, nonatomic, readonly) LGAutoPkgRepoStatus status;
@property (copy) void (^statusChangeBlock)(LGAutoPkgRepoStatus);

/**
* Initialize a repo with a clone url
*
* @param cloneURL clone URL
*
* @return initialized AutoPkgRepo Object
*/
- (instancetype)initWithCloneURL:(NSString *)cloneURL;

/**
* Check if there are updates available for the repo.
*
Expand Down
51 changes: 40 additions & 11 deletions AutoPkgr/Models/AutoPkg Task/LGAutoPkgRepo.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,19 @@ - (instancetype)initWithCloneURL:(NSString *)cloneURL
}

#pragma mark - Accessors
- (NSString *)description {
return self.cloneURL.absoluteString;
}

- (BOOL)isInstalled
{
NSPredicate *repoPredicate = [NSPredicate predicateWithFormat:@"%K CONTAINS[cd] %@", kLGAutoPkgRepoURLKey, self.cloneURL.absoluteString];
NSMutableString *repoURL = self.cloneURL.absoluteString.mutableCopy;
if ([repoURL.pathExtension isEqualToString:@"git"]) {
[repoURL deleteCharactersInRange:NSMakeRange(repoURL.length - 4, 4)];
}

NSPredicate *repoPredicate = [NSPredicate predicateWithFormat:@"%K CONTAINS[cd] %@", kLGAutoPkgRepoURLKey, repoURL];

return [[_activeRepos filteredArrayUsingPredicate:repoPredicate] count];
}

Expand Down Expand Up @@ -140,13 +150,18 @@ - (void)updateRepo:(void (^)(NSError *))reply

- (void)install:(void (^)(NSError *))reply
{
[LGAutoPkgTask repoAdd:_cloneURL.absoluteString reply:^(NSError *error) {
_activeRepos = [LGAutoPkgTask repoList];
if (!error) {
[self statusDidChange:kLGAutoPkgRepoUpToDate];
}
reply(error);
}];
_activeRepos = [LGAutoPkgTask repoList];
if (!self.isInstalled) {
[LGAutoPkgTask repoAdd:_cloneURL.absoluteString reply:^(NSError *error) {
_activeRepos = [LGAutoPkgTask repoList];
if (!error) {
[self statusDidChange:kLGAutoPkgRepoUpToDate];
}
reply(error);
}];
} else {
reply(nil);
}
}

- (void)remove:(void (^)(NSError *))reply
Expand Down Expand Up @@ -245,19 +260,33 @@ + (void)commonRepos:(void (^)(NSArray *))reply
{
void (^constructCommonRepos)() = ^() {
_activeRepos = [LGAutoPkgTask repoList];
NSMutableArray *commonRepos = [_popularRepos mutableCopy];
NSMutableArray *commonRepos = [NSMutableArray arrayWithArray:_popularRepos];

[_activeRepos enumerateObjectsUsingBlock:^(NSDictionary *activeRepo, NSUInteger idx, BOOL *stop) {
NSString *repoURL = activeRepo[kLGAutoPkgRepoURLKey];
NSMutableString *normalizedRepo = repoURL.mutableCopy;

if (![normalizedRepo.pathExtension isEqualToString:@"git"]) {
// Using -stringByAppendingPathComponent: on a url here
// results in the scheme getting mangled from https://xxx to https:/xxx
// so just use -stringByAppendingString: string.
[normalizedRepo appendString:@".git"];
}

NSPredicate *pred = [NSPredicate predicateWithFormat:@"%K.absoluteString == %@",
NSStringFromSelector(@selector(cloneURL)),
activeRepo[kLGAutoPkgRepoURLKey]];
normalizedRepo];

NSArray *matches = [_popularRepos filteredArrayUsingPredicate:pred];

if ([_popularRepos filteredArrayUsingPredicate:pred].count == 0) {
if (matches.count == 0) {
LGAutoPkgRepo *repo = nil;
if ((repo = [[self alloc] initWithAutoPkgDictionary:activeRepo])) {
[commonRepos addObject:repo];
}
} if (matches.count == 1 && ![repoURL isEqualToString:normalizedRepo]) {
LGAutoPkgRepo *repo = matches.firstObject;
repo->_cloneURL = [NSURL URLWithString:repoURL];
}
}];

Expand Down
Loading

0 comments on commit 7364d59

Please sign in to comment.