diff --git a/build.gradle b/build.gradle index 96d150c..6ab645f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,10 @@ plugins { id 'java' - id 'org.jetbrains.intellij' version '0.6.5' + id 'org.jetbrains.intellij' version '1.9.0' } group 'ch.repnik' -version '1.1.2' +version '1.2.0' repositories { mavenCentral() @@ -12,13 +12,14 @@ repositories { dependencies { testImplementation 'org.hamcrest:hamcrest:2.2' - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.2' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0' + testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.9.0' } java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } test { @@ -30,16 +31,17 @@ test { // See https://github.com/JetBrains/gradle-intellij-plugin/ intellij { - version '2021.2' + version.set('2022.2.2') plugins = ['git4idea'] } runPluginVerifier{ - ideVersions = ["IC-2021.2"] + ideVersions = ["IC-2022.2.2"] } patchPluginXml { - untilBuild null + sinceBuild.set("222") + untilBuild.set(null) } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a4b4429..ae04661 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/ch/repnik/intellij/CommitPrefixCheckinHandler.java b/src/main/java/ch/repnik/intellij/CommitPrefixCheckinHandler.java index c86deae..a47233e 100644 --- a/src/main/java/ch/repnik/intellij/CommitPrefixCheckinHandler.java +++ b/src/main/java/ch/repnik/intellij/CommitPrefixCheckinHandler.java @@ -1,6 +1,7 @@ package ch.repnik.intellij; import ch.repnik.intellij.settings.PluginSettings; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.vcs.BranchChangeListener; @@ -15,6 +16,7 @@ import git4idea.GitLocalBranch; import git4idea.branch.GitBranchUtil; import git4idea.repo.GitRepository; +import git4idea.status.GitRefreshListener; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -22,38 +24,37 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public class CommitPrefixCheckinHandler extends CheckinHandler implements BranchChangeListener { +public class CommitPrefixCheckinHandler extends CheckinHandler implements BranchChangeListener, GitRefreshListener { private final Logger log = Logger.getInstance(getClass()); - private CheckinProjectPanel panel; + private final CheckinProjectPanel panel; private static final Pattern branchNamePattern = Pattern.compile("(?<=\\/)*([A-Z0-9]+-[0-9]+)"); private static final Pattern prefixPattern = Pattern.compile("[A-Z0-9]+-[0-9]+"); - - private String newCommitMessage; - - public CommitPrefixCheckinHandler(CheckinProjectPanel panel) { this.panel = panel; MessageBusConnection connect = panel.getProject().getMessageBus().connect(); connect.subscribe(BranchChangeListener.VCS_BRANCH_CHANGED, this); + connect.subscribe(GitRefreshListener.TOPIC, this); //Sets the new message on the new commit UI updateCommitMessage(); } private void updateCommitMessage(){ - PsiDocumentManager psiInstance = PsiDocumentManager.getInstance(this.panel.getProject()); - if (psiInstance instanceof PsiDocumentManagerImpl){ - if (!((PsiDocumentManagerImpl) psiInstance).isCommitInProgress()){ - panel.setCommitMessage(getNewCommitMessage()); + ApplicationManager.getApplication().invokeLater(() -> { + PsiDocumentManager psiInstance = PsiDocumentManager.getInstance(this.panel.getProject()); + if (psiInstance instanceof PsiDocumentManagerImpl){ + if (!((PsiDocumentManagerImpl) psiInstance).isCommitInProgress()){ + panel.setCommitMessage(getNewCommitMessage()); + }else{ + log.info("PsiDocumentManager reported commit in progress. Skipping Git Auto Prefix"); + } }else{ - log.info("PsiDocumentManager reported commit in progress. Skipping Git Auto Prefix"); + log.info("PsiDocumentManager is not an instance of PsiDocumentManagerImpl. Skipping Git Auto Prefix"); } - }else{ - log.info("PsiDocumentManager is not an instance of PsiDocumentManagerImpl. Skipping Git Auto Prefix"); - } + }); } @Nullable @@ -71,9 +72,8 @@ private String getNewCommitMessage(){ Optional jiraTicketName = getJiraTicketName(branchName); if (jiraTicketName.isPresent()){ - String newMessage = updatePrefix(jiraTicketName.get(), panel.getCommitMessage(), getWrapLeft(), getWrapRight()); //Sets the value for the new Panel UI - return newMessage; + return updatePrefix(jiraTicketName.get(), panel.getCommitMessage(), getWrapLeft(), getWrapRight()); } return panel.getCommitMessage(); @@ -177,4 +177,10 @@ public void branchWillChange(@NotNull String branchName) { public void branchHasChanged(@NotNull String branchName) { updateCommitMessage(); } + + //Detects repository updates made in the terminal + @Override + public void repositoryUpdated(@NotNull GitRepository repository) { + updateCommitMessage(); + } } diff --git a/src/main/java/ch/repnik/intellij/GitBaseCheckinHandlerFactory.java b/src/main/java/ch/repnik/intellij/GitBaseCheckinHandlerFactory.java index 28d1a83..88a68a3 100644 --- a/src/main/java/ch/repnik/intellij/GitBaseCheckinHandlerFactory.java +++ b/src/main/java/ch/repnik/intellij/GitBaseCheckinHandlerFactory.java @@ -1,6 +1,7 @@ package ch.repnik.intellij; import com.intellij.openapi.vcs.CheckinProjectPanel; +import com.intellij.openapi.vcs.changes.CommitContext; import com.intellij.openapi.vcs.checkin.CheckinHandler; import com.intellij.openapi.vcs.checkin.VcsCheckinHandlerFactory; import git4idea.GitVcs; @@ -14,7 +15,7 @@ public GitBaseCheckinHandlerFactory(){ @NotNull @Override - protected CheckinHandler createVcsHandler(CheckinProjectPanel panel) { + protected CheckinHandler createVcsHandler(@NotNull CheckinProjectPanel panel, @NotNull CommitContext commitContext) { return new CommitPrefixCheckinHandler(panel); } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 3303add..a1fd893 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -1,10 +1,17 @@ commit-prefix-plugin Git Auto Prefix - 1.1.2 + 1.2.0 Thomas Repnik - Fixes an occasional exception on branch switch + +
    +
  • The Plugin now recognizes branch switches made on the CLI/Terminal
  • +
  • Update to Java 17
  • +
+

+ ]]>
@@ -13,6 +20,8 @@
  • Choose your own delimiter between the issue key and commit message
  • Wrap the issue key if necessary
  • +
    + Important:This plugin only works on branches created by Jira (or manually, with exactly the same naming as jira would use)

    @@ -21,6 +30,11 @@ + + + + + @@ -66,7 +80,7 @@ - + diff --git a/src/test/java/ch/repnik/intellij/CommitPrefixCheckinHandlerTest.java b/src/test/java/ch/repnik/intellij/CommitPrefixCheckinHandlerTest.java index 33b6c7b..a1d7000 100644 --- a/src/test/java/ch/repnik/intellij/CommitPrefixCheckinHandlerTest.java +++ b/src/test/java/ch/repnik/intellij/CommitPrefixCheckinHandlerTest.java @@ -146,6 +146,14 @@ public void getJiraTicketName_withoutBranchType_retunsJiraTicket() { assertThat(result.get(), is("ABC-1234")); } + @Test + public void getJiraTicketName_reproduce() { + Optional result = CommitPrefixCheckinHandler.getJiraTicketName("feature/DATA-4214-ab-CEP3.0-Transition-polling"); + + assertThat(result.isPresent(), is(true)); + assertThat(result.get(), is("DATA-4214")); + } + @Test public void getJiraTicketName_featureBranchType_retunsJiraTicket() { Optional result = CommitPrefixCheckinHandler.getJiraTicketName("feature/ABC-1234-app-not-working"); @@ -188,4 +196,4 @@ public void getJiraTicketName_emptySuffix_retunsJiraTicket() { assertThat(result.get(), is("ABC-1234")); } -} \ No newline at end of file +}
    Commit prefix (with delimiter) Commit prefix (wrapped)
    mainno actionno action
    master no action