@@ -1362,34 +1362,54 @@ - (void)request_CreateCodeFile:(CodeFile *)codeFile withPro:(Project *)project a
1362
1362
1363
1363
- (void )request_CodeBranches_WithObj : (EACodeBranches *)curObj andBlock : (void (^)(EACodeBranches *data, NSError *error))block {
1364
1364
curObj.isLoading = YES ;
1365
+ // 拿 branch 列表
1365
1366
[[CodingNetAPIClient sharedJsonClient ] requestJsonDataWithPath: [curObj toPath ] withParams: [curObj toParams ] withMethodType: Get andBlock: ^(id data, NSError *error) {
1366
- curObj.isLoading = NO ;
1367
1367
if (data) {
1368
1368
[MobClick event: kUmeng_Event_Request_Get label: @" 分支管理_列表" ];
1369
1369
1370
1370
id resultData = [data valueForKeyPath: @" data" ];
1371
1371
EACodeBranches *resultA = [NSObject objectOfClass: @" EACodeBranches" fromJSON: resultData];
1372
1372
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);
1383
1389
}
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
+ }
1389
1407
}else {
1408
+ curObj.isLoading = NO ;
1390
1409
block (resultA, nil );
1391
1410
}
1392
1411
}else {
1412
+ curObj.isLoading = NO ;
1393
1413
block (nil , error);
1394
1414
}
1395
1415
}];
0 commit comments