コード例 #1
0
ファイル: projects.go プロジェクト: ae6rt/decap
func descriptorForTeamProject(data []byte) (v1.ProjectDescriptor, error) {
	var descriptor v1.ProjectDescriptor
	if err := json.Unmarshal(data, &descriptor); err != nil {
		return v1.ProjectDescriptor{}, err
	}

	if descriptor.ManagedRefRegexStr != "" {
		if re, err := regexp.Compile(descriptor.ManagedRefRegexStr); err != nil {
			Log.Printf("Error parsing managed-branch-regex %s for descriptor %+v: %v\n", descriptor.ManagedRefRegexStr, data, err)
		} else {
			descriptor.Regex = re
		}
	}

	return descriptor, nil
}
コード例 #2
0
ファイル: projectdescriptor_test.go プロジェクト: ae6rt/decap
func TestDescriptorRegex(t *testing.T) {
	var descriptor v1.ProjectDescriptor

	// regex matches all branches
	descriptor, _ = descriptorForTeamProject([]byte(`{
     "buildImage": "ae6rt/java7:latest",
     "managedRefRegex": ".*",
     "repoManager": "github",
     "repoUrl": "https://github.com/ae6rt/hello-world-java.git",
     "repoDescription": "Hello world in Java"}`))

	if !descriptor.IsRefManaged("master") {
		t.Fatalf("Want true")
	}

	// no regex matches all branches
	descriptor, _ = descriptorForTeamProject([]byte(`{
     "buildImage": "ae6rt/java7:latest",
     "repoManager": "github",
     "repoUrl": "https://github.com/ae6rt/hello-world-java.git",
     "repoDescription": "Hello world in Java"}`))

	if !descriptor.IsRefManaged("master") {
		t.Fatalf("Want true")
	}

	// match only issue/.*
	descriptor, _ = descriptorForTeamProject([]byte(`{
     "buildImage": "ae6rt/java7:latest",
     "repoManager": "github",
     "managedRefRegex": "issue/.*",
     "repoUrl": "https://github.com/ae6rt/hello-world-java.git",
     "repoDescription": "Hello world in Java"}`))

	if descriptor.IsRefManaged("master") {
		t.Fatalf("Want false")
	}

	// match only feature/.*
	descriptor, _ = descriptorForTeamProject([]byte(`{
     "buildImage": "ae6rt/java7:latest",
     "repoManager": "github",
     "managedRefRegex": "feature/.*",
     "repoUrl": "https://github.com/ae6rt/hello-world-java.git",
     "repoDescription": "Hello world in Java"}`))

	if !descriptor.IsRefManaged("feature/PLAT-99") {
		t.Fatalf("Want true")
	}
}