forked from hebruce110/ioctocat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GHCommits.m
71 lines (60 loc) · 1.88 KB
/
GHCommits.m
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
#import "GHCommits.h"
#import "GHCommit.h"
#import "GHRepository.h"
#import "GHPullRequest.h"
#import "NSDictionary_IOCExtensions.h"
@interface GHCommits ()
@property(nonatomic,strong)GHRepository *repository;
@property(nonatomic,weak)GHPullRequest *pullRequest;
@property(nonatomic,strong)NSString *sha;
@end
@implementation GHCommits
@synthesize resourcePath = _resourcePath;
- (id)initWithRepository:(GHRepository *)repo {
self = [super init];
if (self) {
self.repository = repo;
self.resourcePath = [NSString stringWithFormat:kRepoCommitsFormat, self.repository.owner, self.repository.name];
}
return self;
}
- (id)initWithRepository:(GHRepository *)repo sha:(NSString *)sha {
self = [super init];
if (self) {
self.repository = repo;
self.sha = sha;
}
return self;
}
- (id)initWithPullRequest:(GHPullRequest *)pullRequest {
self = [super init];
if (self) {
self.pullRequest = pullRequest;
self.repository = self.pullRequest.repository;
}
return self;
}
- (NSString *)resourcePath {
if (_resourcePath) {
// in events there is no resourcePath that could be referenced, so we clear
// out the resourcePath with an empty string which should be returned then
return _resourcePath;
} else if (self.pullRequest) {
GHRepository *repo = self.pullRequest.repository;
return [NSString stringWithFormat:kPullRequestCommitsFormat, repo.owner, repo.name, self.pullRequest.number];
} else if (self.sha) {
return [NSString stringWithFormat:kRepoShaCommitsFormat, self.repository.owner, self.repository.name, self.sha];
} else {
return [super resourcePath];
}
}
- (void)setValues:(id)values {
[super setValues:values];
for (NSDictionary *dict in values) {
NSString *sha = [dict ioc_stringForKey:@"sha"];
GHCommit *commit = [[GHCommit alloc] initWithRepository:self.repository andCommitID:sha];
[commit setValues:dict];
[self addObject:commit];
}
}
@end