Esempio n. 1
0
func (c *Config) Repo(u *model.User, owner, name string) (*model.Repo, error) {
	repo, err := internal.NewClientWithToken(c.URL, c.Consumer, u.Token).FindRepo(owner, name)
	if err != nil {
		return nil, err
	}
	return convertRepo(repo), nil
}
Esempio n. 2
0
func (c *Config) Login(res http.ResponseWriter, req *http.Request) (*model.User, error) {
	requestToken, url, err := c.Consumer.GetRequestTokenAndUrl("oob")
	if err != nil {
		return nil, err
	}
	var code = req.FormValue("oauth_verifier")
	if len(code) == 0 {
		http.Redirect(res, req, url, http.StatusSeeOther)
		return nil, nil
	}
	requestToken.Token = req.FormValue("oauth_token")
	accessToken, err := c.Consumer.AuthorizeToken(requestToken, code)
	if err != nil {
		return nil, err
	}

	client := internal.NewClientWithToken(c.URL, c.Consumer, accessToken.Token)

	user, err := client.FindCurrentUser()
	if err != nil {
		return nil, err
	}

	return convertUser(user, accessToken), nil

}
Esempio n. 3
0
func (c *Config) Repos(u *model.User) ([]*model.RepoLite, error) {
	repos, err := internal.NewClientWithToken(c.URL, c.Consumer, u.Token).FindRepos()
	if err != nil {
		return nil, err
	}
	var all []*model.RepoLite
	for _, repo := range repos {
		all = append(all, convertRepoLite(repo))
	}

	return all, nil
}
Esempio n. 4
0
// Status is not supported by the bitbucketserver driver.
func (c *Config) Status(u *model.User, r *model.Repo, b *model.Build, link string) error {
	status := internal.BuildStatus{
		State: convertStatus(b.Status),
		Desc:  convertDesc(b.Status),
		Name:  fmt.Sprintf("Drone #%d - %s", b.Number, b.Branch),
		Key:   "Drone",
		Url:   link,
	}

	client := internal.NewClientWithToken(c.URL, c.Consumer, u.Token)

	return client.CreateStatus(b.Commit, &status)
}
Esempio n. 5
0
func (c *Config) Deactivate(u *model.User, r *model.Repo, link string) error {
	client := internal.NewClientWithToken(c.URL, c.Consumer, u.Token)
	return client.DeleteHook(r.Owner, r.Name, link)
}
Esempio n. 6
0
func (c *Config) File(u *model.User, r *model.Repo, b *model.Build, f string) ([]byte, error) {
	client := internal.NewClientWithToken(c.URL, c.Consumer, u.Token)

	return client.FindFileForRepo(r.Owner, r.Name, f, b.Ref)
}
Esempio n. 7
0
func (c *Config) Perm(u *model.User, owner, repo string) (*model.Perm, error) {
	client := internal.NewClientWithToken(c.URL, c.Consumer, u.Token)

	return client.FindRepoPerms(owner, repo)
}