bitbucket api PostRepositoryHook не вызывается при объединении запроса на включение - PullRequest
0 голосов
/ 04 мая 2018

Я использую PostRepositoryHook для разработки плагина для прослушивания всех толчков, сделанных разработчиком. Во время тестирования я понял, что он работает, когда я тестирую его с помощью командной строки для запуска команды git push. Однако это не работает, когда я занимаюсь пиаром и объединяю свой пиар.

Ниже приведены данные кода.

// 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 голосов
/ 01 июня 2018

Прочитав больше о bitbucket api, я понял, что @SynchronousPreferred(asyncSupported = false) не нужен, как только я удалил его, теперь RepositoryHookRequest работает для всех трех категорий

  1. Подтолкнуть к репо
  2. Онлайн редактирование
  3. PR объединены >> Это триггер два, один для PR объединить и второй для нажатия на целевой репозиторий

Ниже приведен код для справки.

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);
    }
}
...