|
17 | 17 |
|
18 | 18 | import com.getaxonflow.sdk.exceptions.*; |
19 | 19 | import com.getaxonflow.sdk.types.*; |
| 20 | +import com.getaxonflow.sdk.types.codegovernance.*; |
20 | 21 | import com.getaxonflow.sdk.types.policies.PolicyTypes.*; |
21 | 22 | import com.getaxonflow.sdk.util.*; |
22 | 23 | import com.fasterxml.jackson.core.JsonProcessingException; |
@@ -1343,6 +1344,220 @@ private String extractErrorMessage(String body, String defaultMessage) { |
1343 | 1344 | return defaultMessage; |
1344 | 1345 | } |
1345 | 1346 |
|
| 1347 | + // ======================================================================== |
| 1348 | + // Code Governance - Git Provider APIs (Enterprise) |
| 1349 | + // ======================================================================== |
| 1350 | + |
| 1351 | + /** |
| 1352 | + * Validates Git provider credentials without saving them. |
| 1353 | + * |
| 1354 | + * @param request the validation request with provider type and credentials |
| 1355 | + * @return validation result |
| 1356 | + * @throws IOException if the request fails |
| 1357 | + */ |
| 1358 | + public ValidateGitProviderResponse validateGitProvider(ValidateGitProviderRequest request) throws IOException { |
| 1359 | + logger.debug("Validating Git provider: {}", request.getType()); |
| 1360 | + |
| 1361 | + String json = objectMapper.writeValueAsString(request); |
| 1362 | + RequestBody body = RequestBody.create(json, JSON); |
| 1363 | + |
| 1364 | + Request httpRequest = new Request.Builder() |
| 1365 | + .url(config.getAgentUrl() + "/api/v1/code-governance/git-providers/validate") |
| 1366 | + .post(body) |
| 1367 | + .build(); |
| 1368 | + |
| 1369 | + addAuthHeaders(httpRequest.newBuilder()); |
| 1370 | + |
| 1371 | + Request.Builder builder = httpRequest.newBuilder(); |
| 1372 | + addAuthHeaders(builder); |
| 1373 | + |
| 1374 | + try (Response response = httpClient.newCall(builder.build()).execute()) { |
| 1375 | + return parseResponse(response, ValidateGitProviderResponse.class); |
| 1376 | + } |
| 1377 | + } |
| 1378 | + |
| 1379 | + /** |
| 1380 | + * Configures a Git provider for code governance. |
| 1381 | + * |
| 1382 | + * @param request the configuration request with provider type and credentials |
| 1383 | + * @return configuration result |
| 1384 | + * @throws IOException if the request fails |
| 1385 | + */ |
| 1386 | + public ConfigureGitProviderResponse configureGitProvider(ConfigureGitProviderRequest request) throws IOException { |
| 1387 | + logger.debug("Configuring Git provider: {}", request.getType()); |
| 1388 | + |
| 1389 | + String json = objectMapper.writeValueAsString(request); |
| 1390 | + RequestBody body = RequestBody.create(json, JSON); |
| 1391 | + |
| 1392 | + Request.Builder builder = new Request.Builder() |
| 1393 | + .url(config.getAgentUrl() + "/api/v1/code-governance/git-providers") |
| 1394 | + .post(body); |
| 1395 | + |
| 1396 | + addAuthHeaders(builder); |
| 1397 | + |
| 1398 | + try (Response response = httpClient.newCall(builder.build()).execute()) { |
| 1399 | + return parseResponse(response, ConfigureGitProviderResponse.class); |
| 1400 | + } |
| 1401 | + } |
| 1402 | + |
| 1403 | + /** |
| 1404 | + * Lists configured Git providers. |
| 1405 | + * |
| 1406 | + * @return list of configured providers |
| 1407 | + * @throws IOException if the request fails |
| 1408 | + */ |
| 1409 | + public ListGitProvidersResponse listGitProviders() throws IOException { |
| 1410 | + logger.debug("Listing Git providers"); |
| 1411 | + |
| 1412 | + Request.Builder builder = new Request.Builder() |
| 1413 | + .url(config.getAgentUrl() + "/api/v1/code-governance/git-providers") |
| 1414 | + .get(); |
| 1415 | + |
| 1416 | + addAuthHeaders(builder); |
| 1417 | + |
| 1418 | + try (Response response = httpClient.newCall(builder.build()).execute()) { |
| 1419 | + return parseResponse(response, ListGitProvidersResponse.class); |
| 1420 | + } |
| 1421 | + } |
| 1422 | + |
| 1423 | + /** |
| 1424 | + * Deletes a configured Git provider. |
| 1425 | + * |
| 1426 | + * @param providerType the provider type to delete |
| 1427 | + * @throws IOException if the request fails |
| 1428 | + */ |
| 1429 | + public void deleteGitProvider(GitProviderType providerType) throws IOException { |
| 1430 | + logger.debug("Deleting Git provider: {}", providerType); |
| 1431 | + |
| 1432 | + Request.Builder builder = new Request.Builder() |
| 1433 | + .url(config.getAgentUrl() + "/api/v1/code-governance/git-providers/" + providerType.getValue()) |
| 1434 | + .delete(); |
| 1435 | + |
| 1436 | + addAuthHeaders(builder); |
| 1437 | + |
| 1438 | + try (Response response = httpClient.newCall(builder.build()).execute()) { |
| 1439 | + handleErrorResponse(response); |
| 1440 | + } |
| 1441 | + } |
| 1442 | + |
| 1443 | + /** |
| 1444 | + * Creates a Pull Request from LLM-generated code. |
| 1445 | + * |
| 1446 | + * @param request the PR creation request with repository info and files |
| 1447 | + * @return the created PR details |
| 1448 | + * @throws IOException if the request fails |
| 1449 | + */ |
| 1450 | + public CreatePRResponse createPR(CreatePRRequest request) throws IOException { |
| 1451 | + logger.debug("Creating PR: {} in {}/{}", request.getTitle(), request.getOwner(), request.getRepo()); |
| 1452 | + |
| 1453 | + String json = objectMapper.writeValueAsString(request); |
| 1454 | + RequestBody body = RequestBody.create(json, JSON); |
| 1455 | + |
| 1456 | + Request.Builder builder = new Request.Builder() |
| 1457 | + .url(config.getAgentUrl() + "/api/v1/code-governance/prs") |
| 1458 | + .post(body); |
| 1459 | + |
| 1460 | + addAuthHeaders(builder); |
| 1461 | + |
| 1462 | + try (Response response = httpClient.newCall(builder.build()).execute()) { |
| 1463 | + return parseResponse(response, CreatePRResponse.class); |
| 1464 | + } |
| 1465 | + } |
| 1466 | + |
| 1467 | + /** |
| 1468 | + * Lists PRs with optional filtering. |
| 1469 | + * |
| 1470 | + * @param options filtering options (limit, offset, state) |
| 1471 | + * @return list of PRs |
| 1472 | + * @throws IOException if the request fails |
| 1473 | + */ |
| 1474 | + public ListPRsResponse listPRs(ListPRsOptions options) throws IOException { |
| 1475 | + logger.debug("Listing PRs"); |
| 1476 | + |
| 1477 | + StringBuilder url = new StringBuilder(config.getAgentUrl() + "/api/v1/code-governance/prs"); |
| 1478 | + StringBuilder query = new StringBuilder(); |
| 1479 | + |
| 1480 | + if (options != null) { |
| 1481 | + if (options.getLimit() != null) { |
| 1482 | + appendQueryParam(query, "limit", String.valueOf(options.getLimit())); |
| 1483 | + } |
| 1484 | + if (options.getOffset() != null) { |
| 1485 | + appendQueryParam(query, "offset", String.valueOf(options.getOffset())); |
| 1486 | + } |
| 1487 | + if (options.getState() != null) { |
| 1488 | + appendQueryParam(query, "state", options.getState()); |
| 1489 | + } |
| 1490 | + } |
| 1491 | + |
| 1492 | + if (query.length() > 0) { |
| 1493 | + url.append("?").append(query); |
| 1494 | + } |
| 1495 | + |
| 1496 | + Request.Builder builder = new Request.Builder() |
| 1497 | + .url(url.toString()) |
| 1498 | + .get(); |
| 1499 | + |
| 1500 | + addAuthHeaders(builder); |
| 1501 | + |
| 1502 | + try (Response response = httpClient.newCall(builder.build()).execute()) { |
| 1503 | + return parseResponse(response, ListPRsResponse.class); |
| 1504 | + } |
| 1505 | + } |
| 1506 | + |
| 1507 | + /** |
| 1508 | + * Lists PRs with default options. |
| 1509 | + * |
| 1510 | + * @return list of PRs |
| 1511 | + * @throws IOException if the request fails |
| 1512 | + */ |
| 1513 | + public ListPRsResponse listPRs() throws IOException { |
| 1514 | + return listPRs(null); |
| 1515 | + } |
| 1516 | + |
| 1517 | + /** |
| 1518 | + * Gets a specific PR by ID. |
| 1519 | + * |
| 1520 | + * @param prId the PR record ID |
| 1521 | + * @return the PR record |
| 1522 | + * @throws IOException if the request fails |
| 1523 | + */ |
| 1524 | + public PRRecord getPR(String prId) throws IOException { |
| 1525 | + logger.debug("Getting PR: {}", prId); |
| 1526 | + |
| 1527 | + Request.Builder builder = new Request.Builder() |
| 1528 | + .url(config.getAgentUrl() + "/api/v1/code-governance/prs/" + prId) |
| 1529 | + .get(); |
| 1530 | + |
| 1531 | + addAuthHeaders(builder); |
| 1532 | + |
| 1533 | + try (Response response = httpClient.newCall(builder.build()).execute()) { |
| 1534 | + return parseResponse(response, PRRecord.class); |
| 1535 | + } |
| 1536 | + } |
| 1537 | + |
| 1538 | + /** |
| 1539 | + * Syncs PR status from the Git provider. |
| 1540 | + * |
| 1541 | + * @param prId the PR record ID to sync |
| 1542 | + * @return the updated PR record |
| 1543 | + * @throws IOException if the request fails |
| 1544 | + */ |
| 1545 | + public PRRecord syncPRStatus(String prId) throws IOException { |
| 1546 | + logger.debug("Syncing PR status: {}", prId); |
| 1547 | + |
| 1548 | + RequestBody body = RequestBody.create("{}", JSON); |
| 1549 | + |
| 1550 | + Request.Builder builder = new Request.Builder() |
| 1551 | + .url(config.getAgentUrl() + "/api/v1/code-governance/prs/" + prId + "/sync") |
| 1552 | + .post(body); |
| 1553 | + |
| 1554 | + addAuthHeaders(builder); |
| 1555 | + |
| 1556 | + try (Response response = httpClient.newCall(builder.build()).execute()) { |
| 1557 | + return parseResponse(response, PRRecord.class); |
| 1558 | + } |
| 1559 | + } |
| 1560 | + |
1346 | 1561 | @Override |
1347 | 1562 | public void close() { |
1348 | 1563 | httpClient.dispatcher().executorService().shutdown(); |
|
0 commit comments