package com.mhackner.bamboo;

import com.atlassian.bamboo.chains.Chain;
import com.atlassian.bamboo.chains.ChainExecution;
import com.atlassian.bamboo.chains.ChainResultsSummary;
import com.atlassian.bamboo.chains.plugins.PostChainAction;
import com.atlassian.bamboo.configuration.AdministrationConfigurationAccessor;
import com.atlassian.bamboo.security.EncryptionService;

import org.jetbrains.annotations.NotNull;
import org.kohsuke.github.GHCommitState;

public class GitHubStatusPostChain extends AbstractGitHubStatusAction implements PostChainAction {

    public GitHubStatusPostChain(AdministrationConfigurationAccessor adminConfigAccessor,
                                 EncryptionService encryptionService) {
        super(adminConfigAccessor, encryptionService);
    }

    @Override
    public void execute(@NotNull Chain chain, @NotNull ChainResultsSummary chainResultsSummary,
                        @NotNull ChainExecution chainExecution) {
        switch (chainResultsSummary.getBuildState()) {
        case FAILED:
            updateStatus(GHCommitState.FAILURE, chain, chainExecution);
            break;
        case SUCCESS:
            updateStatus(GHCommitState.SUCCESS, chain, chainExecution);
            break;
        case UNKNOWN:
            updateStatus(GHCommitState.ERROR, chain, chainExecution);
            break;
        }
    }

}

@@ -23,16 +23,64 @@
 amboo;%0A%0A
+import com.atlassian.bamboo.builder.BuildState;%0A
 import c
@@ -113,16 +113,16 @@
 .Chain;%0A
-
 import c
@@ -414,16 +414,63 @@
 Service;
+%0Aimport com.google.common.collect.ImmutableMap;
 %0A%0Aimport
@@ -647,16 +647,276 @@
 tion %7B%0A%0A
+    private static final ImmutableMap%3CBuildState, GHCommitState%3E states = ImmutableMap.of(%0A            BuildState.FAILED, GHCommitState.FAILURE,%0A            BuildState.SUCCESS, GHCommitState.SUCCESS,%0A            BuildState.UNKNOWN, GHCommitState.ERROR%0A    );%0A%0A
     publ
@@ -1319,400 +1319,93 @@
     
-switch (chainResultsSummary.getBuildState()) %7B%0A        case FAILED:%0A            updateStatus(GHCommitState.FAILURE, chain, chainExecution);%0A            break;%0A        case SUCCESS:%0A            updateStatus(GHCommitState.SUCCESS, chain, chainExecution);%0A            break;%0A        case UNKNOWN:%0A            updateStatus(GHCommitState.ERROR, chain, chainExecution);%0A            break;%0A        %7D
+updateStatus(states.get(chainResultsSummary.getBuildState()), chain, chainExecution);
 %0A   

Refactor build state mapping to an actual map