@@ -29,7 +29,7 @@ var repoAccessLevels = []string{
2929}
3030
3131// repositoryResource returns a new connector resource for a Github repository.
32- func repositoryResource (ctx context.Context , orgName string , repo * github.Repository , parentResourceID * v2.ResourceId ) (* v2.Resource , error ) {
32+ func repositoryResource (ctx context.Context , repo * github.Repository , parentResourceID * v2.ResourceId ) (* v2.Resource , error ) {
3333 var annos annotations.Annotations
3434 annos .Append (& v2.ExternalLink {
3535 Url : repo .GetHTMLURL (),
@@ -38,17 +38,14 @@ func repositoryResource(ctx context.Context, orgName string, repo *github.Reposi
3838 Id : fmt .Sprintf ("repo:%d" , repo .GetID ()),
3939 })
4040
41- resourceID , err := sdk .NewResourceID ( resourceTypeRepository , parentResourceID , repo .GetID ())
41+ ret , err := sdk .NewResource ( repo . GetName (), resourceTypeRepository , parentResourceID , repo .GetID ())
4242 if err != nil {
4343 return nil , err
4444 }
4545
46- return & v2.Resource {
47- Id : resourceID ,
48- DisplayName : repo .GetName (),
49- ParentResourceId : parentResourceID ,
50- Annotations : annos ,
51- }, nil
46+ ret .Annotations = annos
47+
48+ return ret , nil
5249}
5350
5451type repositoryResourceType struct {
@@ -70,7 +67,10 @@ func (o *repositoryResourceType) List(ctx context.Context, parentID *v2.Resource
7067 return nil , "" , nil , err
7168 }
7269
73- orgName := getOrgName (parentID )
70+ orgName , err := getOrgName (ctx , o .client , parentID )
71+ if err != nil {
72+ return nil , "" , nil , err
73+ }
7474
7575 opts := & github.RepositoryListByOrgOptions {
7676 ListOptions : github.ListOptions {
@@ -96,7 +96,7 @@ func (o *repositoryResourceType) List(ctx context.Context, parentID *v2.Resource
9696
9797 rv := make ([]* v2.Resource , 0 , len (repos ))
9898 for _ , repo := range repos {
99- rr , err := repositoryResource (ctx , orgName , repo , parentID )
99+ rr , err := repositoryResource (ctx , repo , parentID )
100100 if err != nil {
101101 return nil , "" , nil , err
102102 }
@@ -113,16 +113,13 @@ func (o *repositoryResourceType) Entitlements(_ context.Context, resource *v2.Re
113113 annos .Append (& v2.V1Identifier {
114114 Id : fmt .Sprintf ("repo:%s:role:%s" , resource .Id , level ),
115115 })
116- rv = append (rv , & v2.Entitlement {
117- Id : sdk .NewEntitlementID (resource , level ),
118- Resource : resource ,
119- DisplayName : fmt .Sprintf ("%s Repo %s" , resource .DisplayName , titleCaser .String (level )),
120- Description : fmt .Sprintf ("Access to %s repository in Github" , resource .DisplayName ),
121- Annotations : annos ,
122- GrantableTo : []* v2.ResourceType {resourceTypeUser , resourceTypeTeam },
123- Purpose : v2 .Entitlement_PURPOSE_VALUE_PERMISSION ,
124- Slug : level ,
125- })
116+
117+ en := sdk .NewPermissionEntitlement (resource , level , resourceTypeUser , resourceTypeTeam )
118+ en .DisplayName = fmt .Sprintf ("%s Repo %s" , resource .DisplayName , titleCaser .String (level ))
119+ en .Description = fmt .Sprintf ("Access to %s repository in Github" , resource .DisplayName )
120+ en .Annotations = annos
121+
122+ rv = append (rv , en )
126123 }
127124
128125 return rv , "" , nil , nil
@@ -138,7 +135,10 @@ func (o *repositoryResourceType) Grants(
138135 return nil , "" , nil , err
139136 }
140137
141- orgName := getOrgName (resource .Id )
138+ orgName , err := getOrgName (ctx , o .client , resource .ParentResourceId )
139+ if err != nil {
140+ return nil , "" , nil , err
141+ }
142142
143143 var rv []* v2.Grant
144144 var reqAnnos annotations.Annotations
@@ -191,17 +191,10 @@ func (o *repositoryResourceType) Grants(
191191 return nil , "" , nil , err
192192 }
193193
194- en := & v2.Entitlement {
195- Id : sdk .NewEntitlementID (resource , permission ),
196- Resource : resource ,
197- }
194+ grant := sdk .NewGrant (resource , permission , ur .Id )
195+ grant .Annotations = annos
198196
199- rv = append (rv , & v2.Grant {
200- Entitlement : en ,
201- Id : sdk .NewGrantID (en , ur ),
202- Principal : ur ,
203- Annotations : annos ,
204- })
197+ rv = append (rv , grant )
205198 }
206199 }
207200
@@ -237,22 +230,15 @@ func (o *repositoryResourceType) Grants(
237230 Id : fmt .Sprintf ("repo-grant:%s:%d:%s" , resource .Id .Resource , team .GetID (), permission ),
238231 })
239232
240- tr , err := teamResource (ctx , orgName , team , resource .ParentResourceId )
233+ tr , err := teamResource (team , resource .ParentResourceId )
241234 if err != nil {
242235 return nil , "" , nil , err
243236 }
244237
245- en := & v2.Entitlement {
246- Id : sdk .NewEntitlementID (resource , permission ),
247- Resource : resource ,
248- }
238+ grant := sdk .NewGrant (resource , permission , tr .Id )
239+ grant .Annotations = annos
249240
250- rv = append (rv , & v2.Grant {
251- Entitlement : en ,
252- Id : sdk .NewGrantID (en , tr ),
253- Principal : tr ,
254- Annotations : annos ,
255- })
241+ rv = append (rv , grant )
256242 }
257243 }
258244 default :
0 commit comments