/**
 * Copyright (C) 2016 Red Hat, Inc.
 *
 * 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 io.fabric8.jenkins.openshiftsync;

import hudson.model.Cause;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.openshift.api.model.Build;
import io.fabric8.openshift.api.model.GitBuildSource;
import org.apache.commons.lang.StringUtils;

public class BuildCause extends Cause {

  private String uid;

  private String namespace;

  private String name;

  private String gitUri;

  private String commit;

  public BuildCause(String uid, String namespace, String name, String gitUri, String commit) {
    this.uid = uid;
    this.namespace = namespace;
    this.name = name;
    this.gitUri = gitUri;
    this.commit = commit;
  }

  public BuildCause(Build build) {
    if (build == null || build.getMetadata() == null) {
      return;
    }
    ObjectMeta meta = build.getMetadata();
    uid = meta.getUid();
    namespace = meta.getNamespace();
    name = meta.getName();

    if (build.getSpec() != null) {
      if (build.getSpec().getSource() != null && build.getSpec().getSource().getGit() != null) {
        GitBuildSource git = build.getSpec().getSource().getGit();
        gitUri = git.getUri();
      }

      if (build.getSpec().getRevision() != null && build.getSpec().getRevision().getGit() != null) {
        commit = build.getSpec().getRevision().getGit().getCommit();
      }
    }
  }

  @Override
  public String getShortDescription() {
    StringBuilder sb = new StringBuilder("OpenShift Build ")
      .append(namespace).append("/").append(name);

    if (StringUtils.isNotBlank(gitUri)) {
      sb.append(" from ").append(gitUri);
      if (StringUtils.isNotBlank(commit)) {
        sb.append(", commit ").append(commit);
      }
    }

    return sb.toString();
  }

  public String getUid() {
    return uid;
  }

  public String getNamespace() {
    return namespace;
  }

  public String getName() {
    return name;
  }

  public String getGitUri() {
    return gitUri;
  }

  public String getCommit() {
    return commit;
  }
}

@@ -1033,16 +1033,50 @@
 ommit;%0A%0A
+  private String buildConfigUid;%0A%0A
   public
@@ -1158,16 +1158,39 @@
 g commit
+, String buildConfigUid
 ) %7B%0A    
@@ -1317,45 +1317,152 @@
 ;%0A  
-%7D%0A%0A  public BuildCause(Build build) %7B
+  this.buildConfigUid = buildConfigUid;%0A  %7D%0A%0A  public BuildCause(Build build, String buildConfigUid) %7B%0A    this.buildConfigUid = buildConfigUid;
 %0A   
@@ -2745,11 +2745,81 @@
 mit;%0A  %7D
+%0A%0A  public String getBuildConfigUid() %7B%0A    return buildConfigUid;%0A  %7D
 %0A%7D%0A

Add build config uid to build cause to correlate back to build config