( context context.Context, orgID string, number int, )
| 1143 | } |
| 1144 | |
| 1145 | func (c *cli) getOrgInvitations( |
| 1146 | context context.Context, |
| 1147 | orgID string, |
| 1148 | number int, |
| 1149 | ) ([]management.OrganizationInvitation, error) { |
| 1150 | list, err := getWithPagination( |
| 1151 | number, |
| 1152 | func(opts ...management.RequestOption) (result []interface{}, hasNext bool, apiErr error) { |
| 1153 | // Add sort option to existing opts. |
| 1154 | opts = append(opts, management.Sort("created_at:-1")) |
| 1155 | invitations, apiErr := c.api.Organization.Invitations(context, url.PathEscape(orgID), opts...) |
| 1156 | if apiErr != nil { |
| 1157 | return nil, false, apiErr |
| 1158 | } |
| 1159 | var output []interface{} |
| 1160 | for _, invitation := range invitations.OrganizationInvitations { |
| 1161 | if invitation != nil { |
| 1162 | output = append(output, *invitation) |
| 1163 | } |
| 1164 | } |
| 1165 | // Invitations does not return total count yet, so we determine there is a next page if current page is not empty. |
| 1166 | return output, !isEmptyInvitationList(invitations), nil |
| 1167 | }, |
| 1168 | ) |
| 1169 | if err != nil { |
| 1170 | return nil, fmt.Errorf("failed to list invitations of organization with ID %q: %w", orgID, err) |
| 1171 | } |
| 1172 | |
| 1173 | var typedList []management.OrganizationInvitation |
| 1174 | for _, item := range list { |
| 1175 | typedList = append(typedList, item.(management.OrganizationInvitation)) |
| 1176 | } |
| 1177 | |
| 1178 | return typedList, nil |
| 1179 | } |
| 1180 | |
| 1181 | func isEmptyInvitationList(invs *management.OrganizationInvitationList) bool { |
| 1182 | return invs == nil || len(invs.OrganizationInvitations) == 0 |
no test coverage detected