Skip to content

Commit

Permalink
Merge pull request #201 from abd3/master
Browse files Browse the repository at this point in the history
Update the error messages in the event that a project is not found
  • Loading branch information
gabrie-allaigre authored Dec 31, 2018
2 parents e986bbf + 9889bd0 commit a39c76f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Inspired by https://github.com/SonarCommunity/sonar-github
- Fix sonar issues limit 10000 [#140](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/issues/140)
- Add test for covorage

**[Download 3.0.2](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/3.0.2/sonar-gitlab-plugin-3.0.2.jar)**
**[Download 3.0.2](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/3.0.2/sonar-gitlab-plugin-3.0.2.jar)**

## Version 3.0.1

Expand All @@ -50,7 +50,7 @@ Inspired by https://github.com/SonarCommunity/sonar-github
### Fixed
- Fix bug with QualityGate status NONE #107

**[Download 3.0.1](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/3.0.1/sonar-gitlab-plugin-3.0.1.jar)**
**[Download 3.0.1](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/3.0.1/sonar-gitlab-plugin-3.0.1.jar)**

## Version 3.0.0

Expand All @@ -68,7 +68,7 @@ Inspired by https://github.com/SonarCommunity/sonar-github
### Removed
- Plugin property sonar.gitlab.ref. The property is replaced by sonar.gitlab.ref_name

**[Download 3.0.0](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/3.0.0/sonar-gitlab-plugin-3.0.0.jar)**
**[Download 3.0.0](https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/3.0.0/sonar-gitlab-plugin-3.0.0.jar)**

## Version 2.1.0

Expand Down Expand Up @@ -97,7 +97,7 @@ Inspired by https://github.com/SonarCommunity/sonar-github
- Disable reporting in global comments
- Disable reporting in inline comments
- Add support Proxy
- Ignore certficate if auto-signed
- Ignore certficate if auto-signed
- Custom global comment (Template)
- Custom inline comment (Template)
- Get multi SHA for comment inline all commits
Expand Down Expand Up @@ -145,7 +145,7 @@ For SonarQube < 5.4:

- Download last version https://github.com/gabrie-allaigre/sonar-gitlab-plugin/releases/download/1.6.6/sonar-gitlab-plugin-1.6.6.jar
- Copy file in extensions directory `SONARQUBE_HOME/extensions/plugins`
- Restart SonarQube
- Restart SonarQube

For SonarQube >= 5.4 and < 5.6:

Expand Down Expand Up @@ -177,7 +177,7 @@ For SonarQube >= 7.0:

Example:

### Issues mode (Preview)
### Issues mode (Preview)

With Maven

Expand All @@ -188,7 +188,7 @@ mvn --batch-mode verify sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.login=$S
or for comment inline in all commits of branch:

```shell
mvn --batch-mode verify sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_LOGIN -Dsonar.analysis.mode=preview -Dsonar.gitlab.commit_sha=$(git log --pretty=format:%H origin/master..$CI_COMMIT_SHA | tr '\n' ',') -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.project_id=$CI_PROJECT_ID -Dsonar.gitlab.unique_issue_per_inline=true
mvn --batch-mode verify sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_LOGIN -Dsonar.analysis.mode=preview -Dsonar.gitlab.commit_sha=$(git log --pretty=format:%H origin/master..$CI_COMMIT_SHA | tr '\n' ',') -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.project_id=$CI_PROJECT_ID -Dsonar.gitlab.unique_issue_per_inline=true
```

With SonarScanner
Expand Down Expand Up @@ -298,7 +298,7 @@ sonarqube_master_job:
only:
- master
script:
- mvn --batch-mode verify sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_LOGIN -Dsonar.gitlab.project_id=$CI_PROJECT_PATH -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.json_mode=CODECLIMATE -Dsonar.gitlab.failure_notification_mode=commit-status
- mvn --batch-mode verify sonar:sonar -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_LOGIN -Dsonar.gitlab.project_id=$CI_PROJECT_PATH -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.json_mode=CODECLIMATE -Dsonar.gitlab.failure_notification_mode=commit-status
artifacts:
expire_in: 1 day
paths:
Expand Down Expand Up @@ -490,7 +490,7 @@ Usage : `${qualityGate.name(arg1,arg2,...)}`
| conditionCount | Function none argument | Integer | Get size of all conditions |
| conditionCount | Function Status argument | Integer | Get size conditions with Status|

### Types
### Types

Usage : `${Issue.name}`

Expand Down Expand Up @@ -646,9 +646,9 @@ Import it into your JRE cacerts (you can check from the "System Info" page in th
Restart your SonarQube instance.

## Make it works with a private project
- On a private project, with the provided command line upper in this document, you'll got an "IllegalStateException: Unable found project for" Exception.
- It's necessary to create a "Personal Access Tokens". It needs a user with the "developper" right in the project. The token can be created in the profile menu, check the api checkbox.
- Then, use the following command line to run sonar thought gitlab-ci
- On a private project, with the provided command line upper in this document, you'll got an "IllegalStateException: Unable to find project ID" Exception.
- It's necessary to create a "Personal Access Tokens". It needs a user with the "developer" right in the project. The token can be created in the profile menu, check the api checkbox.
- Then, use the following command line to run sonar thought gitlab-ci

``` batch
mvn --batch-mode verify sonar:sonar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void setGitLabAPI(GitLabAPI gitLabAPI) {

private GitLabProject getGitLabProject() throws IOException {
if (config.projectId() == null) {
throw new IllegalStateException("Unable found project for null project name. Set Configuration sonar.gitlab.project_id");
throw new IllegalStateException("Unable to find project ID null. Set the property sonar.gitlab.project_id");
}

try {
Expand All @@ -89,7 +89,7 @@ private GitLabProject getGitLabProject() throws IOException {

Paged<GitLabProject> paged = gitLabAPIV3.getGitLabAPIProjects().getProjects(null, null, null, null, null, null);
if (paged == null) {
throw new IllegalStateException("Unable found project for " + config.projectId() + " Verify Configuration sonar.gitlab.project_id or sonar.gitlab.user_token access project");
throw new IllegalStateException("Unable to find project ID " + config.projectId() + ". Either the project ID is incorrect or you don't have access to this project. Verify the configurations sonar.gitlab.project_id or sonar.gitlab.user_token");
}
List<GitLabProject> projects = new ArrayList<>();
do {
Expand All @@ -99,7 +99,7 @@ private GitLabProject getGitLabProject() throws IOException {
} while ((paged = paged.nextPage()) != null);

if (projects.isEmpty()) {
throw new IllegalStateException("Unable found project for " + config.projectId() + " Verify Configuration sonar.gitlab.project_id or sonar.gitlab.user_token access project");
throw new IllegalStateException("Unable to find project ID " + config.projectId() + ". Either the project ID is incorrect or you don't have access to this project. Verify the configurations sonar.gitlab.project_id or sonar.gitlab.user_token");
}
if (projects.size() > 1) {
throw new IllegalStateException("Multiple found projects for " + config.projectId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void setGitLabAPI(GitLabAPI gitLabAPI) {

private GitLabProject getGitLabProject() throws IOException {
if (config.projectId() == null) {
throw new IllegalStateException("Unable found project for null project name. Set Configuration sonar.gitlab.project_id");
throw new IllegalStateException("Unable to find project ID null. Set the property sonar.gitlab.project_id");
}

try {
Expand All @@ -89,7 +89,7 @@ private GitLabProject getGitLabProject() throws IOException {

Paged<GitLabProject> paged = gitLabAPIV4.getGitLabAPIProjects().getProjects(null, null, null, null, null, null);
if (paged == null) {
throw new IllegalStateException("Unable found project for " + config.projectId() + " Verify Configuration sonar.gitlab.project_id or sonar.gitlab.user_token access project");
throw new IllegalStateException("Unable to find project ID " + config.projectId() + ". Either the project ID is incorrect or you don't have access to this project. Verify the configurations sonar.gitlab.project_id or sonar.gitlab.user_token");
}
List<GitLabProject> projects = new ArrayList<>();
do {
Expand All @@ -99,7 +99,7 @@ private GitLabProject getGitLabProject() throws IOException {
} while ((paged = paged.nextPage()) != null);

if (projects.isEmpty()) {
throw new IllegalStateException("Unable found project for " + config.projectId() + " Verify Configuration sonar.gitlab.project_id or sonar.gitlab.user_token access project");
throw new IllegalStateException("Unable to find project ID " + config.projectId() + ". Either the project ID is incorrect or you don't have access to this project. Verify the configurations sonar.gitlab.project_id or sonar.gitlab.user_token");
}
if (projects.size() > 1) {
throw new IllegalStateException("Multiple found projects for " + config.projectId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void testProjectIdNull() throws Exception {
when(gitLabPluginConfiguration.projectId()).thenReturn(null);

CommitFacade facade = new CommitFacade(gitLabPluginConfiguration);
Assertions.assertThatThrownBy(() -> facade.init(gitBasedir)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Unable found project for null project name. Set Configuration sonar.gitlab.project_id");
Assertions.assertThatThrownBy(() -> facade.init(gitBasedir)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Unable to find project ID null. Set the property sonar.gitlab.project_id");
}

@Test
Expand All @@ -87,7 +87,7 @@ public void testProjectIdReturnEmpty() throws Exception {
"}]"));

CommitFacade facade = new CommitFacade(gitLabPluginConfiguration);
Assertions.assertThatThrownBy(() -> facade.init(gitBasedir)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Unable found project for 123 Verify Configuration sonar.gitlab.project_id or sonar.gitlab.user_token access project");
Assertions.assertThatThrownBy(() -> facade.init(gitBasedir)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Unable to find project ID 123. Either the project ID is incorrect or you don't have access to this project. Verify the configurations sonar.gitlab.project_id or sonar.gitlab.user_token");
}

@Test
Expand All @@ -100,7 +100,7 @@ public void testProjectIdReturnNotFound() throws Exception {
gitlab.enqueue(new MockResponse().setResponseCode(200).setBody("[]"));

CommitFacade facade = new CommitFacade(gitLabPluginConfiguration);
Assertions.assertThatThrownBy(() -> facade.init(gitBasedir)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Unable found project for 123 Verify Configuration sonar.gitlab.project_id or sonar.gitlab.user_token access project");
Assertions.assertThatThrownBy(() -> facade.init(gitBasedir)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Unable to find project ID 123. Either the project ID is incorrect or you don't have access to this project. Verify the configurations sonar.gitlab.project_id or sonar.gitlab.user_token");
}

@Test
Expand Down Expand Up @@ -613,4 +613,4 @@ public void testGetUsernameForRevisionExist() throws Exception {

Assertions.assertThat(facade.getUsernameForRevision("6104942438c14ec7bd21c6cd5bd995272b3faff6")).isEqualTo("john_smith");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void testProjectIdNull() throws Exception {
when(gitLabPluginConfiguration.projectId()).thenReturn(null);

CommitFacade facade = new CommitFacade(gitLabPluginConfiguration);
Assertions.assertThatThrownBy(() -> facade.init(gitBasedir)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Unable found project for null project name. Set Configuration sonar.gitlab.project_id");
Assertions.assertThatThrownBy(() -> facade.init(gitBasedir)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Unable to find project ID null. Set the property sonar.gitlab.project_id");
}

@Test
Expand All @@ -87,7 +87,7 @@ public void testProjectIdReturnEmpty() throws Exception {
"}]"));

CommitFacade facade = new CommitFacade(gitLabPluginConfiguration);
Assertions.assertThatThrownBy(() -> facade.init(gitBasedir)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Unable found project for 123 Verify Configuration sonar.gitlab.project_id or sonar.gitlab.user_token access project");
Assertions.assertThatThrownBy(() -> facade.init(gitBasedir)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Unable to find project ID 123. Either the project ID is incorrect or you don't have access to this project. Verify the configurations sonar.gitlab.project_id or sonar.gitlab.user_token");
}

@Test
Expand All @@ -100,7 +100,7 @@ public void testProjectIdReturnNotFound() throws Exception {
gitlab.enqueue(new MockResponse().setResponseCode(200).setBody("[]"));

CommitFacade facade = new CommitFacade(gitLabPluginConfiguration);
Assertions.assertThatThrownBy(() -> facade.init(gitBasedir)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Unable found project for 123 Verify Configuration sonar.gitlab.project_id or sonar.gitlab.user_token access project");
Assertions.assertThatThrownBy(() -> facade.init(gitBasedir)).isInstanceOf(IllegalStateException.class).hasMessageContaining("Unable to find project ID 123. Either the project ID is incorrect or you don't have access to this project. Verify the configurations sonar.gitlab.project_id or sonar.gitlab.user_token");
}

@Test
Expand Down Expand Up @@ -613,4 +613,4 @@ public void testGetUsernameForRevisionExist() throws Exception {

Assertions.assertThat(facade.getUsernameForRevision("6104942438c14ec7bd21c6cd5bd995272b3faff6")).isEqualTo("john_smith");
}
}
}

0 comments on commit a39c76f

Please sign in to comment.