diff --git a/src/main/java/org/sonar/plugins/github/GitHubPluginConfiguration.java b/src/main/java/org/sonar/plugins/github/GitHubPluginConfiguration.java index b627be4..b77928f 100644 --- a/src/main/java/org/sonar/plugins/github/GitHubPluginConfiguration.java +++ b/src/main/java/org/sonar/plugins/github/GitHubPluginConfiguration.java @@ -28,6 +28,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import org.sonar.api.CoreProperties; import org.sonar.api.batch.BatchSide; import org.sonar.api.batch.InstantiationStrategy; @@ -136,6 +137,10 @@ public boolean tryReportIssuesInline() { return !settings.getBoolean(GitHubPlugin.GITHUB_DISABLE_INLINE_COMMENTS); } + public @Nullable String projectKey() { + return settings.getString("sonar.projectKey"); + } + /** * Checks if a proxy was passed with command line parameters or configured in the system. * If only an HTTP proxy was configured then it's properties are copied to the HTTPS proxy (like SonarQube configuration) diff --git a/src/main/java/org/sonar/plugins/github/GlobalReport.java b/src/main/java/org/sonar/plugins/github/GlobalReport.java index 2b6b104..9f7a26f 100644 --- a/src/main/java/org/sonar/plugins/github/GlobalReport.java +++ b/src/main/java/org/sonar/plugins/github/GlobalReport.java @@ -21,6 +21,8 @@ import java.util.Locale; import javax.annotation.Nullable; + +import org.apache.commons.lang.StringUtils; import org.kohsuke.github.GHCommitState; import org.sonar.api.batch.postjob.issue.PostJobIssue; import org.sonar.api.batch.rule.Severity; @@ -30,15 +32,17 @@ public class GlobalReport { private int[] newIssuesBySeverity = new int[Severity.values().length]; private int extraIssueCount = 0; private int maxGlobalReportedIssues; + private String projectKey; private final ReportBuilder builder; - public GlobalReport(MarkDownUtils markDownUtils, boolean tryReportIssuesInline) { - this(markDownUtils, tryReportIssuesInline, GitHubPluginConfiguration.MAX_GLOBAL_ISSUES); + public GlobalReport(MarkDownUtils markDownUtils, boolean tryReportIssuesInline, @Nullable String projectKey) { + this(markDownUtils, tryReportIssuesInline, GitHubPluginConfiguration.MAX_GLOBAL_ISSUES, projectKey); } - public GlobalReport(MarkDownUtils markDownUtils, boolean tryReportIssuesInline, int maxGlobalReportedIssues) { + public GlobalReport(MarkDownUtils markDownUtils, boolean tryReportIssuesInline, int maxGlobalReportedIssues, @Nullable String projectKey) { this.tryReportIssuesInline = tryReportIssuesInline; this.maxGlobalReportedIssues = maxGlobalReportedIssues; + this.projectKey = projectKey; this.builder = new MarkDownReportBuilder(markDownUtils); } @@ -48,13 +52,17 @@ private void increment(Severity severity) { public String formatForMarkdown() { int newIssues = newIssues(Severity.BLOCKER) + newIssues(Severity.CRITICAL) + newIssues(Severity.MAJOR) + newIssues(Severity.MINOR) + newIssues(Severity.INFO); - if (newIssues == 0) { - return "SonarQube analysis reported no issues."; - } boolean hasInlineIssues = newIssues > extraIssueCount; boolean extraIssuesTruncated = extraIssueCount > maxGlobalReportedIssues; + + if (newIssues == 0) { + builder.append("SonarQube analysis reported no issues.").appendProjectId(projectKey); + return builder.toString(); + } + builder.append("SonarQube analysis reported ").append(newIssues).append(" issue").append(newIssues > 1 ? "s" : "").append("\n"); + if (hasInlineIssues || extraIssuesTruncated) { appendSummaryBySeverity(builder); } @@ -66,7 +74,7 @@ public String formatForMarkdown() { appendExtraIssues(builder, hasInlineIssues, extraIssuesTruncated); } - return builder.toString(); + return builder.appendProjectId(projectKey).toString(); } private void appendExtraIssues(ReportBuilder builder, boolean hasInlineIssues, boolean extraIssuesTruncated) { diff --git a/src/main/java/org/sonar/plugins/github/MarkDownReportBuilder.java b/src/main/java/org/sonar/plugins/github/MarkDownReportBuilder.java index c288b57..614760c 100644 --- a/src/main/java/org/sonar/plugins/github/MarkDownReportBuilder.java +++ b/src/main/java/org/sonar/plugins/github/MarkDownReportBuilder.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Set; import java.util.TreeSet; +import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.postjob.issue.PostJobIssue; import org.sonar.api.batch.rule.Severity; @@ -50,6 +51,15 @@ private IssueHolder(PostJobIssue issue, String gitHubUrl) { this.markDownUtils = markDownUtils; } + @Override + public ReportBuilder appendProjectId(String projectId) { + if (!StringUtils.isEmpty(projectId)) { + sb.append(MarkDownUtils.projectId(projectId)); + } + + return this; + } + @Override public ReportBuilder append(Object o) { sb.append(o); diff --git a/src/main/java/org/sonar/plugins/github/MarkDownUtils.java b/src/main/java/org/sonar/plugins/github/MarkDownUtils.java index 7fcca91..11be936 100644 --- a/src/main/java/org/sonar/plugins/github/MarkDownUtils.java +++ b/src/main/java/org/sonar/plugins/github/MarkDownUtils.java @@ -47,6 +47,12 @@ public MarkDownUtils(Settings settings) { this.ruleUrlPrefix = baseUrl; } + public static String projectId(String projectId) { + StringBuilder sb = new StringBuilder(); + sb.append("\n[project-id]: ").append(projectId); + return sb.toString(); + } + public String inlineIssue(Severity severity, String message, String ruleKey) { String ruleLink = getRuleLink(ruleKey); StringBuilder sb = new StringBuilder(); diff --git a/src/main/java/org/sonar/plugins/github/PullRequestFacade.java b/src/main/java/org/sonar/plugins/github/PullRequestFacade.java index 5e5ae9c..18891ee 100644 --- a/src/main/java/org/sonar/plugins/github/PullRequestFacade.java +++ b/src/main/java/org/sonar/plugins/github/PullRequestFacade.java @@ -31,6 +31,8 @@ import java.util.regex.Pattern; import javax.annotation.CheckForNull; import javax.annotation.Nullable; + +import org.apache.commons.lang.StringUtils; import org.kohsuke.github.GHCommitState; import org.kohsuke.github.GHCommitStatus; import org.kohsuke.github.GHIssueComment; @@ -72,6 +74,7 @@ public class PullRequestFacade { public PullRequestFacade(GitHubPluginConfiguration config) { this.config = config; + } public void init(int pullRequestNumber, File projectBaseDir) { @@ -136,8 +139,12 @@ private void loadExistingReviewComments() throws IOException { // Ignore comments from other users continue; } + if (!StringUtils.isEmpty(config.projectKey()) && !comment.getBody().contains(MarkDownUtils.projectId(config.projectKey()))) { + // Ignore comments that don't contain projectId + continue; + } if (!existingReviewCommentsByLocationByFile.containsKey(comment.getPath())) { - existingReviewCommentsByLocationByFile.put(comment.getPath(), new HashMap()); + existingReviewCommentsByLocationByFile.put(comment.getPath(), new HashMap<>()); } // By default all previous comments will be marked for deletion reviewCommentToBeDeletedById.put(comment.getId(), comment); @@ -255,6 +262,10 @@ private boolean findAndDeleteOthers(@Nullable String markup) throws IOException boolean found = false; for (GHIssueComment comment : pr.listComments()) { if (myself.equals(comment.getUser().getLogin())) { + if (!StringUtils.isEmpty(config.projectKey()) && !comment.getBody().contains(MarkDownUtils.projectId(config.projectKey()))) { + // Ignore comments that don't contain projectId + continue; + } if (markup == null || found || !markup.equals(comment.getBody())) { comment.delete(); continue; diff --git a/src/main/java/org/sonar/plugins/github/PullRequestIssuePostJob.java b/src/main/java/org/sonar/plugins/github/PullRequestIssuePostJob.java index ffcc023..f46758e 100644 --- a/src/main/java/org/sonar/plugins/github/PullRequestIssuePostJob.java +++ b/src/main/java/org/sonar/plugins/github/PullRequestIssuePostJob.java @@ -23,7 +23,9 @@ import java.util.HashMap; import java.util.Map; import java.util.stream.StreamSupport; +import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; + import org.kohsuke.github.GHCommitState; import org.sonar.api.batch.fs.InputComponent; import org.sonar.api.batch.fs.InputFile; @@ -61,9 +63,11 @@ public void describe(PostJobDescriptor descriptor) { @Override public void execute(PostJobContext context) { - GlobalReport report = new GlobalReport(markDownUtils, gitHubPluginConfiguration.tryReportIssuesInline()); + String projectKey = gitHubPluginConfiguration.projectKey(); + + GlobalReport report = new GlobalReport(markDownUtils, gitHubPluginConfiguration.tryReportIssuesInline(), projectKey); try { - Map> commentsToBeAddedByLine = processIssues(report, context.issues()); + Map> commentsToBeAddedByLine = processIssues(report, context.issues(), projectKey); updateReviewComments(commentsToBeAddedByLine); @@ -78,7 +82,8 @@ public void execute(PostJobContext context) { } } - private Map> processIssues(GlobalReport report, Iterable issues) { + private Map> processIssues( + GlobalReport report, Iterable issues, @Nullable String projectKey) { Map> commentToBeAddedByFileAndByLine = new HashMap<>(); StreamSupport.stream(issues.spliterator(), false) @@ -91,21 +96,21 @@ private Map> processIssues(GlobalReport r pullRequestFacade.hasFile((InputFile) inputComponent); }) .sorted(ISSUE_COMPARATOR) - .forEach(i -> processIssue(report, commentToBeAddedByFileAndByLine, i)); + .forEach(i -> processIssue(report, commentToBeAddedByFileAndByLine, i, projectKey)); return commentToBeAddedByFileAndByLine; } - private void processIssue(GlobalReport report, Map> commentToBeAddedByFileAndByLine, PostJobIssue issue) { + private void processIssue(GlobalReport report, Map> commentToBeAddedByFileAndByLine, PostJobIssue issue, @Nullable String projectKey) { boolean reportedInline = false; InputComponent inputComponent = issue.inputComponent(); if (gitHubPluginConfiguration.tryReportIssuesInline() && inputComponent != null && inputComponent.isFile()) { - reportedInline = tryReportInline(commentToBeAddedByFileAndByLine, issue, (InputFile) inputComponent); + reportedInline = tryReportInline(commentToBeAddedByFileAndByLine, issue, (InputFile) inputComponent, projectKey); } report.process(issue, pullRequestFacade.getGithubUrl(inputComponent, issue.line()), reportedInline); } - private boolean tryReportInline(Map> commentToBeAddedByFileAndByLine, PostJobIssue issue, InputFile inputFile) { + private boolean tryReportInline(Map> commentToBeAddedByFileAndByLine, PostJobIssue issue, InputFile inputFile, @Nullable String projectKey) { Integer lineOrNull = issue.line(); if (lineOrNull != null) { int line = lineOrNull.intValue(); @@ -113,13 +118,21 @@ private boolean tryReportInline(Map> comm String message = issue.message(); String ruleKey = issue.ruleKey().toString(); if (!commentToBeAddedByFileAndByLine.containsKey(inputFile)) { - commentToBeAddedByFileAndByLine.put(inputFile, new HashMap()); + commentToBeAddedByFileAndByLine.put(inputFile, new HashMap<>()); } Map commentsByLine = commentToBeAddedByFileAndByLine.get(inputFile); + if (!commentsByLine.containsKey(line)) { - commentsByLine.put(line, new StringBuilder()); + StringBuilder stringBuilder = new StringBuilder(); + commentsByLine.put(line, stringBuilder); } + commentsByLine.get(line).append(markDownUtils.inlineIssue(issue.severity(), message, ruleKey)).append("\n"); + + if (!StringUtils.isEmpty(projectKey)) { + commentsByLine.get(line).append(MarkDownUtils.projectId(projectKey)).append("\n"); + } + return true; } } diff --git a/src/main/java/org/sonar/plugins/github/ReportBuilder.java b/src/main/java/org/sonar/plugins/github/ReportBuilder.java index f5cdc15..d2d32fc 100644 --- a/src/main/java/org/sonar/plugins/github/ReportBuilder.java +++ b/src/main/java/org/sonar/plugins/github/ReportBuilder.java @@ -24,6 +24,14 @@ import org.sonar.api.batch.rule.Severity; public interface ReportBuilder { + /** + * Append project id to the report. + * + * @param projectId Project id to append + * @return a reference to this object + */ + ReportBuilder appendProjectId(String projectId); + /** * Append an object to the report, using its toString() method. * diff --git a/src/test/java/org/sonar/plugins/github/GlobalReportTest.java b/src/test/java/org/sonar/plugins/github/GlobalReportTest.java index 007d3cf..b6e94e6 100644 --- a/src/test/java/org/sonar/plugins/github/GlobalReportTest.java +++ b/src/test/java/org/sonar/plugins/github/GlobalReportTest.java @@ -36,7 +36,7 @@ import static org.mockito.Mockito.when; public class GlobalReportTest { - + private static final String PROJECT_KEY = "test.key"; private static final String GITHUB_URL = "https://github.com/SonarSource/sonar-github"; private Settings settings; @@ -70,10 +70,10 @@ private PostJobIssue newMockedIssue(String componentKey, @CheckForNull DefaultIn } @Test - public void noIssues() { - GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), true); + public void noIssuesWithProjectId() { + GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), true, PROJECT_KEY); - String desiredMarkdown = "SonarQube analysis reported no issues."; + String desiredMarkdown = "SonarQube analysis reported no issues.\n[project-id]: test.key"; String formattedGlobalReport = globalReport.formatForMarkdown(); @@ -81,14 +81,15 @@ public void noIssues() { } @Test - public void oneIssue() { - GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), true); + public void oneIssueWithProjectId() { + GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), true, PROJECT_KEY); globalReport.process(newMockedIssue("component", null, null, Severity.INFO, true, "Issue", "rule"), GITHUB_URL, true); String desiredMarkdown = "SonarQube analysis reported 1 issue\n" + - "* ![INFO][INFO] 1 info\n" + - "\nWatch the comments in this conversation to review them.\n" + - "\n[INFO]: https://sonarsource.github.io/sonar-github/severity-info.png 'Severity: INFO'"; + "* ![INFO][INFO] 1 info\n" + + "\nWatch the comments in this conversation to review them.\n" + + "\n[project-id]: test.key" + + "\n[INFO]: https://sonarsource.github.io/sonar-github/severity-info.png 'Severity: INFO'"; String formattedGlobalReport = globalReport.formatForMarkdown(); @@ -97,13 +98,14 @@ public void oneIssue() { @Test public void oneIssueOnDir() { - GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), true); + GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), true, PROJECT_KEY); globalReport.process(newMockedIssue("component0", null, null, Severity.INFO, true, "Issue0", "rule0"), null, false); String desiredMarkdown = "SonarQube analysis reported 1 issue\n\n" + "Note: The following issues were found on lines that were not modified in the pull request. Because these issues can't be reported as line comments, they are summarized here:\n\n" + "1. ![INFO][INFO] component0: Issue0 [![rule](https://sonarsource.github.io/sonar-github/rule.png)](http://myserver/coding_rules#rule_key=repo%3Arule0)\n" + + "\n[project-id]: test.key" + "\n[INFO]: https://sonarsource.github.io/sonar-github/severity-info.png 'Severity: INFO'"; String formattedGlobalReport = globalReport.formatForMarkdown(); @@ -113,7 +115,7 @@ public void oneIssueOnDir() { @Test public void shouldFormatIssuesForMarkdownNoInline() { - GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), true); + GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), true, PROJECT_KEY); globalReport.process(newMockedIssue("component", null, null, Severity.INFO, true, "Issue", "rule"), GITHUB_URL, true); globalReport.process(newMockedIssue("component", null, null, Severity.MINOR, true, "Issue", "rule"), GITHUB_URL, true); globalReport.process(newMockedIssue("component", null, null, Severity.MAJOR, true, "Issue", "rule"), GITHUB_URL, true); @@ -128,6 +130,7 @@ public void shouldFormatIssuesForMarkdownNoInline() { "* ![INFO][INFO] 1 info\n" + "\nWatch the comments in this conversation to review them.\n" + "\n" + + "[project-id]: test.key\n" + "[BLOCKER]: https://sonarsource.github.io/sonar-github/severity-blocker.png 'Severity: BLOCKER'\n" + "[CRITICAL]: https://sonarsource.github.io/sonar-github/severity-critical.png 'Severity: CRITICAL'\n" + "[INFO]: https://sonarsource.github.io/sonar-github/severity-info.png 'Severity: INFO'\n" @@ -141,7 +144,7 @@ public void shouldFormatIssuesForMarkdownNoInline() { @Test public void shouldFormatIssuesForMarkdownMixInlineGlobal() { - GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), true); + GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), true, PROJECT_KEY); globalReport.process(newMockedIssue("component", null, null, Severity.INFO, true, "Issue 0", "rule0"), GITHUB_URL, true); globalReport.process(newMockedIssue("component", null, null, Severity.MINOR, true, "Issue 1", "rule1"), GITHUB_URL, false); globalReport.process(newMockedIssue("component", null, null, Severity.MAJOR, true, "Issue 2", "rule2"), GITHUB_URL, true); @@ -162,6 +165,7 @@ public void shouldFormatIssuesForMarkdownMixInlineGlobal() { + "1. ![CRITICAL][CRITICAL] [sonar-github](https://github.com/SonarSource/sonar-github): Issue 3 [![rule](https://sonarsource.github.io/sonar-github/rule.png)](http://myserver/coding_rules#rule_key=repo%3Arule3)\n" + "\n" + + "[project-id]: test.key\n" + "[BLOCKER]: https://sonarsource.github.io/sonar-github/severity-blocker.png 'Severity: BLOCKER'\n" + "[CRITICAL]: https://sonarsource.github.io/sonar-github/severity-critical.png 'Severity: CRITICAL'\n" + "[INFO]: https://sonarsource.github.io/sonar-github/severity-info.png 'Severity: INFO'\n" @@ -175,7 +179,7 @@ public void shouldFormatIssuesForMarkdownMixInlineGlobal() { @Test public void shouldFormatIssuesForMarkdownWhenInlineCommentsDisabled() { - GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), false); + GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), false, PROJECT_KEY); globalReport.process(newMockedIssue("component", null, null, Severity.INFO, true, "Issue 0", "rule0"), GITHUB_URL, false); globalReport.process(newMockedIssue("component", null, null, Severity.MINOR, true, "Issue 1", "rule1"), GITHUB_URL, false); globalReport.process(newMockedIssue("component", null, null, Severity.MAJOR, true, "Issue 2", "rule2"), GITHUB_URL, false); @@ -193,6 +197,7 @@ public void shouldFormatIssuesForMarkdownWhenInlineCommentsDisabled() { + "1. ![BLOCKER][BLOCKER] [sonar-github](https://github.com/SonarSource/sonar-github): Issue 4 [![rule](https://sonarsource.github.io/sonar-github/rule.png)](http://myserver/coding_rules#rule_key=repo%3Arule4)\n" + "\n" + + "[project-id]: test.key\n" + "[BLOCKER]: https://sonarsource.github.io/sonar-github/severity-blocker.png 'Severity: BLOCKER'\n" + "[CRITICAL]: https://sonarsource.github.io/sonar-github/severity-critical.png 'Severity: CRITICAL'\n" + "[INFO]: https://sonarsource.github.io/sonar-github/severity-info.png 'Severity: INFO'\n" @@ -206,7 +211,7 @@ public void shouldFormatIssuesForMarkdownWhenInlineCommentsDisabled() { @Test public void shouldFormatIssuesForMarkdownWhenInlineCommentsDisabledAndLimitReached() { - GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), false, 4); + GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), false, 4, PROJECT_KEY); globalReport.process(newMockedIssue("component", null, null, Severity.INFO, true, "Issue 0", "rule0"), GITHUB_URL, false); globalReport.process(newMockedIssue("component", null, null, Severity.MINOR, true, "Issue 1", "rule1"), GITHUB_URL, false); globalReport.process(newMockedIssue("component", null, null, Severity.MAJOR, true, "Issue 2", "rule2"), GITHUB_URL, false); @@ -228,6 +233,7 @@ public void shouldFormatIssuesForMarkdownWhenInlineCommentsDisabledAndLimitReach + "1. ![CRITICAL][CRITICAL] [sonar-github](https://github.com/SonarSource/sonar-github): Issue 3 [![rule](https://sonarsource.github.io/sonar-github/rule.png)](http://myserver/coding_rules#rule_key=repo%3Arule3)\n" + "\n" + + "[project-id]: test.key\n" + "[BLOCKER]: https://sonarsource.github.io/sonar-github/severity-blocker.png 'Severity: BLOCKER'\n" + "[CRITICAL]: https://sonarsource.github.io/sonar-github/severity-critical.png 'Severity: CRITICAL'\n" + "[INFO]: https://sonarsource.github.io/sonar-github/severity-info.png 'Severity: INFO'\n" @@ -241,7 +247,7 @@ public void shouldFormatIssuesForMarkdownWhenInlineCommentsDisabledAndLimitReach @Test public void shouldLimitGlobalIssues() { - GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), true); + GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), true, PROJECT_KEY); for (int i = 0; i < 17; i++) { globalReport.process(newMockedIssue("component", null, null, Severity.MAJOR, true, "Issue number:" + i, "rule" + i), GITHUB_URL + "/File.java#L" + i, false); } @@ -271,6 +277,7 @@ public void shouldLimitGlobalIssues() { + "1. ![MAJOR][MAJOR] [File.java#L9](https://github.com/SonarSource/sonar-github/File.java#L9): Issue number:9 [![rule](https://sonarsource.github.io/sonar-github/rule.png)](http://myserver/coding_rules#rule_key=repo%3Arule9)\n" + "\n" + + "[project-id]: test.key\n" + "[MAJOR]: https://sonarsource.github.io/sonar-github/severity-major.png 'Severity: MAJOR'"; String formattedGlobalReport = globalReport.formatForMarkdown(); @@ -280,7 +287,7 @@ public void shouldLimitGlobalIssues() { @Test public void shouldLimitGlobalIssuesWhenInlineCommentsDisabled() { - GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), false); + GlobalReport globalReport = new GlobalReport(new MarkDownUtils(settings), false, PROJECT_KEY); for (int i = 0; i < 17; i++) { globalReport.process(newMockedIssue("component", null, null, Severity.MAJOR, true, "Issue number:" + i, "rule" + i), GITHUB_URL + "/File.java#L" + i, false); } @@ -308,6 +315,7 @@ public void shouldLimitGlobalIssuesWhenInlineCommentsDisabled() { + "1. ![MAJOR][MAJOR] [File.java#L9](https://github.com/SonarSource/sonar-github/File.java#L9): Issue number:9 [![rule](https://sonarsource.github.io/sonar-github/rule.png)](http://myserver/coding_rules#rule_key=repo%3Arule9)\n" + "\n" + + "[project-id]: test.key\n" + "[MAJOR]: https://sonarsource.github.io/sonar-github/severity-major.png 'Severity: MAJOR'"; String formattedGlobalReport = globalReport.formatForMarkdown(); diff --git a/src/test/java/org/sonar/plugins/github/PullRequestIssuePostJobTest.java b/src/test/java/org/sonar/plugins/github/PullRequestIssuePostJobTest.java index c9278f8..b40dfb4 100644 --- a/src/test/java/org/sonar/plugins/github/PullRequestIssuePostJobTest.java +++ b/src/test/java/org/sonar/plugins/github/PullRequestIssuePostJobTest.java @@ -56,17 +56,25 @@ public class PullRequestIssuePostJobTest { @Before public void prepare() throws Exception { pullRequestFacade = mock(PullRequestFacade.class); - Settings settings = new Settings(new PropertyDefinitions(PropertyDefinition.builder(CoreProperties.SERVER_BASE_URL) - .name("Server base URL") - .description("HTTP URL of this SonarQube server, such as http://yourhost.yourdomain/sonar. This value is used i.e. to create links in emails.") - .category(CoreProperties.CATEGORY_GENERAL) - .defaultValue(CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE) - .build())); + Settings settings = new Settings(new PropertyDefinitions( + PropertyDefinition.builder(CoreProperties.SERVER_BASE_URL) + .name("Server base URL") + .description("HTTP URL of this SonarQube server, such as http://yourhost.yourdomain/sonar. This value is used i.e. to create links in emails.") + .category(CoreProperties.CATEGORY_GENERAL) + .defaultValue(CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE) + .build(), + PropertyDefinition.builder(CoreProperties.PROJECT_KEY_PROPERTY) + .name("Project Id") + .description("Project Id") + .category(CoreProperties.CATEGORY_GENERAL) + .defaultValue("") + .build())); GitHubPluginConfiguration config = new GitHubPluginConfiguration(settings, new System2()); context = mock(PostJobContext.class); settings.setProperty("sonar.host.url", "http://192.168.0.1"); settings.setProperty(CoreProperties.SERVER_BASE_URL, "http://myserver"); + settings.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "project-id"); pullRequestIssuePostJob = new PullRequestIssuePostJob(config, pullRequestFacade, new MarkDownUtils(settings)); }