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