blob: d559bc3b6d04471ddb2e857f22bc9c80ef779fc8 [file] [log] [blame]
// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.googlesource.gerrit.plugins.hooks.workflow;
import com.google.gerrit.common.EventListener;
import com.google.gerrit.server.events.ChangeAbandonedEvent;
import com.google.gerrit.server.events.ChangeMergedEvent;
import com.google.gerrit.server.events.ChangeRestoredEvent;
import com.google.gerrit.server.events.CommentAddedEvent;
import com.google.gerrit.server.events.Event;
import com.google.gerrit.server.events.PatchSetCreatedEvent;
import com.google.gerrit.server.events.RefUpdatedEvent;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import com.googlesource.gerrit.plugins.hooks.its.ItsConfig;
import com.googlesource.gerrit.plugins.hooks.util.CommitMessageFetcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
public class GerritHookFilter implements EventListener {
private static final Logger log = LoggerFactory.getLogger(GerritHookFilter.class);
@Inject
private CommitMessageFetcher commitMessageFetcher;
@Inject
private ItsConfig itsConfig;
public String getComment(String projectName, String commitId)
throws IOException {
return commitMessageFetcher.fetch(projectName, commitId);
}
/**
* Filter patch set created event.
* @param hook
* @throws IOException
* @throws OrmException
*/
public void doFilter(PatchSetCreatedEvent hook) throws IOException,
OrmException {
}
/**
* Filter comment added event.
* @param hook
* @throws IOException
*/
public void doFilter(CommentAddedEvent hook) throws IOException {
}
/**
* Filter change merged event.
* @param hook
* @throws IOException
*/
public void doFilter(ChangeMergedEvent hook) throws IOException {
}
/**
* Filter change abandoned event.
* @param changeAbandonedHook
* @throws IOException
*/
public void doFilter(ChangeAbandonedEvent changeAbandonedHook)
throws IOException {
}
/**
* Filter change restored event.
* @param changeRestoredHook
* @throws IOException
*/
public void doFilter(ChangeRestoredEvent changeRestoredHook)
throws IOException {
}
/**
* Filter ref updated event.
* @param refUpdatedHook
* @throws IOException
*/
public void doFilter(RefUpdatedEvent refUpdatedHook) throws IOException {
}
@Override
public void onEvent(Event event) {
if (!itsConfig.isEnabled(event)) {
return;
}
try {
if (event instanceof PatchSetCreatedEvent) {
doFilter((PatchSetCreatedEvent) event);
} else if (event instanceof CommentAddedEvent) {
doFilter((CommentAddedEvent) event);
} else if (event instanceof ChangeMergedEvent) {
doFilter((ChangeMergedEvent) event);
} else if (event instanceof ChangeAbandonedEvent) {
doFilter((ChangeAbandonedEvent) event);
} else if (event instanceof ChangeRestoredEvent) {
doFilter((ChangeRestoredEvent) event);
} else if (event instanceof RefUpdatedEvent) {
doFilter((RefUpdatedEvent) event);
} else {
log.debug("Event " + event + " not recognised and ignored");
}
} catch (Throwable e) {
log.error("Event " + event + " processing failed", e);
}
}
public String getUrl(PatchSetCreatedEvent hook) {
return null;
}
}