Skip to content

Commit 4021af7

Browse files
committed
IOS APP中分支提交数和前台分支提交数不一致
1 parent 52ea818 commit 4021af7

File tree

3 files changed

+45
-28
lines changed

3 files changed

+45
-28
lines changed

Coding_iOS/Models/EACodeBranches.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@property (strong, nonatomic) NSString *queryStr;
1616
@property (strong, nonatomic) Project *curPro;
1717

18-
@property (strong, nonatomic, readonly) NSString *curBaseStr;
18+
@property (strong, nonatomic) CodeBranchOrTag *defaultBranch;
1919

2020
- (NSString *)toPath;
2121
- (NSDictionary *)toParams;

Coding_iOS/Models/EACodeBranches.m

+8-11
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,16 @@ - (instancetype)init
1919
return self;
2020
}
2121

22-
- (NSString *)curBaseStr{
23-
CodeBranchOrTag *defaultB = nil;
24-
for (CodeBranchOrTag *itemB in self.list) {
25-
if (itemB.is_default_branch.boolValue) {
26-
defaultB = itemB;
27-
break;
22+
- (CodeBranchOrTag *)defaultBranch{
23+
if (!_defaultBranch) {
24+
for (CodeBranchOrTag *itemB in self.list) {
25+
if (itemB.is_default_branch.boolValue) {
26+
_defaultBranch = itemB;
27+
break;
28+
}
2829
}
2930
}
30-
if (!defaultB) {
31-
defaultB = self.list.firstObject;
32-
}
33-
return defaultB.last_commit.commitId;
34-
// return [(CodeBranchOrTag *)self.list.firstObject last_commit].commitId;
31+
return _defaultBranch;
3532
}
3633

3734
//https://coding.net/api/user/ease/project/CodingTest/git/branches/filter?page=1&q=

Coding_iOS/Util/Manager/Coding_NetAPIManager.m

+36-16
Original file line numberDiff line numberDiff line change
@@ -1362,34 +1362,54 @@ - (void)request_CreateCodeFile:(CodeFile *)codeFile withPro:(Project *)project a
13621362

13631363
- (void)request_CodeBranches_WithObj:(EACodeBranches *)curObj andBlock:(void (^)(EACodeBranches *data, NSError *error))block{
13641364
curObj.isLoading = YES;
1365+
//拿 branch 列表
13651366
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:[curObj toPath] withParams:[curObj toParams] withMethodType:Get andBlock:^(id data, NSError *error) {
1366-
curObj.isLoading = NO;
13671367
if (data) {
13681368
[MobClick event:kUmeng_Event_Request_Get label:@"分支管理_列表"];
13691369

13701370
id resultData = [data valueForKeyPath:@"data"];
13711371
EACodeBranches *resultA = [NSObject objectOfClass:@"EACodeBranches" fromJSON:resultData];
13721372
if (resultA.list.count > 0) {
1373-
NSString *path = [NSString stringWithFormat:@"api/user/%@/project/%@/git/branch_metrics", curObj.curPro.owner_user_name, curObj.curPro.name];
1374-
NSString *targetsStr = [[resultA.list valueForKeyPath:@"last_commit.commitId"] componentsJoinedByString:@","];
1375-
NSDictionary *params = @{@"base": curObj.curBaseStr ?: resultA.curBaseStr,
1376-
@"targets": targetsStr
1377-
};
1378-
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Get andBlock:^(id dataM, NSError *errorM) {
1379-
if (dataM) {
1380-
dataM = dataM[@"data"];
1381-
for (CodeBranchOrTag *curB in resultA.list) {
1382-
curB.branch_metric = [NSObject objectOfClass:@"CodeBranchOrTagMetric" fromJSON:dataM[curB.last_commit.commitId]];
1373+
//拿 branch 对应的 metrics
1374+
void (^metricsQueryBlock)() = ^(){
1375+
NSString *path = [NSString stringWithFormat:@"api/user/%@/project/%@/git/branch_metrics", curObj.curPro.owner_user_name, curObj.curPro.name];
1376+
NSString *targetsStr = [[resultA.list valueForKeyPath:@"last_commit.commitId"] componentsJoinedByString:@","];
1377+
NSDictionary *params = @{@"base": curObj.defaultBranch.last_commit.commitId ?: @"",
1378+
@"targets": targetsStr
1379+
};
1380+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:path withParams:params withMethodType:Get andBlock:^(id dataM, NSError *errorM) {
1381+
if (dataM) {
1382+
dataM = dataM[@"data"];
1383+
for (CodeBranchOrTag *curB in resultA.list) {
1384+
curB.branch_metric = [NSObject objectOfClass:@"CodeBranchOrTagMetric" fromJSON:dataM[curB.last_commit.commitId]];
1385+
}
1386+
block(resultA, nil);
1387+
}else{
1388+
block(nil, errorM);
13831389
}
1384-
block(resultA, nil);
1385-
}else{
1386-
block(nil, errorM);
1387-
}
1388-
}];
1390+
curObj.isLoading = NO;
1391+
}];
1392+
};
1393+
curObj.defaultBranch = curObj.defaultBranch ?: resultA.defaultBranch;
1394+
if (!curObj.defaultBranch) {//请求 default 分支
1395+
[[CodingNetAPIClient sharedJsonClient] requestJsonDataWithPath:[NSString stringWithFormat:@"api/user/%@/project/%@/git/branches/default", curObj.curPro.owner_user_name, curObj.curPro.name] withParams:nil withMethodType:Get andBlock:^(id dataD, NSError *errorD) {
1396+
if (dataD) {
1397+
curObj.defaultBranch = [NSObject objectOfClass:@"CodeBranchOrTag" fromJSON:dataD[@"data"]];
1398+
metricsQueryBlock();
1399+
}else{
1400+
curObj.isLoading = NO;
1401+
block(nil, errorD);
1402+
}
1403+
}];
1404+
}else{
1405+
metricsQueryBlock();
1406+
}
13891407
}else{
1408+
curObj.isLoading = NO;
13901409
block(resultA, nil);
13911410
}
13921411
}else{
1412+
curObj.isLoading = NO;
13931413
block(nil, error);
13941414
}
13951415
}];

0 commit comments

Comments
 (0)