Search in sources :

Example 1 with GithubRepoInfo

use of com.walmartlabs.concord.server.events.github.GithubRepoInfo in project concord by walmartlabs.

the class GithubTriggerEnricher method enrichTriggerConditions.

private Map<String, Object> enrichTriggerConditions(DSLContext tx, UUID repoId, Map<String, Object> conditions) {
    if (conditions.containsKey(GITHUB_ORG_KEY) && conditions.containsKey(GITHUB_REPO_KEY) && conditions.containsKey(REPO_BRANCH_KEY)) {
        return conditions;
    }
    RepositoryEntry repo = repositoryDao.get(tx, repoId);
    GithubRepoInfo githubRepoInfo = GithubUtils.getRepositoryInfo(repo.getUrl());
    if (githubRepoInfo == null) {
        return conditions;
    }
    Map<String, Object> newParams = new HashMap<>(conditions);
    newParams.putIfAbsent(GITHUB_ORG_KEY, githubRepoInfo.owner());
    newParams.putIfAbsent(GITHUB_REPO_KEY, githubRepoInfo.name());
    Object eventType = conditions.get(TYPE_KEY);
    if ((PULL_REQUEST_EVENT.equals(eventType) || PUSH_EVENT.equals(eventType)) && (repo.getBranch() != null)) {
        newParams.putIfAbsent(REPO_BRANCH_KEY, repo.getBranch());
    }
    return newParams;
}
Also used : HashMap(java.util.HashMap) RepositoryEntry(com.walmartlabs.concord.server.org.project.RepositoryEntry) GithubRepoInfo(com.walmartlabs.concord.server.events.github.GithubRepoInfo)

Aggregations

GithubRepoInfo (com.walmartlabs.concord.server.events.github.GithubRepoInfo)1 RepositoryEntry (com.walmartlabs.concord.server.org.project.RepositoryEntry)1 HashMap (java.util.HashMap)1