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

Method detectGitRemoteAndProject

cli/cmd/project/deploy.go:200–257  ·  view source on GitHub ↗
(ctx context.Context, ch *cmdutil.Helper, repoRoot, subpath string)

Source from the content-addressed store, hash-verified

198}
199
200func (o *DeployOpts) detectGitRemoteAndProject(ctx context.Context, ch *cmdutil.Helper, repoRoot, subpath string) error {
201 remotes, err := gitutil.ExtractRemotes(repoRoot, false)
202 if err != nil && !errors.Is(err, gitutil.ErrGitRemoteNotFound) {
203 return err
204 }
205 c, err := ch.Client()
206 if err != nil {
207 return err
208 }
209
210 // find matching projects
211 req := &adminv1.ListProjectsForFingerprintRequest{
212 DirectoryName: filepath.Base(o.LocalProjectPath()),
213 SubPath: subpath,
214 }
215 for _, remote := range remotes {
216 switch remote.Name {
217 case "__rill_remote":
218 req.RillMgdGitRemote = remote.URL
219 case o.RemoteName:
220 gitremote, err := remote.Github()
221 if err == nil {
222 req.GitRemote = gitremote
223 }
224 }
225 }
226 resp, err := c.ListProjectsForFingerprint(ctx, req)
227 if err != nil {
228 // TODO: check for not found error
229 return err
230 }
231 if resp.UnauthorizedProject != "" {
232 ch.PrintfWarn("You do not have access to the project %q which is connected to this repository. Please reach out to your Rill admin\n", resp.UnauthorizedProject)
233 return fmt.Errorf("aborting deploy")
234 }
235 for _, p := range resp.Projects {
236 if p.ManagedGitId != "" {
237 o.pushToProject = p
238 o.remoteURL = p.GitRemote
239 return nil
240 }
241 o.pushToProject = p
242 o.remoteURL = p.GitRemote
243 // do not return yet, there might be a managed project
244 // this is not possible with new flow but keeping it for consistency
245 }
246
247 if len(resp.Projects) == 1 && resp.Projects[0].ManagedGitId == "" && req.RillMgdGitRemote != "" {
248 err = ch.HandleRepoTransfer(repoRoot, req.GitRemote)
249 if err != nil {
250 return err
251 }
252 }
253 if req.GitRemote != "" {
254 o.remoteURL = req.GitRemote
255 }
256 return nil
257}

Callers 1

Calls 8

LocalProjectPathMethod · 0.95
ExtractRemotesFunction · 0.92
GithubMethod · 0.80
PrintfWarnMethod · 0.80
HandleRepoTransferMethod · 0.80
ErrorfMethod · 0.65
ClientMethod · 0.45

Tested by

no test coverage detected