(ctx context.Context, ch *cmdutil.Helper, localGitPath string)
| 231 | } |
| 232 | |
| 233 | func createGithubRepoFlow(ctx context.Context, ch *cmdutil.Helper, localGitPath string) error { |
| 234 | // Get the admin client |
| 235 | c, err := ch.Client() |
| 236 | if err != nil { |
| 237 | return err |
| 238 | } |
| 239 | |
| 240 | res, err := c.GetGithubUserStatus(ctx, &adminv1.GetGithubUserStatusRequest{}) |
| 241 | if err != nil { |
| 242 | return err |
| 243 | } |
| 244 | |
| 245 | if !res.HasAccess { |
| 246 | ch.Telemetry(ctx).RecordBehavioralLegacy(activity.BehavioralEventGithubConnectedStart) |
| 247 | |
| 248 | if res.GrantAccessUrl != "" { |
| 249 | // Print instructions to grant access |
| 250 | ch.Print("Open this URL in your browser to grant Rill access to Github:\n\n") |
| 251 | ch.Print("\t" + res.GrantAccessUrl + "\n\n") |
| 252 | |
| 253 | // Open browser if possible |
| 254 | if ch.Interactive { |
| 255 | _ = browser.Open(res.GrantAccessUrl) |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | // Poll for permission granted |
| 261 | pollCtx, cancel := context.WithTimeout(ctx, pollTimeout) |
| 262 | defer cancel() |
| 263 | var pollRes *adminv1.GetGithubUserStatusResponse |
| 264 | for { |
| 265 | select { |
| 266 | case <-pollCtx.Done(): |
| 267 | return pollCtx.Err() |
| 268 | case <-time.After(pollInterval): |
| 269 | // Ready to check again. |
| 270 | } |
| 271 | |
| 272 | // Poll for access to the Github's user account |
| 273 | pollRes, err = c.GetGithubUserStatus(ctx, &adminv1.GetGithubUserStatusRequest{}) |
| 274 | if err != nil { |
| 275 | return err |
| 276 | } |
| 277 | if pollRes.HasAccess { |
| 278 | break |
| 279 | } |
| 280 | // Sleep and poll again |
| 281 | } |
| 282 | |
| 283 | // Emit success telemetry |
| 284 | ch.Telemetry(ctx).RecordBehavioralLegacy(activity.BehavioralEventGithubConnectedSuccess) |
| 285 | |
| 286 | // get orgs on which rill github app is installed with write permission |
| 287 | var candidateOrgs []string |
| 288 | if pollRes.UserInstallationPermission == adminv1.GithubPermission_GITHUB_PERMISSION_WRITE { |
| 289 | candidateOrgs = append(candidateOrgs, pollRes.Account) |
| 290 | } |
no test coverage detected