MCPcopy Index your code
hub / github.com/rilldata/rill / githubStatus

Method githubStatus

admin/server/github.go:943–981  ·  view source on GitHub ↗

githubStatus is a http wrapper over [GetGithubRepoStatus]/[GetGithubUserStatus] depending upon whether `remote` query is passed. It redirects to the grantAccessURL if there is no access. It's implemented as a non-gRPC endpoint mounted directly on /github/post-auth-redirect.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

941// It redirects to the grantAccessURL if there is no access.
942// It's implemented as a non-gRPC endpoint mounted directly on /github/post-auth-redirect.
943func (s *Server) githubStatus(w http.ResponseWriter, r *http.Request) {
944 ctx := r.Context()
945 // Check the request is made by an authenticated user
946 claims := auth.GetClaims(ctx)
947 if claims.OwnerType() != auth.OwnerTypeUser {
948 s.redirectLogin(w, r)
949 return
950 }
951
952 var hasAccess bool
953 var grantAccessURL string
954 remote := r.URL.Query().Get("remote")
955 remote = normalizeGitRemote(remote) // Backwards compatibility
956 if remote == "" {
957 resp, err := s.GetGithubUserStatus(ctx, &adminv1.GetGithubUserStatusRequest{})
958 if err != nil {
959 http.Error(w, fmt.Sprintf("failed to fetch user status: %s", err), http.StatusInternalServerError)
960 return
961 }
962 hasAccess = resp.HasAccess
963 grantAccessURL = resp.GrantAccessUrl
964 } else {
965 resp, err := s.GetGithubRepoStatus(ctx, &adminv1.GetGithubRepoStatusRequest{Remote: remote})
966 if err != nil {
967 http.Error(w, fmt.Sprintf("failed to fetch github repo status: %s", err), http.StatusInternalServerError)
968 return
969 }
970 hasAccess = resp.HasAccess
971 grantAccessURL = resp.GrantAccessUrl
972 }
973
974 if hasAccess {
975 http.Redirect(w, r, s.admin.URLs.GithubConnectSuccessUI(false), http.StatusTemporaryRedirect)
976 return
977 }
978
979 redirectURL := s.admin.URLs.GithubConnectUI(grantAccessURL)
980 http.Redirect(w, r, redirectURL, http.StatusTemporaryRedirect)
981}
982
983func (s *Server) userAuthGithubClient(ctx context.Context, code string) (*github.Client, *admin.GithubToken, error) {
984 oauthConf := &oauth2.Config{

Callers

nothing calls this directly

Calls 12

redirectLoginMethod · 0.95
GetGithubUserStatusMethod · 0.95
GetGithubRepoStatusMethod · 0.95
GetClaimsFunction · 0.92
normalizeGitRemoteFunction · 0.85
GithubConnectUIMethod · 0.80
ContextMethod · 0.65
OwnerTypeMethod · 0.65
GetMethod · 0.65
QueryMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected