mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-20 23:35:59 +00:00
rework to delete the repository from the datastore if there are previous errors from the remote
This commit is contained in:
@@ -256,7 +256,7 @@ func DeleteKey(client *github.Client, owner, name, title, key string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%s not found in the list of keys", title)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateKey is a helper function that creates a deploy key
|
// CreateKey is a helper function that creates a deploy key
|
||||||
|
@@ -156,7 +156,7 @@ func (r *Gogs) Activate(user *model.User, repo *model.Repo, link string) error {
|
|||||||
// Deactivate removes a repository by removing all the post-commit hooks
|
// Deactivate removes a repository by removing all the post-commit hooks
|
||||||
// which are equal to link and removing the SSH deploy key.
|
// which are equal to link and removing the SSH deploy key.
|
||||||
func (r *Gogs) Deactivate(user *model.User, repo *model.Repo, link string) error {
|
func (r *Gogs) Deactivate(user *model.User, repo *model.Repo, link string) error {
|
||||||
return fmt.Errorf("Remove %#v in gots not implemented", *repo)
|
return fmt.Errorf("Remove %#v in gogs not implemented", *repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseHook parses the post-commit hook from the Request body
|
// ParseHook parses the post-commit hook from the Request body
|
||||||
|
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/drone/drone/plugin/remote"
|
"github.com/drone/drone/plugin/remote"
|
||||||
"github.com/drone/drone/server/datastore"
|
"github.com/drone/drone/server/datastore"
|
||||||
|
"github.com/drone/drone/shared/build/log"
|
||||||
"github.com/drone/drone/shared/httputil"
|
"github.com/drone/drone/shared/httputil"
|
||||||
"github.com/drone/drone/shared/model"
|
"github.com/drone/drone/shared/model"
|
||||||
"github.com/drone/drone/shared/sshutil"
|
"github.com/drone/drone/shared/sshutil"
|
||||||
@@ -59,33 +60,34 @@ func DelRepo(c web.C, w http.ResponseWriter, r *http.Request) {
|
|||||||
var user = ToUser(c)
|
var user = ToUser(c)
|
||||||
var remote = remote.Lookup(repo.Host)
|
var remote = remote.Lookup(repo.Host)
|
||||||
if remote == nil {
|
if remote == nil {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
log.Errf("no remote for host '%s' found", repo.Host)
|
||||||
return
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
// Request a new token and update
|
// Request a new token and update
|
||||||
user_token, err := remote.GetToken(user)
|
user_token, err := remote.GetToken(user)
|
||||||
|
if err != nil {
|
||||||
|
log.Errf("no token for user '%s' on remote '%s' ", repo.Host)
|
||||||
|
} else {
|
||||||
if user_token != nil {
|
if user_token != nil {
|
||||||
user.Access = user_token.AccessToken
|
user.Access = user_token.AccessToken
|
||||||
user.Secret = user_token.RefreshToken
|
user.Secret = user_token.RefreshToken
|
||||||
datastore.PutUser(ctx, user)
|
datastore.PutUser(ctx, user)
|
||||||
} else if err != nil {
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup the post-commit hook with the remote system and
|
// setup the post-commit hook with the remote system and
|
||||||
// if necessary, register the public key
|
// and deactiveate this hook/user on the remote system
|
||||||
var hook = fmt.Sprintf("%s/api/hook/%s/%s", httputil.GetURL(r), repo.Remote, repo.Token)
|
var hook = fmt.Sprintf("%s/api/hook/%s/%s", httputil.GetURL(r), repo.Remote, repo.Token)
|
||||||
if err := remote.Deactivate(user, repo, hook); err != nil {
|
if err := remote.Deactivate(user, repo, hook); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
log.Errf("deactivate on remote '%s' failed: %s", repo.Host, err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// fail through: if any of the actions on the remote failed
|
||||||
|
// we try to delete the repo in our datastore anyway
|
||||||
if err := datastore.DelRepo(ctx, repo); err != nil {
|
if err := datastore.DelRepo(ctx, repo); err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
} else {
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// disable everything
|
// disable everything
|
||||||
|
Reference in New Issue
Block a user