1
1
package gitlab
2
2
3
3
import (
4
+ "context"
4
5
"fmt"
5
6
"log"
6
7
8
+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
7
9
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
8
10
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
9
11
"github.com/xanzy/go-gitlab"
10
12
)
11
13
12
14
func dataSourceGitlabProjectProtectedBranch () * schema.Resource {
13
15
return & schema.Resource {
14
- Read : dataSourceGitlabProjectProtectedBranchRead ,
16
+ ReadContext : dataSourceGitlabProjectProtectedBranchRead ,
15
17
Schema : map [string ]* schema.Schema {
16
18
"project_id" : {
17
19
Type : schema .TypeString ,
@@ -70,7 +72,7 @@ func dataSourceGitlabProjectProtectedBranchSchemaAccessLevels() *schema.Schema {
70
72
}
71
73
}
72
74
73
- func dataSourceGitlabProjectProtectedBranchRead (d * schema.ResourceData , meta interface {}) error {
75
+ func dataSourceGitlabProjectProtectedBranchRead (ctx context. Context , d * schema.ResourceData , meta interface {}) diag. Diagnostics {
74
76
client := meta .(* gitlab.Client )
75
77
76
78
log .Printf ("[INFO] Reading Gitlab protected branch" )
@@ -79,24 +81,24 @@ func dataSourceGitlabProjectProtectedBranchRead(d *schema.ResourceData, meta int
79
81
name := d .Get ("name" ).(string )
80
82
81
83
// Get protected branch by project ID/path and branch name
82
- pb , _ , err := client .ProtectedBranches .GetProtectedBranch (project , name )
84
+ pb , _ , err := client .ProtectedBranches .GetProtectedBranch (project , name , gitlab . WithContext ( ctx ) )
83
85
if err != nil {
84
- return fmt .Errorf ("error getting protected branch (Project: %v / Name %v): %v" , project , name , err )
86
+ return diag .Errorf ("error getting protected branch (Project: %v / Name %v): %v" , project , name , err )
85
87
}
86
88
87
89
// lintignore:R004 // TODO: Resolve this tfproviderlint issue
88
90
if err := d .Set ("push_access_levels" , convertBranchAccessDescriptionsToStateBranchAccessDescriptions (pb .PushAccessLevels )); err != nil {
89
- return err
91
+ return diag . FromErr ( err )
90
92
}
91
93
// lintignore:R004 // TODO: Resolve this tfproviderlint issue
92
94
if err := d .Set ("merge_access_levels" , convertBranchAccessDescriptionsToStateBranchAccessDescriptions (pb .MergeAccessLevels )); err != nil {
93
- return err
95
+ return diag . FromErr ( err )
94
96
}
95
97
if err := d .Set ("allow_force_push" , pb .AllowForcePush ); err != nil {
96
- return err
98
+ return diag . FromErr ( err )
97
99
}
98
100
if err := d .Set ("code_owner_approval_required" , pb .CodeOwnerApprovalRequired ); err != nil {
99
- return err
101
+ return diag . FromErr ( err )
100
102
}
101
103
102
104
d .SetId (fmt .Sprintf ("%d" , pb .ID ))
0 commit comments