MCPcopy Index your code
hub / github.com/commitdev/zero / isOrganizationOwned

Function isOrganizationOwned

internal/vcs/create-git-repos.go:130–149  ·  view source on GitHub ↗

isOrganizationOwned will determine if ownerName is an organization. If ownerName is an organization it's id will be returned.

(ownerName string, githubApiKey string)

Source from the content-addressed store, hash-verified

128// isOrganizationOwned will determine if ownerName is an organization.
129// If ownerName is an organization it's id will be returned.
130func isOrganizationOwned(ownerName string, githubApiKey string) (bool, string, error) {
131 oRequest := graphql.NewRequest(getOrganizationQuery)
132 oRequest.Var("ownerName", ownerName)
133 oRequest.Header.Add("Authorization", fmt.Sprintf("Bearer %s", githubApiKey))
134
135 var oResponse organizationQueryResponse
136 c := graphql.NewClient("https://api.github.com/graphql")
137 ctx := context.Background()
138 if err := c.Run(ctx, oRequest, &oResponse); err != nil {
139
140 notAnOrgMessage := fmt.Sprintf("graphql: Could not resolve to an Organization with the login of '%s'.", ownerName)
141 if err.Error() == notAnOrgMessage {
142 return false, "", nil
143 }
144 return false, "", err
145 }
146 organizationId := oResponse.Organization.Id
147
148 return true, organizationId, nil
149}
150
151type initialCommands struct {
152 description string

Callers 1

InitializeRepositoryFunction · 0.85

Calls 1

ErrorMethod · 0.45

Tested by

no test coverage detected