Skip to content
Snippets Groups Projects
Select Git revision
  • f7c5df3fa19506018334573340e3800c36837bb7
  • master default protected
  • v1.11.0
  • v1.10.0
  • v1.9.0
  • v1.8.0
  • v1.7.0
  • v1.6.0
  • v1.5.0
  • v1.4.0
  • v1.3.1
  • v1.3.0
  • v1.2.1
  • v1.2.0
  • v1.1.0
  • v1.0.1
  • v1.0.0
17 results

gitlab.go

Blame
  • gitlab.go 915 B
    package condition
    
    import (
    	"fmt"
    	"os"
    )
    
    var CIVERSION = "dev"
    
    type GitLab struct {
    }
    
    func (gl *GitLab) Name() string {
    	return "GitLab CI"
    }
    
    func (gl *GitLab) Version() string {
    	return CIVERSION
    }
    
    func (gl *GitLab) GetCurrentBranch() string {
    	return os.Getenv("CI_COMMIT_BRANCH")
    }
    
    func (gl *GitLab) GetCurrentSHA() string {
    	return os.Getenv("CI_COMMIT_SHA")
    }
    
    func (gl *GitLab) IsBranchRef() bool {
    	return gl.GetCurrentBranch() != ""
    }
    
    func (gl *GitLab) RunCondition(config map[string]string) error {
    	defaultBranch := config["defaultBranch"]
    	if !gl.IsBranchRef() {
    		return fmt.Errorf("This test run is not running on a branch build.")
    	}
    	if branch := gl.GetCurrentBranch(); defaultBranch != "*" && branch != defaultBranch {
    		return fmt.Errorf("This test run was triggered on the branch %s, while semantic-release is configured to only publish from %s.", branch, defaultBranch)
    	}
    	return nil
    }