bitbucket api PostRepositoryHook不会在pull请求合并

时间:2018-05-04 00:25:11

标签: bitbucket bitbucket-server bitbucket-api

我正在使用PostRepositoryHook开发插件来监听开发人员所做的所有推送。在测试期间,我意识到当我使用命令行测试它以运行git push命令时它确实有效。但是,当我做PR并合并我的公关时,它不起作用。

以下是代码详情。

// LoggingPostRepositoryHook.java

import com.atlassian.bitbucket.hook.repository.PostRepositoryHook;
import com.atlassian.bitbucket.hook.repository.PostRepositoryHookContext;
import com.atlassian.bitbucket.hook.repository.RepositoryHookRequest;
import com.atlassian.bitbucket.hook.repository.SynchronousPreferred;


import javax.annotation.Nonnull;

/**
 * Example hook that logs what changes have been made to a set of refs
 */
@SynchronousPreferred(asyncSupported = false)
public class LoggingPostRepositoryHook implements PostRepositoryHook<RepositoryHookRequest> {

    @Override
    public void postUpdate(@Nonnull PostRepositoryHookContext context,
                           @Nonnull RepositoryHookRequest hookRequest) {

        String message = hookRequest.getRepository().getProject()+" "+ hookRequest.getRepository().getName();
        PostMessage postMessage = new PostMessage();
        postMessage.send(message);
        hookRequest.getScmHookDetails().ifPresent(scmDetails -> {
            hookRequest.getRefChanges().forEach(refChange -> {
                scmDetails.out().println("Thank you for pusing code! "+ message);
            });
        });


    }
}

// atlassian-plugin.xml
<repository-hook key="logging-hook" name="Logging Post Hook"
                   i18n-name-key="hook.guide.logginghook.name"
                   configurable="false"
                   class="com.myapp.impl.LoggingPostRepositoryHook">
    <description key="hook.guide.logginghook.description" />
  </repository-hook>


// PostMessage.java
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;

public class PostMessage {
    public void send(String message) {

        HttpClient httpClient = HttpClientBuilder.create().build(); //Use this instead

        try {

            HttpPost request = new HttpPost("http://localhost:3008/git-hooks");
            StringEntity params =new StringEntity("details={\"message\":\""+message+"\"} ");
            request.addHeader("content-type", "application/x-www-form-urlencoded");
            request.setEntity(params);
            HttpResponse response = httpClient.execute(request);

            //handle response here...

        }catch (Exception ex) {

            //handle exception here
            System.out.println(ex);

        }
    }
}

请帮忙。

1 个答案:

答案 0 :(得分:0)

在阅读了有关bitbucket api的更多信息之后,我意识到import com.atlassian.bitbucket.hook.repository.PostRepositoryHook; import com.atlassian.bitbucket.hook.repository.PostRepositoryHookContext; import com.atlassian.bitbucket.hook.repository.RepositoryHookRequest; import javax.annotation.Nonnull; public class PostCommitGlobalHook implements PostRepositoryHook<RepositoryHookRequest> { @Override public void postUpdate(@Nonnull PostRepositoryHookContext context, @Nonnull RepositoryHookRequest hookRequest) { // Pass request to handler PostHookHandler handler = new PostHookHandler(); handler.handleRequest(hookRequest); } } 是不必要的,一旦我删除它,现在HTTPSConnectionPool(host='api.fixer.io', port=443): Max retries exceeded with url: /latest?base=INR (Caused by SSLError(SSLError(1, '_ssl.c:510: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure'))) 适用于所有三个类别

  1. 推送回购
  2. 在线编辑
  3. PR合并&gt;&gt;这触发两个,一个用于PR 合并和第二次推送目标存储库
  4. 以下是供参考的代码。

    response=requests.get("https://api.fixer.io/latest?base="+cfrm)
    
相关问题