This repository was archived by the owner on Feb 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathXGAStatusViewItem.m
More file actions
86 lines (68 loc) · 2.98 KB
/
XGAStatusViewItem.m
File metadata and controls
86 lines (68 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
@file XGAStatusViewItem.m
@package xcode-github-app
@brief The status view detail line.
@author Edward Smith
@date September 2018
@copyright Copyright © 2018 Branch. All rights reserved.
*/
#import "XGAStatusViewItem.h"
#import "XGASettings.h"
@implementation XGAStatusViewItem
+ (instancetype) itemWithBot:(XGXcodeBot*)bot status:(XGXcodeBotStatus*)botStatus {
if (bot == nil || botStatus == nil) return nil;
XGAStatusViewItem *status = [XGAStatusViewItem new];
NSAssert(status, @"Nil XGAStatusViewItem!");
status->_bot = bot;
status->_botStatus = botStatus;
status.server = botStatus.serverName;
status.botName = botStatus.botName;
status.statusSummary = [APFormattedString boldText:@"%@", botStatus.summaryString];
status.statusDetail = botStatus.formattedDetailString;
status.repository = [NSString stringWithFormat:@"%@/%@", bot.repoOwner, bot.repoName];
// isXGAMonitored
__auto_type tasks = [XGASettings shared].gitHubSyncTasks;
for (XGAGitHubSyncTask *task in tasks) {
if (status.server.length && status.bot.name.length &&
[task.xcodeServer isEqualToString:status.server] &&
[task.botNameForTemplate isEqualToString:status.bot.name])
status->_isXGAMonitored = YES;
}
status->_botIsFromTemplate = @(NO);
if (bot.botIsFromTemplateBot && bot.pullRequestNumber.length) {
status->_botIsFromTemplate = @(YES);
status.branchOrPRName = [NSString stringWithFormat:@"PR#%@ %@", bot.pullRequestNumber, bot.pullRequestTitle];
} else {
if (status.isXGAMonitored)
status.branchOrPRName = [NSString stringWithFormat:@"✓ %@", bot.branch];
else
status.branchOrPRName = bot.branch;
}
if (!status.branchOrPRName.length) status.branchOrPRName = @"< Unknown >";
status->_hasGitHubRepo = [bot.sourceControlRepository hasPrefix:@"github.com:"];
status->_botIsFromTemplate = [NSNumber numberWithBool:bot.botIsFromTemplateBot];
status.templateBotName = bot.templateBotName;
if (!status.templateBotName.length) status.templateBotName = status.bot.name;
NSString *result = [botStatus.result lowercaseString];
if ([botStatus.currentStep containsString:@"completed"]) {
NSString*imageName = @"RoundRed";
if ([result containsString:@"succeeded"])
imageName = @"RoundGreen";
else
if ([result containsString:@"unknown"])
imageName = @"RoundAlert";
else
if ([result containsString:@"warning"])
imageName = @"RoundYellow";
else
if ([result containsString:@"unknown"])
imageName = @"RoundAlert";
status.statusImage = [NSImage imageNamed:imageName];
} else
if ([botStatus.currentStep containsString:@"pending"]) {
status.statusImage = [NSImage imageNamed:@"RoundGrey"];
} else
status.statusImage = [NSImage imageNamed:@"RoundBlue"];
return status;
}
@end