1
1
package gitlab
2
2
3
3
import (
4
+ "context"
4
5
"errors"
5
6
"fmt"
6
7
"log"
7
8
"net/http"
8
9
10
+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
9
11
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10
12
"github.com/xanzy/go-gitlab"
11
13
)
12
14
13
15
func dataSourceGitlabProject () * schema.Resource {
14
16
return & schema.Resource {
15
- Read : dataSourceGitlabProjectRead ,
17
+ ReadContext : dataSourceGitlabProjectRead ,
16
18
17
19
Schema : map [string ]* schema.Schema {
18
20
"id" : {
@@ -156,16 +158,16 @@ func dataSourceGitlabProject() *schema.Resource {
156
158
}
157
159
}
158
160
159
- func dataSourceGitlabProjectRead (d * schema.ResourceData , meta interface {}) error {
161
+ func dataSourceGitlabProjectRead (ctx context. Context , d * schema.ResourceData , meta interface {}) diag. Diagnostics {
160
162
client := meta .(* gitlab.Client )
161
163
162
164
log .Printf ("[INFO] Reading Gitlab project" )
163
165
164
166
v , _ := d .GetOk ("id" )
165
167
166
- found , _ , err := client .Projects .GetProject (v , nil )
168
+ found , _ , err := client .Projects .GetProject (v , nil , gitlab . WithContext ( ctx ) )
167
169
if err != nil {
168
- return err
170
+ return diag . FromErr ( err )
169
171
}
170
172
171
173
d .SetId (fmt .Sprintf ("%d" , found .ID ))
@@ -191,12 +193,12 @@ func dataSourceGitlabProjectRead(d *schema.ResourceData, meta interface{}) error
191
193
192
194
log .Printf ("[DEBUG] Reading Gitlab project %q push rules" , d .Id ())
193
195
194
- pushRules , _ , err := client .Projects .GetProjectPushRules (d .Id ())
196
+ pushRules , _ , err := client .Projects .GetProjectPushRules (d .Id (), gitlab . WithContext ( ctx ) )
195
197
var httpError * gitlab.ErrorResponse
196
198
if errors .As (err , & httpError ) && httpError .Response .StatusCode == http .StatusNotFound {
197
199
log .Printf ("[DEBUG] Failed to get push rules for project %q: %v" , d .Id (), err )
198
200
} else if err != nil {
199
- return fmt .Errorf ("Failed to get push rules for project %q: %w " , d .Id (), err )
201
+ return diag .Errorf ("Failed to get push rules for project %q: %v " , d .Id (), err )
200
202
}
201
203
202
204
d .Set ("push_rules" , flattenProjectPushRules (pushRules )) // lintignore: XR004 // TODO: Resolve this tfproviderlint issue
0 commit comments