Listen for Git push events from IntelliJ plugin

已回答

I'm currently working on an IntelliJ plugin that, among many others, should have a feature for creating PRs after a successful push. For this, I have to react to the push event and take appropriate action. So far, I was only able to find out how to listen to commits using a CheckInHandler - is there something similar for pushes that would allow me to implement what I'm trying to do?

评论操作 固定链接
正式评论

Please try GitPushProcessCustomization#executeAfterPush(). You'll have to check the push results, whether they are successful or not.

评论操作 固定链接

Thanks a lot. Just to be sure my code doesn't break any other possible Git integrations, is this the correct way to only use GitPushProcessCustomization#executeAfterPush() without re-implementing all the other methods in the interface?

public class CustomGitPushProcessCustomizationFactory implements GitPushProcessCustomizationFactory {

@Nullable
@Override
public GitPushProcessCustomization createCustomization(@NotNull Project project, @NotNull Map<GitRepository, PushSpec<GitPushSource, GitPushTarget>> map, boolean b) {
return new CustomGitPushProcessCustomization();
}
}
public class CustomGitPushProcessCustomization implements GitPushProcessCustomizationFactory.GitPushProcessCustomization {

@NotNull
@Override
public Map<GitRepository, GitPushRepoResult> executeAfterPushIteration(@NotNull Map<GitRepository, GitPushRepoResult> map) {
return map;
}


@NotNull
@Override
public GitCommandResult runPushCommand(@NotNull GitRepository gitRepository, @NotNull PushSpec<GitPushSource, GitPushTarget> pushSpec, @NotNull GitPushParams gitPushParams, @NotNull GitLineHandlerListener gitLineHandlerListener) {
return Git.getInstance().push(gitRepository, gitPushParams, gitLineHandlerListener);
}


@Override
public void executeAfterPush(@NotNull Map<GitRepository, GitPushRepoResult> map) {
// My custom behavior
}
}
0
评论操作 固定链接

Ah, you're right: it is not that straightforward there. If a customization is defined, it is in some cases executed instead of the base code. See the GitPushOperation class. So you might need to provide some duplication of the base code inside of yours for runPushCommand (your implementation above is correct) and for executeAfterPushIteration() as well (although if you're going to support only single-repository projects, this should work as is).

Moreover, the code assumes that there is no more than one customization, otherwise they are all disabled. However, I'm not aware of any available implementations of it, apart from one our plugin that we use internally.

That said, it should work, but you should be aware of potential issues, until we provide an API to notify about the push result.

1
评论操作 固定链接

Great, thanks! This question can be marked as solved then.

0

请先登录再写评论。