isOrganizationOwned will determine if ownerName is an organization. If ownerName is an organization it's id will be returned.
(ownerName string, githubApiKey string)
| 128 | // isOrganizationOwned will determine if ownerName is an organization. |
| 129 | // If ownerName is an organization it's id will be returned. |
| 130 | func 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 | |
| 151 | type initialCommands struct { |
| 152 | description string |
no test coverage detected