Skip to content

Commit 197081f

Browse files
authored
Merge pull request #57 from github/check-org-membership-api
Use a better API to check organization membership.
2 parents 8894738 + 37eee5f commit 197081f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

internal/push/push.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ func (pushService *pushService) createRepository() (*github.Repository, error) {
9999
}
100100
}
101101

102-
_, response, err = pushService.githubEnterpriseClient.Organizations.GetOrgMembership(pushService.ctx, user.GetLogin(), pushService.destinationRepositoryOwner)
103-
if err != nil && (response == nil || response.StatusCode != http.StatusNotFound) {
102+
_, response, err = pushService.githubEnterpriseClient.Organizations.IsMember(pushService.ctx, pushService.destinationRepositoryOwner, user.GetLogin())
103+
if err != nil {
104104
return nil, errors.Wrap(err, "Failed to check membership of destination organization.")
105105
}
106-
if err != nil && githubapiutil.HasAnyScope(response, "site_admin") {
107-
log.Debugf("No access to destination organization. Switching to impersonation token for %s...", pushService.actionsAdminUser)
106+
if (response.StatusCode == http.StatusFound || response.StatusCode == http.StatusNotFound) && githubapiutil.HasAnyScope(response, "site_admin") {
107+
log.Debugf("No access to destination organization (status code %d). Switching to impersonation token for %s...", response.StatusCode, pushService.actionsAdminUser)
108108
impersonationToken, _, err := pushService.githubEnterpriseClient.Admin.CreateUserImpersonation(pushService.ctx, pushService.actionsAdminUser, &github.ImpersonateUserOptions{Scopes: []string{minimumRepositoryScope, "workflow"}})
109109
if err != nil {
110110
return nil, errors.Wrap(err, "Failed to impersonate Actions admin user.")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy