diff --git a/azuredevops/internal/acceptancetests/resource_branchpolicy_test.go b/azuredevops/internal/acceptancetests/resource_branchpolicy_test.go index d6dd6571a..24c5ce509 100644 --- a/azuredevops/internal/acceptancetests/resource_branchpolicy_test.go +++ b/azuredevops/internal/acceptancetests/resource_branchpolicy_test.go @@ -5,6 +5,7 @@ package acceptancetests import ( "fmt" + "os" "strings" "testing" @@ -23,6 +24,7 @@ func TestAccBranchPolicy_CreateAndUpdate(t *testing.T) { projectName: projName, repoName: repoName, minReviewerOptions: minReviewPolicyOpts{true, true, 1, false}, + autoReviewerOptions: autoReviewPolicyOpts{true, true, false, "auto reviewer", fmt.Sprintf("\"%s\",\"%s\"", "*/API*.cs", "README.md")}, buildValidationOptions: buildValidationPolicyOpts{true, true, "build validation", 0}, } @@ -30,14 +32,17 @@ func TestAccBranchPolicy_CreateAndUpdate(t *testing.T) { projectName: projName, repoName: repoName, minReviewerOptions: minReviewPolicyOpts{false, false, 2, true}, + autoReviewerOptions: autoReviewPolicyOpts{false, false, true, "new auto reviewer", fmt.Sprintf("\"%s\",\"%s\"", "*/API*.cs", "README.md")}, buildValidationOptions: buildValidationPolicyOpts{false, false, "build validation rename", 720}, } minReviewerTfNode := "azuredevops_branch_policy_min_reviewers.p" buildVlidationTfNode := "azuredevops_branch_policy_build_validation.p" + autoReviewerTfNode := "azuredevops_branch_policy_auto_reviewers.p" + fmt.Println(getHCL(opts1)) resource.Test(t, resource.TestCase{ - PreCheck: func() { testutils.PreCheck(t, nil) }, + PreCheck: func() { testutils.PreCheck(t, &[]string{"AZDO_TEST_AAD_USER_EMAIL"}) }, Providers: testutils.GetProviders(), Steps: []resource.TestStep{ { @@ -46,6 +51,8 @@ func TestAccBranchPolicy_CreateAndUpdate(t *testing.T) { resource.TestCheckResourceAttrSet(minReviewerTfNode, "id"), resource.TestCheckResourceAttr(minReviewerTfNode, "blocking", "true"), resource.TestCheckResourceAttr(minReviewerTfNode, "enabled", "true"), + resource.TestCheckResourceAttr(autoReviewerTfNode, "enabled", "true"), + resource.TestCheckResourceAttr(autoReviewerTfNode, "blocking", "true"), resource.TestCheckResourceAttr(buildVlidationTfNode, "enabled", "true"), resource.TestCheckResourceAttr(buildVlidationTfNode, "enabled", "true"), ), @@ -55,6 +62,8 @@ func TestAccBranchPolicy_CreateAndUpdate(t *testing.T) { resource.TestCheckResourceAttrSet(minReviewerTfNode, "id"), resource.TestCheckResourceAttr(minReviewerTfNode, "blocking", "false"), resource.TestCheckResourceAttr(minReviewerTfNode, "enabled", "false"), + resource.TestCheckResourceAttr(autoReviewerTfNode, "enabled", "false"), + resource.TestCheckResourceAttr(autoReviewerTfNode, "blocking", "false"), resource.TestCheckResourceAttr(buildVlidationTfNode, "enabled", "false"), resource.TestCheckResourceAttr(buildVlidationTfNode, "enabled", "false"), ), @@ -68,6 +77,11 @@ func TestAccBranchPolicy_CreateAndUpdate(t *testing.T) { ImportStateIdFunc: testutils.ComputeProjectQualifiedResourceImportID(buildVlidationTfNode), ImportState: true, ImportStateVerify: true, + }, { + ResourceName: autoReviewerTfNode, + ImportStateIdFunc: testutils.ComputeProjectQualifiedResourceImportID(autoReviewerTfNode), + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -80,6 +94,14 @@ type minReviewPolicyOpts struct { submitterCanVote bool } +type autoReviewPolicyOpts struct { + enabled bool + blocking bool + submitterCanVote bool + message string + pathFilters string +} + type buildValidationPolicyOpts struct { enabled bool blocking bool @@ -92,10 +114,13 @@ type hclOptions struct { repoName string minReviewerOptions minReviewPolicyOpts buildValidationOptions buildValidationPolicyOpts + autoReviewerOptions autoReviewPolicyOpts } func getHCL(opts hclOptions) string { projectAndRepo := testutils.HclGitRepoResource(opts.projectName, opts.repoName, "Clean") + userEmail := os.Getenv("AZDO_TEST_AAD_USER_EMAIL") + userEntitlement := testutils.HclUserEntitlementResource(userEmail) buildDef := ` resource "azuredevops_build_definition" "build" { project_id = azuredevops_project.project.id @@ -108,6 +133,7 @@ func getHCL(opts hclOptions) string { } } ` + minReviewCountPolicyFmt := ` resource "azuredevops_branch_policy_min_reviewers" "p" { project_id = azuredevops_project.project.id @@ -124,7 +150,6 @@ func getHCL(opts hclOptions) string { } } ` - minReviewCountPolicy := fmt.Sprintf( minReviewCountPolicyFmt, opts.minReviewerOptions.enabled, @@ -132,6 +157,32 @@ func getHCL(opts hclOptions) string { opts.minReviewerOptions.reviewers, opts.minReviewerOptions.submitterCanVote) + autoReviewerPolicyFmt := ` + resource "azuredevops_branch_policy_auto_reviewers" "p" { + project_id = azuredevops_project.project.id + enabled = %t + blocking = %t + settings { + auto_reviewer_ids = [azuredevops_user_entitlement.user.id] + submitter_can_vote = %t + message = "%s" + path_filters = [%s] + scope { + repository_id = azuredevops_git_repository.gitrepo.id + repository_ref = azuredevops_git_repository.gitrepo.default_branch + match_type = "exact" + } + } + } + ` + autoReviewerPolicy := fmt.Sprintf( + autoReviewerPolicyFmt, + opts.autoReviewerOptions.enabled, + opts.autoReviewerOptions.blocking, + opts.autoReviewerOptions.submitterCanVote, + opts.autoReviewerOptions.message, + opts.autoReviewerOptions.pathFilters) + buildValidationPolicyFmt := ` resource "azuredevops_branch_policy_build_validation" "p" { project_id = azuredevops_project.project.id @@ -149,7 +200,7 @@ func getHCL(opts hclOptions) string { } } ` - buildValidationPolicyFmt = fmt.Sprintf( + buildValidationPolicy := fmt.Sprintf( buildValidationPolicyFmt, opts.buildValidationOptions.enabled, opts.buildValidationOptions.blocking, @@ -159,9 +210,11 @@ func getHCL(opts hclOptions) string { return strings.Join( []string{ projectAndRepo, + userEntitlement, buildDef, minReviewCountPolicy, - buildValidationPolicyFmt, + buildValidationPolicy, + autoReviewerPolicy, }, "\n", ) diff --git a/azuredevops/internal/service/policy/common.go b/azuredevops/internal/service/policy/common.go index 173da755c..47d6710d0 100644 --- a/azuredevops/internal/service/policy/common.go +++ b/azuredevops/internal/service/policy/common.go @@ -28,6 +28,7 @@ var ( NoActiveComments = uuid.MustParse("c6a1889d-b943-4856-b76f-9e46bb6b0df2") MinReviewerCount = uuid.MustParse("fa4e907d-c16b-4a4c-9dfa-4906e5d171dd") BuildValidation = uuid.MustParse("0609b952-1397-4640-95ec-e00a01b2c241") + AutoReviewers = uuid.MustParse("fd2167ab-b0be-447a-8ec8-39368250530e") ) // Keys for schema elements diff --git a/azuredevops/internal/service/policy/resource_branchpolicy_auto_reviewers.go b/azuredevops/internal/service/policy/resource_branchpolicy_auto_reviewers.go new file mode 100644 index 000000000..7bb001457 --- /dev/null +++ b/azuredevops/internal/service/policy/resource_branchpolicy_auto_reviewers.go @@ -0,0 +1,124 @@ +package policy + +import ( + "encoding/json" + "fmt" + + "github.com/google/uuid" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + + "github.com/microsoft/azure-devops-go-api/azuredevops/policy" +) + +type autoReviewerPolicySettings struct { + SubmitterCanVote bool `json:"creatorVoteCounts"` + AutoReviewerIds []string `json:"requiredReviewerIds"` + PathFilters []string `json:"filenamePatterns"` + DisplayMessage string `json:"message"` +} + +const ( + autoReviewerIds = "auto_reviewer_ids" + pathFilters = "path_filters" + displayMessage = "message" +) + +// ResourceBranchPolicyAutoReviewers schema and implementation for automatic code reviewer policy resource +func ResourceBranchPolicyAutoReviewers() *schema.Resource { + resource := genBasePolicyResource(&policyCrudArgs{ + FlattenFunc: autoReviewersFlattenFunc, + ExpandFunc: autoReviewersExpandFunc, + PolicyType: AutoReviewers, + }) + + settingsSchema := resource.Schema[SchemaSettings].Elem.(*schema.Resource).Schema + settingsSchema[autoReviewerIds] = &schema.Schema{ + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.StringIsNotEmpty, + }, + } + settingsSchema[pathFilters] = &schema.Schema{ + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.StringIsNotEmpty, + }, + } + settingsSchema[displayMessage] = &schema.Schema{ + Type: schema.TypeString, + Required: false, + Default: "", + Optional: true, + } + settingsSchema[schemaSubmitterCanVote] = &schema.Schema{ + Type: schema.TypeBool, + Default: false, + Optional: true, + } + + return resource +} + +func autoReviewersFlattenFunc(d *schema.ResourceData, policyConfig *policy.PolicyConfiguration, projectID *string) error { + err := baseFlattenFunc(d, policyConfig, projectID) + if err != nil { + return err + } + policyAsJSON, err := json.Marshal(policyConfig.Settings) + if err != nil { + return fmt.Errorf("Unable to marshal policy settings into JSON: %+v", err) + } + + policySettings := autoReviewerPolicySettings{} + err = json.Unmarshal(policyAsJSON, &policySettings) + if err != nil { + return fmt.Errorf("Unable to unmarshal branch policy settings (%+v): %+v", policySettings, err) + } + + settingsList := d.Get(SchemaSettings).([]interface{}) + settings := settingsList[0].(map[string]interface{}) + + settings[schemaSubmitterCanVote] = policySettings.SubmitterCanVote + settings[autoReviewerIds] = policySettings.AutoReviewerIds + settings[pathFilters] = policySettings.PathFilters + settings[displayMessage] = policySettings.DisplayMessage + d.Set(SchemaSettings, settingsList) + return nil +} + +func autoReviewersExpandFunc(d *schema.ResourceData, typeID uuid.UUID) (*policy.PolicyConfiguration, *string, error) { + policyConfig, projectID, err := baseExpandFunc(d, typeID) + if err != nil { + return nil, nil, err + } + + settingsList := d.Get(SchemaSettings).([]interface{}) + settings := settingsList[0].(map[string]interface{}) + + policySettings := policyConfig.Settings.(map[string]interface{}) + policySettings["creatorVoteCounts"] = settings[schemaSubmitterCanVote].(bool) + policySettings["message"] = settings[displayMessage].(string) + + if value, ok := settings[autoReviewerIds]; ok { + var reviewersID []string + for _, item := range value.([]interface{}) { + reviewersID = append(reviewersID, item.(string)) + } + policySettings["requiredReviewerIds"] = reviewersID + } + + if value, ok := settings[pathFilters]; ok { + var pathFilters []string + for _, item := range value.([]interface{}) { + pathFilters = append(pathFilters, item.(string)) + } + policySettings["filenamePatterns"] = pathFilters + } + + return policyConfig, projectID, nil +} diff --git a/azuredevops/provider.go b/azuredevops/provider.go index b5fbf22b8..45cf6bf24 100644 --- a/azuredevops/provider.go +++ b/azuredevops/provider.go @@ -22,6 +22,7 @@ func Provider() *schema.Provider { "azuredevops_resource_authorization": build.ResourceResourceAuthorization(), "azuredevops_branch_policy_build_validation": policy.ResourceBranchPolicyBuildValidation(), "azuredevops_branch_policy_min_reviewers": policy.ResourceBranchPolicyMinReviewers(), + "azuredevops_branch_policy_auto_reviewers": policy.ResourceBranchPolicyAutoReviewers(), "azuredevops_build_definition": build.ResourceBuildDefinition(), "azuredevops_project": core.ResourceProject(), "azuredevops_project_features": core.ResourceProjectFeatures(), diff --git a/azuredevops/provider_test.go b/azuredevops/provider_test.go index f6c4a8fe6..c7bce425e 100644 --- a/azuredevops/provider_test.go +++ b/azuredevops/provider_test.go @@ -13,6 +13,7 @@ func TestProvider_HasChildResources(t *testing.T) { "azuredevops_build_definition", "azuredevops_branch_policy_build_validation", "azuredevops_branch_policy_min_reviewers", + "azuredevops_branch_policy_auto_reviewers", "azuredevops_project", "azuredevops_project_features", "azuredevops_serviceendpoint_github", diff --git a/go.sum b/go.sum index d1d9f25c7..57711ea6c 100644 --- a/go.sum +++ b/go.sum @@ -386,7 +386,6 @@ golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTk golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190409202823-959b441ac422 h1:QzoH/1pFpZguR8NrRHLcO6jKqfv2zpuSqZLgdm7ZmjI= golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -402,9 +401,7 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191009170851-d66e71096ffb h1:TR699M2v0qoKTOHxeLgp6zPqaQNs74f01a/ob9W0qko= golang.org/x/net v0.0.0-20191009170851-d66e71096ffb/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0= golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -432,9 +429,7 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0 h1:HyfiK1WMnHj5FXFXatD+Qs1A/xC2Run6RzeW1SyHxpc= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa h1:KIDDMLT1O0Nr7TSxp8xM5tJcdn8tgyAONntO829og1M= golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So= golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -455,7 +450,6 @@ golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0 h1:Dh6fw+p6FyRl5x/FvNswO1ji0lIGzm3KP8Y9VkS9PTE= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= @@ -473,16 +467,13 @@ google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRn google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200310143817-43be25429f5a h1:lRlI5zu6AFy3iU/F8YWyNrAmn/tPCnhiTxfwhWb76eU= google.golang.org/genproto v0.0.0-20200310143817-43be25429f5a/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.21.1 h1:j6XxA85m/6txkUCHvzlV5f+HBNl/1r5cZ2A/3IEFOO8= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.23.0 h1:AzbTB6ux+okLTzP8Ru1Xs41C303zdcfEht7MQnYJt5A= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.1 h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk= @@ -496,7 +487,6 @@ gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/website/docs/r/branch_policy_auto_reviewers.html.markdown b/website/docs/r/branch_policy_auto_reviewers.html.markdown new file mode 100644 index 000000000..e6d279204 --- /dev/null +++ b/website/docs/r/branch_policy_auto_reviewers.html.markdown @@ -0,0 +1,92 @@ +--- +layout: "azuredevops" +page_title: "AzureDevops: azuredevops_branch_policy_auto_reviewers" +description: |- + Manages required reviewer policy branch policy within Azure DevOps project. +--- + +# azuredevops_branch_policy_auto_reviewers + +Manages required reviewer policy branch policy within Azure DevOps. + +## Example Usage + +```hcl +resource "azuredevops_project" "p" { + project_name = "Sample Project" +} + +resource "azuredevops_git_repository" "r" { + project_id = azuredevops_project.p.id + name = "Sample Repo" + initialization { + init_type = "Clean" + } +} + +resource "azuredevops_user_entitlement" "user" { + principal_name = "mail@email.com" + account_license_type = "basic" +} + +resource "azuredevops_branch_policy_auto_reviewers" "p" { + project_id = azuredevops_project.p.id + + enabled = true + blocking = true + + settings { + auto_reviewer_ids = [azuredevops_user_entitlement.user.id] + submitter_can_vote = false + message = "Auto reviewer" + path_filters = ["*/src/*.ts"] + + scope { + repository_id = azuredevops_git_repository.r.id + repository_ref = azuredevops_git_repository.r.default_branch + match_type = "Exact" + } + } +} +``` + +## Argument Reference + +The following arguments are supported: + +- `project_id` - (Required) The ID of the project in which the policy will be created. +- `enabled` - (Optional) A flag indicating if the policy should be enabled. Defaults to `true`. +- `blocking` - (Optional) A flag indicating if the policy should be blocking. Defaults to `true`. +- `settings` - (Required) Configuration for the policy. This block must be defined exactly once. + +`settings` block supports the following: + +- `auto_reviewer_ids` - (Required) Required reviewers ids. Supports multiples user Ids. +- `path_filters` - (Optional) Filter path(s) on which the policy is applied. Supports absolute paths, wildcards and multiple paths. Example: /WebApp/Models/Data.cs, /WebApp/* or *.cs,/WebApp/Models/Data.cs;ClientApp/Models/Data.cs. +- `submitter_can_vote` - (Optional) Controls whether or not the submitter's vote counts. Defaults to `false`. +- `message` - (Optional) Activity feed message, Message will appear in the activity feed of pull requests with automatically added reviewers. +- `scope` (Required) Controls which repositories and branches the policy will be enabled for. This block must be defined at least once. + + `scope` block supports the following: + + - `repository_id` - (Optional) The repository ID. Needed only if the scope of the policy will be limited to a single repository. + - `repository_ref` - (Optional) The ref pattern to use for the match. If `match_type` is `Exact`, this should be a qualified ref such as `refs/heads/master`. If `match_type` is `Prefix`, this should be a ref path such as `refs/heads/releases`. + - `match_type` (Optional) The match type to use when applying the policy. Supported values are `Exact` (default) or `Prefix`. + +## Attributes Reference + +In addition to all arguments above, the following attributes are exported: + +- `id` - The ID of branch policy configuration. + +## Relevant Links + +- [Azure DevOps Service REST API 5.1 - Policy Configurations](https://docs.microsoft.com/en-us/rest/api/azure/devops/policy/configurations/create?view=azure-devops-rest-5.1) + +## Import + +Azure DevOps Branch Policies can be imported using the project ID and policy configuration ID: + +```sh +terraform import azuredevops_branch_policy_auto_reviewers.p aa4a9756-8a86-4588-86d7-b3ee2d88b033/60 +```