package cn.reghao.bnt.web.devops.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 GithubPushEvent implements PushEvent {
    @Override
    public BuildParam handle(JsonObject jsonObject) {
        String signature = ServletUtil.getHeader("X-Hub-Signature-256");

        JsonObject repoObject = jsonObject.get("repository").getAsJsonObject();
        String repo = repoObject.get("git_url").getAsString();
        String branch = repoObject.get("default_branch").getAsString();
        String buildBy = this.getClass().getSimpleName();
        return new BuildParam(repo, branch, buildBy);
    }
}
