google / google/go-github

How to ensure that a repository has been synced to the Github servers?

Aperta
#3,366 2 commenti 2 reazioni 0 assegnatari Vedi su GitHub
waiting for reply
Lingua principale
Go
Stelle
11.3k
Fork
2.5k
Merge medio
1g 20h
PR unite (30g)
52

Descrizione

The documentation for `RepositoriesService.Create` states that

> Also note that this method will return the response without actually
waiting for GitHub to finish creating the repository and letting the
changes propagate throughout its servers. You may set up a loop with
exponential back-off to verify repository's creation.

However, doing so does not seem to be sufficient to ensure that a new repository has been synced.

I'm trying to create a new repository and enable Github Advanced Security features after it. The `Update` request returns a 200 and the result also indicates a success (the updated fields contain the value "enabled" which is what I wanted to achieve). When validating the result on github.com the features are disabled.
When I tried to sleep for a couple of seconds after creating and before updating the repo, the result is also visible on github.com.

Here is my code to reproduce the issue:
```go
package main

import (
"context"
"fmt"
"time"

"github.com/google/go-github/v67/github"
log "github.com/sirupsen/logrus"
)

func main() {
org := "some-org"
name := "some-repo"
token := "some-token"

client := github.NewClient(nil).WithAuthToken(token)
_, _, err := client.Repositories.Create(context.Background(), org, &github.Repository{
Name: github.String(name),
AutoInit: github.Bool(true),
Visibility: github.String("internal"),
DefaultBranch: github.String("main"),
})
if err != nil {
log.WithError(err).Fatal("unable to create repository")
}
maxRetries := 5
for i := 0; i < maxRetries; i++ {
_, _, err := client.Repositories.Get(context.Background(), org, name)
if err == nil {
break
}
if i == maxRetries-1 {
log.Fatal("unable to verify repository creation")
}
time.Sleep(time.Duration(i*2) * time.Second)
}

// time.Sleep(5 * time.Second)

repo := github.Repository{
SecurityAndAnalysis: &github.SecurityAndAnalysis{
AdvancedSecurity: &github.AdvancedSecurity{
Status: github.String("enabled"),
},
SecretScanning: &github.SecretScanning{
Status: github.String("enabled"),
},
},
}
updatedRepo, _, err := client.Repositories.Edit(context.Background(), org, name, &repo)
if err != nil {
log.Fatal("unable to enable Advanced Security")
}
fmt.Printf("Advanced Security: %s\n", *updatedRepo.SecurityAndAnalysis.AdvancedSecurity.Status)
fmt.Printf("Secret Scanning: %s\n", *updatedRepo.SecurityAndAnalysis.SecretScanning.Status)
}
```
No matter if I sleep the 5 seconds or not, both run print
```
Advanced Security: enabled
Secret Scanning: enabled
```

github.com without sleeping

![Image](https://github.com/user-attachments/assets/085ee3d8-8d16-4d31-a569-691ae3134d73)

github.com with sleeping

![Image](https://github.com/user-attachments/assets/34862738-51c2-496f-8fec-4f640fe845a4)

Any idea how I can make sure that the repository is ready to enable Advanced Security features? (I'm not sure if other updates are affected as well)

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con le chiamate RepositoriesService.Create, Get ed Edit mostrate nella riproduzione, quindi confronta le relative risposte API con lo stato del repository su github.com. Determina se il client espone un controllo affidabile della disponibilità per abilitare Advanced Security e Secret Scanning e documenta il comportamento supportato o la limitazione quando il repository è ancora in fase di propagazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
github, go
Ambito
api, backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.