Browse Source

SONAR-20640 removed 'organization' parameter from api/alm_integrations/import_github_project

tags/10.3.0.82913
Aurelien Poscia 7 months ago
parent
commit
b9ee3198bb

+ 0
- 16
server/sonar-webserver-webapi/src/it/java/org/sonar/server/almintegration/ws/github/ImportGithubProjectActionIT.java View File

import static org.sonar.db.newcodeperiod.NewCodePeriodType.NUMBER_OF_DAYS; import static org.sonar.db.newcodeperiod.NewCodePeriodType.NUMBER_OF_DAYS;
import static org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH; import static org.sonar.db.newcodeperiod.NewCodePeriodType.REFERENCE_BRANCH;
import static org.sonar.server.almintegration.ws.ImportHelper.PARAM_ALM_SETTING; import static org.sonar.server.almintegration.ws.ImportHelper.PARAM_ALM_SETTING;
import static org.sonar.server.almintegration.ws.github.ImportGithubProjectAction.PARAM_ORGANIZATION;
import static org.sonar.server.almintegration.ws.github.ImportGithubProjectAction.PARAM_REPOSITORY_KEY; import static org.sonar.server.almintegration.ws.github.ImportGithubProjectAction.PARAM_REPOSITORY_KEY;
import static org.sonar.server.tester.UserSessionRule.standalone; import static org.sonar.server.tester.UserSessionRule.standalone;
import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_NEW_CODE_DEFINITION_TYPE; import static org.sonarqube.ws.client.project.ProjectsWsParameters.PARAM_NEW_CODE_DEFINITION_TYPE;


Projects.CreateWsResponse response = ws.newRequest() Projects.CreateWsResponse response = ws.newRequest()
.setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey()) .setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey())
.setParam(PARAM_ORGANIZATION, "octocat")
.setParam(PARAM_REPOSITORY_KEY, "octocat/" + PROJECT_KEY_NAME) .setParam(PARAM_REPOSITORY_KEY, "octocat/" + PROJECT_KEY_NAME)
.setParam(PARAM_NEW_CODE_DEFINITION_TYPE, "NUMBER_OF_DAYS") .setParam(PARAM_NEW_CODE_DEFINITION_TYPE, "NUMBER_OF_DAYS")
.setParam(PARAM_NEW_CODE_DEFINITION_VALUE, "30") .setParam(PARAM_NEW_CODE_DEFINITION_VALUE, "30")


Projects.CreateWsResponse response = ws.newRequest() Projects.CreateWsResponse response = ws.newRequest()
.setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey()) .setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey())
.setParam(PARAM_ORGANIZATION, "octocat")
.setParam(PARAM_REPOSITORY_KEY, "octocat/" + PROJECT_KEY_NAME) .setParam(PARAM_REPOSITORY_KEY, "octocat/" + PROJECT_KEY_NAME)
.setParam(PARAM_NEW_CODE_DEFINITION_TYPE, "NUMBER_OF_DAYS") .setParam(PARAM_NEW_CODE_DEFINITION_TYPE, "NUMBER_OF_DAYS")
.setParam(PARAM_NEW_CODE_DEFINITION_VALUE, "30") .setParam(PARAM_NEW_CODE_DEFINITION_VALUE, "30")


Projects.CreateWsResponse response = ws.newRequest() Projects.CreateWsResponse response = ws.newRequest()
.setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey()) .setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey())
.setParam(PARAM_ORGANIZATION, "octocat")
.setParam(PARAM_REPOSITORY_KEY, "octocat/" + PROJECT_KEY_NAME) .setParam(PARAM_REPOSITORY_KEY, "octocat/" + PROJECT_KEY_NAME)
.setParam(PARAM_NEW_CODE_DEFINITION_TYPE, "reference_branch") .setParam(PARAM_NEW_CODE_DEFINITION_TYPE, "reference_branch")
.executeProtobuf(Projects.CreateWsResponse.class); .executeProtobuf(Projects.CreateWsResponse.class);


Projects.CreateWsResponse response = ws.newRequest() Projects.CreateWsResponse response = ws.newRequest()
.setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey()) .setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey())
.setParam(PARAM_ORGANIZATION, "octocat")
.setParam(PARAM_REPOSITORY_KEY, "octocat/" + PROJECT_KEY_NAME) .setParam(PARAM_REPOSITORY_KEY, "octocat/" + PROJECT_KEY_NAME)
.setParam(PARAM_NEW_CODE_DEFINITION_TYPE, "reference_branch") .setParam(PARAM_NEW_CODE_DEFINITION_TYPE, "reference_branch")
.executeProtobuf(Projects.CreateWsResponse.class); .executeProtobuf(Projects.CreateWsResponse.class);


Projects.CreateWsResponse response = ws.newRequest() Projects.CreateWsResponse response = ws.newRequest()
.setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey()) .setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey())
.setParam(PARAM_ORGANIZATION, "octocat")
.setParam(PARAM_REPOSITORY_KEY, "Hello-World") .setParam(PARAM_REPOSITORY_KEY, "Hello-World")
.executeProtobuf(Projects.CreateWsResponse.class); .executeProtobuf(Projects.CreateWsResponse.class);




ws.newRequest() ws.newRequest()
.setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey()) .setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey())
.setParam(PARAM_ORGANIZATION, "octocat")
.setParam(PARAM_REPOSITORY_KEY, "octocat/" + PROJECT_KEY_NAME) .setParam(PARAM_REPOSITORY_KEY, "octocat/" + PROJECT_KEY_NAME)
.executeProtobuf(Projects.CreateWsResponse.class); .executeProtobuf(Projects.CreateWsResponse.class);




ws.newRequest() ws.newRequest()
.setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey()) .setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey())
.setParam(PARAM_ORGANIZATION, "octocat")
.setParam(PARAM_REPOSITORY_KEY, "octocat/" + PROJECT_KEY_NAME) .setParam(PARAM_REPOSITORY_KEY, "octocat/" + PROJECT_KEY_NAME)
.executeProtobuf(Projects.CreateWsResponse.class); .executeProtobuf(Projects.CreateWsResponse.class);




TestRequest request = ws.newRequest() TestRequest request = ws.newRequest()
.setParam(PARAM_ALM_SETTING, "unknown") .setParam(PARAM_ALM_SETTING, "unknown")
.setParam(PARAM_ORGANIZATION, "test")
.setParam(PARAM_REPOSITORY_KEY, "test/repo"); .setParam(PARAM_REPOSITORY_KEY, "test/repo");
assertThatThrownBy(request::execute) assertThatThrownBy(request::execute)
.isInstanceOf(NotFoundException.class) .isInstanceOf(NotFoundException.class)
userSession.logIn(user).addPermission(GlobalPermission.PROVISION_PROJECTS); userSession.logIn(user).addPermission(GlobalPermission.PROVISION_PROJECTS);


TestRequest request = ws.newRequest() TestRequest request = ws.newRequest()
.setParam(PARAM_ORGANIZATION, "test")
.setParam(PARAM_REPOSITORY_KEY, "test/repo"); .setParam(PARAM_REPOSITORY_KEY, "test/repo");
assertThatThrownBy(request::execute) assertThatThrownBy(request::execute)
.isInstanceOf(NotFoundException.class) .isInstanceOf(NotFoundException.class)
db.almSettings().insertGitHubAlmSetting(); db.almSettings().insertGitHubAlmSetting();


TestRequest request = ws.newRequest() TestRequest request = ws.newRequest()
.setParam(PARAM_ORGANIZATION, "test")
.setParam(PARAM_REPOSITORY_KEY, "test/repo"); .setParam(PARAM_REPOSITORY_KEY, "test/repo");
assertThatThrownBy(request::execute) assertThatThrownBy(request::execute)
.isInstanceOf(IllegalArgumentException.class) .isInstanceOf(IllegalArgumentException.class)


TestRequest request = ws.newRequest() TestRequest request = ws.newRequest()
.setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey()) .setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey())
.setParam(PARAM_ORGANIZATION, "octocat")
.setParam(PARAM_REPOSITORY_KEY, "octocat/" + PROJECT_KEY_NAME); .setParam(PARAM_REPOSITORY_KEY, "octocat/" + PROJECT_KEY_NAME);


assertThatNoException().isThrownBy(request::execute); assertThatNoException().isThrownBy(request::execute);
private Projects.CreateWsResponse callWebService(AlmSettingDto githubAlmSetting) { private Projects.CreateWsResponse callWebService(AlmSettingDto githubAlmSetting) {
return ws.newRequest() return ws.newRequest()
.setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey()) .setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey())
.setParam(PARAM_ORGANIZATION, "octocat")
.setParam(PARAM_REPOSITORY_KEY, "octocat/" + PROJECT_KEY_NAME) .setParam(PARAM_REPOSITORY_KEY, "octocat/" + PROJECT_KEY_NAME)
.executeProtobuf(Projects.CreateWsResponse.class); .executeProtobuf(Projects.CreateWsResponse.class);
} }
public void fail_when_not_logged_in() { public void fail_when_not_logged_in() {
TestRequest request = ws.newRequest() TestRequest request = ws.newRequest()
.setParam(PARAM_ALM_SETTING, "asdfghjkl") .setParam(PARAM_ALM_SETTING, "asdfghjkl")
.setParam(PARAM_ORGANIZATION, "test")
.setParam(PARAM_REPOSITORY_KEY, "test/repo"); .setParam(PARAM_REPOSITORY_KEY, "test/repo");
assertThatThrownBy(request::execute) assertThatThrownBy(request::execute)
.isInstanceOf(UnauthorizedException.class); .isInstanceOf(UnauthorizedException.class);


TestRequest request = ws.newRequest() TestRequest request = ws.newRequest()
.setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey()) .setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey())
.setParam(PARAM_ORGANIZATION, "test")
.setParam(PARAM_REPOSITORY_KEY, "test/repo"); .setParam(PARAM_REPOSITORY_KEY, "test/repo");
assertThatThrownBy(request::execute) assertThatThrownBy(request::execute)
.isInstanceOf(IllegalArgumentException.class) .isInstanceOf(IllegalArgumentException.class)
.extracting(WebService.Param::key, WebService.Param::isRequired) .extracting(WebService.Param::key, WebService.Param::isRequired)
.containsExactlyInAnyOrder( .containsExactlyInAnyOrder(
tuple(PARAM_ALM_SETTING, false), tuple(PARAM_ALM_SETTING, false),
tuple(PARAM_ORGANIZATION, true),
tuple(PARAM_REPOSITORY_KEY, true), tuple(PARAM_REPOSITORY_KEY, true),
tuple(PARAM_NEW_CODE_DEFINITION_TYPE, false), tuple(PARAM_NEW_CODE_DEFINITION_TYPE, false),
tuple(PARAM_NEW_CODE_DEFINITION_VALUE, false)); tuple(PARAM_NEW_CODE_DEFINITION_VALUE, false));

+ 1
- 1
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almsettings/ws/GitHubDevOpsPlatformServiceTest.java View File

when(repository.getDefaultBranch()).thenReturn(MAIN_BRANCH_NAME); when(repository.getDefaultBranch()).thenReturn(MAIN_BRANCH_NAME);
when(repository.getName()).thenReturn(PROJECT_NAME); when(repository.getName()).thenReturn(PROJECT_NAME);
when(repository.getFullName()).thenReturn(GITHUB_REPO_FULL_NAME); when(repository.getFullName()).thenReturn(GITHUB_REPO_FULL_NAME);
when(githubApplicationClient.getRepository(GITHUB_API_URL, appInstallationToken, PROJECT_NAME)).thenReturn(Optional.of(repository));
when(githubApplicationClient.getRepository(GITHUB_API_URL, appInstallationToken, GITHUB_REPO_FULL_NAME)).thenReturn(Optional.of(repository));
when(projectKeyGenerator.generateUniqueProjectKey(repository.getFullName())).thenReturn("generated_" + PROJECT_KEY); when(projectKeyGenerator.generateUniqueProjectKey(repository.getFullName())).thenReturn("generated_" + PROJECT_KEY);
} }



+ 19
- 0
sonar-core/src/main/java/org/sonar/core/ce/package-info.java View File

/*
* SonarQube
* Copyright (C) 2009-2023 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
package org.sonar.core.ce; package org.sonar.core.ce;



+ 0
- 1
sonar-ws/src/main/java/org/sonarqube/ws/client/almintegrations/AlmIntegrationsService.java View File

return call( return call(
new PostRequest(path("import_github_project")) new PostRequest(path("import_github_project"))
.setParam("almSetting", request.getAlmSetting()) .setParam("almSetting", request.getAlmSetting())
.setParam("organization", request.getOrganization())
.setParam("repositoryKey", request.getRepositoryKey()) .setParam("repositoryKey", request.getRepositoryKey())
.setMediaType(MediaTypes.JSON), .setMediaType(MediaTypes.JSON),
Projects.CreateWsResponse.parser()); Projects.CreateWsResponse.parser());

+ 0
- 14
sonar-ws/src/main/java/org/sonarqube/ws/client/almintegrations/ImportGithubProjectRequest.java View File

private String almSetting; private String almSetting;
private String repositoryKey; private String repositoryKey;


private String organization;

/** /**
* This is a mandatory parameter. * This is a mandatory parameter.
*/ */
return this; return this;
} }


public String getOrganization() {
return organization;
}

/**
* This is a mandatory parameter.
*/
public ImportGithubProjectRequest setOrganization(String organization) {
this.organization = organization;
return this;
}

} }

Loading…
Cancel
Save