2015-04-09 00:00:27 +02:00
|
|
|
package remote
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
"github.com/drone/drone/model"
|
|
|
|
"github.com/drone/drone/remote/github"
|
|
|
|
"github.com/drone/drone/remote/gitlab"
|
|
|
|
"github.com/drone/drone/shared/envconfig"
|
2015-08-06 17:54:47 +02:00
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
log "github.com/Sirupsen/logrus"
|
2015-04-09 00:00:27 +02:00
|
|
|
)
|
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
func Load(env envconfig.Env) Remote {
|
|
|
|
driver := env.Get("REMOTE_DRIVER")
|
2015-07-24 21:44:02 +02:00
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
switch driver {
|
|
|
|
case "github":
|
|
|
|
return github.Load(env)
|
|
|
|
case "gitlab":
|
|
|
|
return gitlab.Load(env)
|
2015-07-24 21:44:02 +02:00
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
default:
|
|
|
|
log.Fatalf("unknown remote driver %s", driver)
|
2015-07-24 21:44:02 +02:00
|
|
|
}
|
2015-09-30 03:21:17 +02:00
|
|
|
|
|
|
|
return nil
|
2015-07-24 21:44:02 +02:00
|
|
|
}
|
|
|
|
|
2015-04-09 00:00:27 +02:00
|
|
|
type Remote interface {
|
|
|
|
// Login authenticates the session and returns the
|
|
|
|
// remote user details.
|
2015-09-30 03:21:17 +02:00
|
|
|
Login(w http.ResponseWriter, r *http.Request) (*model.User, bool, error)
|
2015-04-09 00:00:27 +02:00
|
|
|
|
2015-09-30 03:21:17 +02:00
|
|
|
// Auth authenticates the session and returns the remote user
|
|
|
|
// login for the given token and secret
|
|
|
|
Auth(token, secret string) (string, error)
|
2015-04-15 09:20:00 +02:00
|
|
|
|
2015-04-09 00:00:27 +02:00
|
|
|
// Repo fetches the named repository from the remote system.
|
2015-09-30 03:21:17 +02:00
|
|
|
Repo(u *model.User, owner, repo string) (*model.Repo, error)
|
|
|
|
|
|
|
|
// Repos fetches a list of repos from the remote system.
|
|
|
|
Repos(u *model.User) ([]*model.RepoLite, error)
|
2015-04-09 00:00:27 +02:00
|
|
|
|
2015-04-22 00:48:06 +02:00
|
|
|
// Perm fetches the named repository permissions from
|
|
|
|
// the remote system for the specified user.
|
2015-09-30 03:21:17 +02:00
|
|
|
Perm(u *model.User, owner, repo string) (*model.Perm, error)
|
2015-04-09 00:00:27 +02:00
|
|
|
|
|
|
|
// Script fetches the build script (.drone.yml) from the remote
|
|
|
|
// repository and returns in string format.
|
2015-09-30 03:21:17 +02:00
|
|
|
Script(u *model.User, r *model.Repo, b *model.Build) ([]byte, []byte, error)
|
2015-04-09 00:00:27 +02:00
|
|
|
|
|
|
|
// Status sends the commit status to the remote system.
|
|
|
|
// An example would be the GitHub pull request status.
|
2015-09-30 03:21:17 +02:00
|
|
|
Status(u *model.User, r *model.Repo, b *model.Build, link string) error
|
2015-04-09 00:00:27 +02:00
|
|
|
|
2015-04-28 23:39:48 +02:00
|
|
|
// Netrc returns a .netrc file that can be used to clone
|
|
|
|
// private repositories from a remote system.
|
2015-09-30 03:21:17 +02:00
|
|
|
Netrc(u *model.User, r *model.Repo) (*model.Netrc, error)
|
2015-04-28 23:39:48 +02:00
|
|
|
|
2015-04-09 00:00:27 +02:00
|
|
|
// Activate activates a repository by creating the post-commit hook and
|
|
|
|
// adding the SSH deploy key, if applicable.
|
2015-09-30 03:21:17 +02:00
|
|
|
Activate(u *model.User, r *model.Repo, k *model.Key, link string) error
|
2015-04-09 00:00:27 +02:00
|
|
|
|
|
|
|
// Deactivate removes a repository by removing all the post-commit hooks
|
|
|
|
// which are equal to link and removing the SSH deploy key.
|
2015-09-30 03:21:17 +02:00
|
|
|
Deactivate(u *model.User, r *model.Repo, link string) error
|
2015-04-09 00:00:27 +02:00
|
|
|
|
|
|
|
// Hook parses the post-commit hook from the Request body
|
|
|
|
// and returns the required data in a standard format.
|
2015-09-30 03:21:17 +02:00
|
|
|
Hook(r *http.Request) (*model.Repo, *model.Build, error)
|
2015-04-09 00:00:27 +02:00
|
|
|
}
|