Skip to content

Commit

Permalink
Use a better API to check organization membership.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgavin committed Mar 2, 2021
1 parent 3346397 commit 346185e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ func (pushService *pushService) createRepository() (*github.Repository, error) {
}
}

_, response, err = pushService.githubEnterpriseClient.Organizations.GetOrgMembership(pushService.ctx, user.GetLogin(), pushService.destinationRepositoryOwner)
if err != nil && (response == nil || response.StatusCode != http.StatusNotFound) {
_, response, err = pushService.githubEnterpriseClient.Organizations.IsMember(pushService.ctx, user.GetLogin(), pushService.destinationRepositoryOwner)
if err != nil {
return nil, errors.Wrap(err, "Failed to check membership of destination organization.")
}
if err != nil && githubapiutil.HasAnyScope(response, "site_admin") {
if (response.StatusCode == http.StatusFound || response.StatusCode == http.StatusNotFound) && githubapiutil.HasAnyScope(response, "site_admin") {
log.Debugf("No access to destination organization. Switching to impersonation token for %s...", pushService.actionsAdminUser)
impersonationToken, _, err := pushService.githubEnterpriseClient.Admin.CreateUserImpersonation(pushService.ctx, pushService.actionsAdminUser, &github.ImpersonateUserOptions{Scopes: []string{minimumRepositoryScope, "workflow"}})
if err != nil {
Expand Down

0 comments on commit 346185e

Please sign in to comment.