-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BitConDec-11: Enable unit testing with Jacoco (#4)
* Add interface for ApplicationLinkService class to make its responsibility clearer * Get CommitService via ComponentLocator instead of injecting it for better testability * Add interface for MergeCheckHandler and rename merge check classes, separate MergChecking bean from completeness checking logic * Add Jacoco maven plugin to generate coverage reports and send them to Codecov GitHub plugin in .travis.yml * Test completion checking in JSON String * Refactor and test method to retrieve project key from text * Add mock package and class for a pull request * Add test for getCommitsOfPullRequest method
- Loading branch information
Showing
16 changed files
with
674 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...va/de/uhd/ifi/se/decision/management/bitbucket/merge/checks/CompletenessCheckHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package de.uhd.ifi.se.decision.management.bitbucket.merge.checks; | ||
|
||
import java.util.Locale; | ||
import java.util.Set; | ||
|
||
/** | ||
* Interface to check the completeness of the documentation of decision | ||
* knowledge related to a pull request. | ||
*/ | ||
public interface CompletenessCheckHandler { | ||
|
||
/** | ||
* Checks whether the documentation is complete. | ||
* | ||
* @return true if the documentation is complete. | ||
*/ | ||
boolean isDocumentationComplete(); | ||
|
||
/** | ||
* Returns a set of Jira issues with an incomplete documentation. | ||
* | ||
* @return set of Jira issue keys. | ||
*/ | ||
Set<String> getJiraIssuesWithIncompleteDocumentation(); | ||
|
||
/** | ||
* Looks for the first Jira issue key (e.g. CONDEC-1) in a String and returns the | ||
* Jira project key (e.g. CONDEC). | ||
* | ||
* @param text | ||
* that might contain a project key, e.g., a commit message, branch | ||
* name oder pull request title. | ||
* @return potential project key in upper case. | ||
*/ | ||
static String retrieveProjectKey(String text) { | ||
if (text.indexOf("-") == -1) { | ||
// there is no Jira issue key (e.g. CONDEC-1) in the text | ||
return ""; | ||
} | ||
String splitted = text.split("-")[0]; | ||
String[] words = splitted.split(" "); | ||
String projectKey = words[words.length - 1]; | ||
return projectKey.toUpperCase(Locale.ENGLISH); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...java/de/uhd/ifi/se/decision/management/bitbucket/merge/checks/CompletenessMergeCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package de.uhd.ifi.se.decision.management.bitbucket.merge.checks; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import com.atlassian.bitbucket.hook.repository.PreRepositoryHookContext; | ||
import com.atlassian.bitbucket.hook.repository.PullRequestMergeHookRequest; | ||
import com.atlassian.bitbucket.hook.repository.RepositoryHookResult; | ||
import com.atlassian.bitbucket.hook.repository.RepositoryMergeCheck; | ||
import com.atlassian.bitbucket.pull.PullRequest; | ||
|
||
import de.uhd.ifi.se.decision.management.bitbucket.merge.checks.impl.CompletenessCheckHandlerImpl; | ||
|
||
/** | ||
* Enforces that pull requests can only be accepted, i.e., the respective branch | ||
* can only be merged back to the maineline if the decision knowledge | ||
* documentation is complete. The completeness is determined in the | ||
* {@link CompletenessCheckHandler}. | ||
* | ||
*/ | ||
@Component("completenessMergeCheck") | ||
public class CompletenessMergeCheck implements RepositoryMergeCheck { | ||
|
||
@Nonnull | ||
@Override | ||
public RepositoryHookResult preUpdate(@Nonnull PreRepositoryHookContext context, | ||
@Nonnull PullRequestMergeHookRequest request) { | ||
PullRequest pullRequest = request.getPullRequest(); | ||
|
||
CompletenessCheckHandler completenessCheckHandler = new CompletenessCheckHandlerImpl(pullRequest); | ||
if (completenessCheckHandler.isDocumentationComplete()) { | ||
return RepositoryHookResult.accepted(); | ||
} | ||
String summaryMessage = "There are not enough decision knowledge elements linked to the pull request."; | ||
String detailMessage = "Every Jira ticket has to have at least one decision problem (=issue) and one decision linked. " | ||
+ "Jira tickets with an incomplete documentation are: "; | ||
for (String jiraIssueKey : completenessCheckHandler.getJiraIssuesWithIncompleteDocumentation()) { | ||
detailMessage += jiraIssueKey + " "; | ||
} | ||
|
||
// TODO | ||
// @issue Should the developers be allowed to merge the branch with an | ||
// incomplete decision knowledge documentation? | ||
// @decision It should be configurable on a setting page whether the incomplete | ||
// documentation enforces that the branch cannot be merged or not. | ||
return RepositoryHookResult.rejected(summaryMessage, detailMessage); | ||
} | ||
} |
75 changes: 0 additions & 75 deletions
75
...a/de/uhd/ifi/se/decision/management/bitbucket/merge/checks/HasDecisionKnowledgeCheck.java
This file was deleted.
Oops, something went wrong.
146 changes: 0 additions & 146 deletions
146
.../java/de/uhd/ifi/se/decision/management/bitbucket/merge/checks/MergeCheckDataHandler.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.