@@ -205,6 +205,51 @@ type DefaultReviewers struct {
205
205
DefaultReviewers []DefaultReviewer
206
206
}
207
207
208
+ type Group struct {
209
+ AccountPrivilege string `mapstructure:"account_privilege"`
210
+ DefaultPermission string `mapstructure:"default_permission"`
211
+ EmailForwardingDisabled bool `mapstructure:"email_forwarding_disabled"`
212
+ FullSlug string `mapstructure:"full_slug"`
213
+ Links map [string ]map [string ]string
214
+ Name string `mapstructure:"name"`
215
+ Slug string `mapstructure:"slug"`
216
+ Type string `mapstructure:"type"`
217
+ Workspace map [string ]interface {} `mapstructure:"workspace"`
218
+ Owner map [string ]interface {}
219
+ }
220
+
221
+ type GroupPermission struct {
222
+ Type string
223
+ Group Group
224
+ Permission string
225
+ Links map [string ]map [string ]string
226
+ }
227
+
228
+ type GroupPermissions struct {
229
+ Page int
230
+ Pagelen int
231
+ MaxDepth int
232
+ Size int
233
+ Next string
234
+ GroupPermissions []GroupPermission
235
+ }
236
+
237
+ type UserPermission struct {
238
+ Type string
239
+ User User
240
+ Permission string
241
+ Links map [string ]map [string ]string
242
+ }
243
+
244
+ type UserPermissions struct {
245
+ Page int
246
+ Pagelen int
247
+ MaxDepth int
248
+ Size int
249
+ Next string
250
+ UserPermissions []UserPermission
251
+ }
252
+
208
253
func (r * Repository ) Create (ro * RepositoryOptions ) (* Repository , error ) {
209
254
data , err := r .buildRepositoryBody (ro )
210
255
if err != nil {
@@ -834,6 +879,88 @@ func (r *Repository) UpdateDeploymentVariable(opt *RepositoryDeploymentVariableO
834
879
return decodeDeploymentVariable (response )
835
880
}
836
881
882
+ func (r * Repository ) ListGroupPermissions (ro * RepositoryOptions ) (* GroupPermissions , error ) {
883
+ urlStr := r .c .requestUrl ("/repositories/%s/%s/permissions-config/groups?pagelen=1" , ro .Owner , ro .RepoSlug )
884
+
885
+ res , err := r .c .executePaginated ("GET" , urlStr , "" )
886
+ if err != nil {
887
+ return nil , err
888
+ }
889
+ return decodeGroupsPermissions (res )
890
+ }
891
+
892
+ func (r * Repository ) SetGroupPermissions (rgo * RepositoryGroupPermissionsOptions ) (* GroupPermission , error ) {
893
+ body , err := r .buildRepositoryGroupPermissionBody (rgo )
894
+ if err != nil {
895
+ return nil , err
896
+ }
897
+
898
+ urlStr := r .c .requestUrl ("/repositories/%s/%s/permissions-config/groups/%s" , rgo .Owner , rgo .RepoSlug , rgo .Group )
899
+
900
+ res , err := r .c .execute ("PUT" , urlStr , body )
901
+ if err != nil {
902
+ return nil , err
903
+ }
904
+
905
+ return decodeGroupPermissions (res )
906
+ }
907
+
908
+ func (r * Repository ) DeleteGroupPermissions (rgo * RepositoryGroupPermissionsOptions ) (interface {}, error ) {
909
+ urlStr := r .c .requestUrl ("/repositories/%s/%s/permissions-config/groups/%s" , rgo .Owner , rgo .RepoSlug , rgo .Group )
910
+ return r .c .execute ("DELETE" , urlStr , "" )
911
+ }
912
+
913
+ func (r * Repository ) GetGroupPermissions (rgo * RepositoryGroupPermissionsOptions ) (* GroupPermission , error ) {
914
+ urlStr := r .c .requestUrl ("/repositories/%s/%s/permissions-config/groups/%s" , rgo .Owner , rgo .RepoSlug , rgo .Group )
915
+
916
+ res , err := r .c .executePaginated ("GET" , urlStr , "" )
917
+ if err != nil {
918
+ return nil , err
919
+ }
920
+ return decodeGroupPermissions (res )
921
+ }
922
+
923
+ func (r * Repository ) ListUserPermissions (ro * RepositoryOptions ) (* UserPermissions , error ) {
924
+ urlStr := r .c .requestUrl ("/repositories/%s/%s/permissions-config/users?pagelen=1" , ro .Owner , ro .RepoSlug )
925
+
926
+ res , err := r .c .executePaginated ("GET" , urlStr , "" )
927
+ if err != nil {
928
+ return nil , err
929
+ }
930
+ return decodeUsersPermissions (res )
931
+ }
932
+
933
+ func (r * Repository ) SetUserPermissions (rgo * RepositoryUserPermissionsOptions ) (* UserPermission , error ) {
934
+ body , err := r .buildRepositoryUserPermissionBody (rgo )
935
+ if err != nil {
936
+ return nil , err
937
+ }
938
+
939
+ urlStr := r .c .requestUrl ("/repositories/%s/%s/permissions-config/users/%s" , rgo .Owner , rgo .RepoSlug , rgo .User )
940
+
941
+ res , err := r .c .execute ("PUT" , urlStr , body )
942
+ if err != nil {
943
+ return nil , err
944
+ }
945
+
946
+ return decodeUserPermissions (res )
947
+ }
948
+
949
+ func (r * Repository ) DeleteUserPermissions (rgo * RepositoryUserPermissionsOptions ) (interface {}, error ) {
950
+ urlStr := r .c .requestUrl ("/repositories/%s/%s/permissions-config/users/%s" , rgo .Owner , rgo .RepoSlug , rgo .User )
951
+ return r .c .execute ("DELETE" , urlStr , "" )
952
+ }
953
+
954
+ func (r * Repository ) GetUserPermissions (rgo * RepositoryUserPermissionsOptions ) (* UserPermission , error ) {
955
+ urlStr := r .c .requestUrl ("/repositories/%s/%s/permissions-config/users/%s" , rgo .Owner , rgo .RepoSlug , rgo .User )
956
+
957
+ res , err := r .c .executePaginated ("GET" , urlStr , "" )
958
+ if err != nil {
959
+ return nil , err
960
+ }
961
+ return decodeUserPermissions (res )
962
+ }
963
+
837
964
func (r * Repository ) buildRepositoryBody (ro * RepositoryOptions ) (string , error ) {
838
965
body := map [string ]interface {}{}
839
966
@@ -1019,6 +1146,22 @@ func (r *Repository) buildDeploymentVariableBody(opt *RepositoryDeploymentVariab
1019
1146
return r .buildJsonBody (body )
1020
1147
}
1021
1148
1149
+ func (r * Repository ) buildRepositoryGroupPermissionBody (rpo * RepositoryGroupPermissionsOptions ) (string , error ) {
1150
+ body := map [string ]interface {}{}
1151
+
1152
+ body ["permission" ] = rpo .Permission
1153
+
1154
+ return r .buildJsonBody (body )
1155
+ }
1156
+
1157
+ func (r * Repository ) buildRepositoryUserPermissionBody (rpo * RepositoryUserPermissionsOptions ) (string , error ) {
1158
+ body := map [string ]interface {}{}
1159
+
1160
+ body ["permission" ] = rpo .Permission
1161
+
1162
+ return r .buildJsonBody (body )
1163
+ }
1164
+
1022
1165
func (r * Repository ) buildJsonBody (body map [string ]interface {}) (string , error ) {
1023
1166
data , err := json .Marshal (body )
1024
1167
if err != nil {
@@ -1591,3 +1734,115 @@ func decodeDefaultReviewers(response interface{}) (*DefaultReviewers, error) {
1591
1734
}
1592
1735
return & defaultReviewerVariables , nil
1593
1736
}
1737
+
1738
+ func decodeGroupPermissions (response interface {}) (* GroupPermission , error ) {
1739
+ var groupPermission GroupPermission
1740
+ err := mapstructure .Decode (response , & groupPermission )
1741
+ if err != nil {
1742
+ return nil , err
1743
+ }
1744
+ return & groupPermission , nil
1745
+ }
1746
+
1747
+ func decodeGroupsPermissions (response interface {}) (* GroupPermissions , error ) {
1748
+ responseMap := response .(map [string ]interface {})
1749
+ values := responseMap ["values" ].([]interface {})
1750
+
1751
+ var variables []GroupPermission
1752
+ for _ , variable := range values {
1753
+ var groupPermission GroupPermission
1754
+ err := mapstructure .Decode (variable , & groupPermission )
1755
+ if err == nil {
1756
+ variables = append (variables , groupPermission )
1757
+ }
1758
+ }
1759
+
1760
+ page , ok := responseMap ["page" ].(float64 )
1761
+ if ! ok {
1762
+ page = 0
1763
+ }
1764
+
1765
+ pagelen , ok := responseMap ["pagelen" ].(float64 )
1766
+ if ! ok {
1767
+ pagelen = 0
1768
+ }
1769
+ max_depth , ok := responseMap ["max_depth" ].(float64 )
1770
+ if ! ok {
1771
+ max_depth = 0
1772
+ }
1773
+ size , ok := responseMap ["size" ].(float64 )
1774
+ if ! ok {
1775
+ size = 0
1776
+ }
1777
+
1778
+ next , ok := responseMap ["next" ].(string )
1779
+ if ! ok {
1780
+ next = ""
1781
+ }
1782
+
1783
+ groupPermissions := GroupPermissions {
1784
+ Page : int (page ),
1785
+ Pagelen : int (pagelen ),
1786
+ MaxDepth : int (max_depth ),
1787
+ Size : int (size ),
1788
+ Next : next ,
1789
+ GroupPermissions : variables ,
1790
+ }
1791
+ return & groupPermissions , nil
1792
+ }
1793
+
1794
+ func decodeUserPermissions (response interface {}) (* UserPermission , error ) {
1795
+ var userPermission UserPermission
1796
+ err := mapstructure .Decode (response , & userPermission )
1797
+ if err != nil {
1798
+ return nil , err
1799
+ }
1800
+ return & userPermission , nil
1801
+ }
1802
+
1803
+ func decodeUsersPermissions (response interface {}) (* UserPermissions , error ) {
1804
+ responseMap := response .(map [string ]interface {})
1805
+ values := responseMap ["values" ].([]interface {})
1806
+
1807
+ var variables []UserPermission
1808
+ for _ , variable := range values {
1809
+ var userPermission UserPermission
1810
+ err := mapstructure .Decode (variable , & userPermission )
1811
+ if err == nil {
1812
+ variables = append (variables , userPermission )
1813
+ }
1814
+ }
1815
+
1816
+ page , ok := responseMap ["page" ].(float64 )
1817
+ if ! ok {
1818
+ page = 0
1819
+ }
1820
+
1821
+ pagelen , ok := responseMap ["pagelen" ].(float64 )
1822
+ if ! ok {
1823
+ pagelen = 0
1824
+ }
1825
+ max_depth , ok := responseMap ["max_depth" ].(float64 )
1826
+ if ! ok {
1827
+ max_depth = 0
1828
+ }
1829
+ size , ok := responseMap ["size" ].(float64 )
1830
+ if ! ok {
1831
+ size = 0
1832
+ }
1833
+
1834
+ next , ok := responseMap ["next" ].(string )
1835
+ if ! ok {
1836
+ next = ""
1837
+ }
1838
+
1839
+ userPermissions := UserPermissions {
1840
+ Page : int (page ),
1841
+ Pagelen : int (pagelen ),
1842
+ MaxDepth : int (max_depth ),
1843
+ Size : int (size ),
1844
+ Next : next ,
1845
+ UserPermissions : variables ,
1846
+ }
1847
+ return & userPermissions , nil
1848
+ }
0 commit comments