package cn.reghao.devops.mgr.app.service.webhook.event;

import cn.reghao.jutil.web.ServletUtil;
import com.google.gson.JsonObject;
import org.springframework.stereotype.Component;

/**
 * @author reghao
 * @date 2022-05-13 13:12:05
 */
@Component
public class GogsPushEvent implements PushEvent {
    @Override
    public BuildParam handle(JsonObject jsonObject) {
        String signature = ServletUtil.getHeader("X-Gogs-Signature");

        JsonObject repoObject = jsonObject.get("repository").getAsJsonObject();
        String repo = repoObject.get("clone_url").getAsString();
        String branch = jsonObject.get("ref").getAsString().replace("refs/heads/", "");
        String buildBy = this.getClass().getSimpleName();
        return new BuildParam(repo, branch, buildBy);
    }
}
