1
1
package gitlab
2
2
3
3
import (
4
+ "errors"
4
5
"fmt"
5
6
"log"
7
+ "net/http"
6
8
7
9
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8
10
"github.com/xanzy/go-gitlab"
@@ -19,12 +21,10 @@ func dataSourceGitlabProject() *schema.Resource {
19
21
},
20
22
"name" : {
21
23
Type : schema .TypeString ,
22
- Optional : true ,
23
24
Computed : true ,
24
25
},
25
26
"path" : {
26
27
Type : schema .TypeString ,
27
- Optional : true ,
28
28
Computed : true ,
29
29
},
30
30
"path_with_namespace" : {
@@ -33,89 +33,125 @@ func dataSourceGitlabProject() *schema.Resource {
33
33
},
34
34
"description" : {
35
35
Type : schema .TypeString ,
36
- Optional : true ,
37
36
Computed : true ,
38
37
},
39
38
"default_branch" : {
40
39
Type : schema .TypeString ,
41
- Optional : true ,
42
40
Computed : true ,
43
41
},
44
42
"request_access_enabled" : {
45
43
Type : schema .TypeBool ,
46
- Optional : true ,
47
44
Computed : true ,
48
45
},
49
46
"issues_enabled" : {
50
47
Type : schema .TypeBool ,
51
- Optional : true ,
52
48
Computed : true ,
53
49
},
54
50
"merge_requests_enabled" : {
55
51
Type : schema .TypeBool ,
56
- Optional : true ,
57
52
Computed : true ,
58
53
},
59
54
"pipelines_enabled" : {
60
55
Type : schema .TypeBool ,
61
- Optional : true ,
62
56
Computed : true ,
63
57
},
64
58
"wiki_enabled" : {
65
59
Type : schema .TypeBool ,
66
- Optional : true ,
67
60
Computed : true ,
68
61
},
69
62
"snippets_enabled" : {
70
63
Type : schema .TypeBool ,
71
- Optional : true ,
72
64
Computed : true ,
73
65
},
74
66
"lfs_enabled" : {
75
67
Type : schema .TypeBool ,
76
- Optional : true ,
77
68
Computed : true ,
78
69
},
79
70
"visibility_level" : {
80
71
Type : schema .TypeString ,
81
- Optional : true ,
82
72
Computed : true ,
83
73
},
84
74
"namespace_id" : {
85
75
Type : schema .TypeInt ,
86
- Optional : true ,
87
76
Computed : true ,
88
77
},
89
78
"ssh_url_to_repo" : {
90
79
Type : schema .TypeString ,
91
- Optional : true ,
92
80
Computed : true ,
93
81
},
94
82
"http_url_to_repo" : {
95
83
Type : schema .TypeString ,
96
- Optional : true ,
97
84
Computed : true ,
98
85
},
99
86
"web_url" : {
100
87
Type : schema .TypeString ,
101
- Optional : true ,
102
88
Computed : true ,
103
89
},
104
90
"runners_token" : {
105
91
Type : schema .TypeString ,
106
- Optional : true ,
107
92
Computed : true ,
108
93
},
109
94
"archived" : {
110
95
Type : schema .TypeBool ,
111
- Optional : true ,
112
96
Computed : true ,
113
97
},
114
98
"remove_source_branch_after_merge" : {
115
99
Type : schema .TypeBool ,
116
- Optional : true ,
117
100
Computed : true ,
118
101
},
102
+ "push_rules" : {
103
+ Type : schema .TypeList ,
104
+ MaxItems : 1 ,
105
+ Computed : true ,
106
+ Elem : & schema.Resource {
107
+ Schema : map [string ]* schema.Schema {
108
+ "author_email_regex" : {
109
+ Type : schema .TypeString ,
110
+ Computed : true ,
111
+ },
112
+ "branch_name_regex" : {
113
+ Type : schema .TypeString ,
114
+ Computed : true ,
115
+ },
116
+ "commit_message_regex" : {
117
+ Type : schema .TypeString ,
118
+ Computed : true ,
119
+ },
120
+ "commit_message_negative_regex" : {
121
+ Type : schema .TypeString ,
122
+ Computed : true ,
123
+ },
124
+ "file_name_regex" : {
125
+ Type : schema .TypeString ,
126
+ Computed : true ,
127
+ },
128
+ "commit_committer_check" : {
129
+ Type : schema .TypeBool ,
130
+ Computed : true ,
131
+ },
132
+ "deny_delete_tag" : {
133
+ Type : schema .TypeBool ,
134
+ Computed : true ,
135
+ },
136
+ "member_check" : {
137
+ Type : schema .TypeBool ,
138
+ Computed : true ,
139
+ },
140
+ "prevent_secrets" : {
141
+ Type : schema .TypeBool ,
142
+ Computed : true ,
143
+ },
144
+ "reject_unsigned_commits" : {
145
+ Type : schema .TypeBool ,
146
+ Computed : true ,
147
+ },
148
+ "max_file_size" : {
149
+ Type : schema .TypeInt ,
150
+ Computed : true ,
151
+ },
152
+ },
153
+ },
154
+ },
119
155
},
120
156
}
121
157
}
@@ -152,5 +188,18 @@ func dataSourceGitlabProjectRead(d *schema.ResourceData, meta interface{}) error
152
188
d .Set ("runners_token" , found .RunnersToken )
153
189
d .Set ("archived" , found .Archived )
154
190
d .Set ("remove_source_branch_after_merge" , found .RemoveSourceBranchAfterMerge )
191
+
192
+ log .Printf ("[DEBUG] Reading Gitlab project %q push rules" , d .Id ())
193
+
194
+ pushRules , _ , err := client .Projects .GetProjectPushRules (d .Id ())
195
+ var httpError * gitlab.ErrorResponse
196
+ if errors .As (err , & httpError ) && httpError .Response .StatusCode == http .StatusNotFound {
197
+ log .Printf ("[DEBUG] Failed to get push rules for project %q: %v" , d .Id (), err )
198
+ } else if err != nil {
199
+ return fmt .Errorf ("Failed to get push rules for project %q: %w" , d .Id (), err )
200
+ }
201
+
202
+ d .Set ("push_rules" , flattenProjectPushRules (pushRules ))
203
+
155
204
return nil
156
205
}
0 commit comments