Skip to content
This repository was archived by the owner on Apr 2, 2019. It is now read-only.

Commit 066032d

Browse files
committed
SONARGITUB-14 Do not rely only on sonar.dryRun property since it was removed in 5.2
1 parent 88c8f29 commit 066032d

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

src/main/java/org/sonar/plugins/github/PullRequestProjectBuilder.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ public void build(Context context) {
5555
}
5656

5757
private void checkMode() {
58-
if (!settings.getBoolean(CoreProperties.DRY_RUN)) {
59-
throw MessageException.of("The GitHub plugin is only intended to be used in preview mode. Please set '" + CoreProperties.ANALYSIS_MODE + "'.");
58+
boolean isIssues = settings.getBoolean(CoreProperties.DRY_RUN) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(settings.getString(CoreProperties.ANALYSIS_MODE))
59+
|| CoreProperties.ANALYSIS_MODE_INCREMENTAL.equals(settings.getString(CoreProperties.ANALYSIS_MODE))
60+
// 5.2+
61+
|| "issues".equals(settings.getString(CoreProperties.ANALYSIS_MODE));
62+
if (!isIssues) {
63+
throw MessageException.of("The GitHub plugin is only intended to be used in preview or issues mode. Please set '" + CoreProperties.ANALYSIS_MODE + "'.");
6064
}
6165

6266
}

src/test/java/org/sonar/plugins/github/PullRequestProjectBuilderTest.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,48 @@ public void shouldFailIfNotPreview() {
6666
settings.setProperty(GitHubPlugin.GITHUB_PULL_REQUEST, "1");
6767

6868
thrown.expect(MessageException.class);
69-
thrown.expectMessage("The GitHub plugin is only intended to be used in preview mode. Please set 'sonar.analysis.mode'.");
69+
thrown.expectMessage("The GitHub plugin is only intended to be used in preview or issues mode. Please set 'sonar.analysis.mode'.");
7070

7171
pullRequestProjectBuilder.build(null);
7272
}
7373

7474
@Test
75-
public void shouldNotFailIfPreview() {
75+
public void shouldNotFailIfDryRun() {
7676
settings.setProperty(GitHubPlugin.GITHUB_PULL_REQUEST, "1");
7777
settings.setProperty(CoreProperties.DRY_RUN, "true");
7878

7979
pullRequestProjectBuilder.build(mock(ProjectBuilder.Context.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS)));
8080

8181
verify(facade).init(eq(1), any(File.class));
82+
}
8283

84+
@Test
85+
public void shouldNotFailIfPreview() {
86+
settings.setProperty(GitHubPlugin.GITHUB_PULL_REQUEST, "1");
87+
settings.setProperty(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW);
88+
89+
pullRequestProjectBuilder.build(mock(ProjectBuilder.Context.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS)));
90+
91+
verify(facade).init(eq(1), any(File.class));
92+
}
93+
94+
@Test
95+
public void shouldNotFailIfIncremental() {
96+
settings.setProperty(GitHubPlugin.GITHUB_PULL_REQUEST, "1");
97+
settings.setProperty(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_INCREMENTAL);
98+
99+
pullRequestProjectBuilder.build(mock(ProjectBuilder.Context.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS)));
100+
101+
verify(facade).init(eq(1), any(File.class));
102+
}
103+
104+
@Test
105+
public void shouldNotFailIfIssues() {
106+
settings.setProperty(GitHubPlugin.GITHUB_PULL_REQUEST, "1");
107+
settings.setProperty(CoreProperties.ANALYSIS_MODE, "issues");
108+
109+
pullRequestProjectBuilder.build(mock(ProjectBuilder.Context.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS)));
110+
111+
verify(facade).init(eq(1), any(File.class));
83112
}
84113
}

0 commit comments

Comments
 (0)