Gitlab endpoint for creating project randomly ignore 'initialize_with_readme' and 'default_branch' fields
Summary
Inside my app, hosted on AWS, I'm using a project endpoint to create a project (https://docs.gitlab.com/ee/api/projects.html#create-project). The problem is it not always create a project with the configuration I send in a body of a request. This is a log from my app:
and this is a code I java I use to call this endpoint:
@Override
public ProjectResponse createProject(
GroupResponse group, ProjectParameters parameters, String gitlabToken) {
String createProject = jsonService.toJson(
CreateProject.builder()
.name(parameters.getProjectName())
.path(encode(buildPathFromName(parameters.getProjectName())))
.namespaceId(group == null ? null : group.getId())
.defaultBranch(parameters.getBranch())
.build());
log.info("Create project json: " + createProject);
HttpRequest request =
HttpRequest.newBuilder(URI.create(GITLAB_HOST + "/projects"))
.header(PRIVATE_TOKEN_HEADER, gitlabToken)
.timeout(
Duration.of(
config.get(EnvironmentVariables.HTTP_CLIENT_TIMEOUT_IN_SECONDS, 20), SECONDS))
.header(CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType())
.POST(HttpRequest.BodyPublishers.ofString(createProject))
.build();
HttpResponse<String> response = callService(request);
if (response.statusCode() != HttpStatus.SC_CREATED) {
throw new IllegalArgumentException(
"Couldn't create Gitlab project with name "
+ parameters.getProjectName()
+ ": "
+ response.body());
}
String reqbody = request.bodyPublisher().map(p -> {
var bodySubscriber = HttpResponse.BodySubscribers.ofString(StandardCharsets.UTF_8);
var flowSubscriber = new StringSubscriber(bodySubscriber);
p.subscribe(flowSubscriber);
return bodySubscriber.getBody().toCompletableFuture().join();
}).orElseThrow();
log.info("Request body from body Publisher: " + reqbody);
log.info("Create project response: " + response.body());
return parseResponse(response, ProjectResponse.class);
}
As you can see the only thing is happening between these two logs is this:
HttpRequest request =
HttpRequest.newBuilder(URI.create(GITLAB_HOST + "/projects"))
.header(PRIVATE_TOKEN_HEADER, gitlabToken)
.timeout(
Duration.of(
config.get(EnvironmentVariables.HTTP_CLIENT_TIMEOUT_IN_SECONDS, 20), SECONDS))
.header(CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType())
.POST(HttpRequest.BodyPublishers.ofString(createProject))
.build();
Am I doing something wrong here?
Also, I was trying to reproduce this error with Jmeter with no luck.