Skip to content

Commit

Permalink
adding github testing
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Mar 12, 2014
1 parent 265138c commit d70a6bb
Show file tree
Hide file tree
Showing 3 changed files with 447 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/database/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func Setup() {
database.SaveMember(user1.ID, team2.ID, RoleOwner)
database.SaveMember(user2.ID, team2.ID, RoleAdmin)
database.SaveMember(user3.ID, team2.ID, RoleWrite)
database.SaveMember(user1.ID, team3.ID, RoleOwner)
database.SaveMember(user1.ID, team3.ID, RoleRead)

// create dummy repo data
repo1 := Repo{
Expand Down
15 changes: 6 additions & 9 deletions pkg/handler/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package handler

import (
"fmt"
"log"
"net/http"

"github.com/drone/drone/pkg/channel"
Expand Down Expand Up @@ -87,7 +86,7 @@ func RepoCreateGithub(w http.ResponseWriter, r *http.Request, u *User) error {
client.ApiUrl = settings.GitHubApiUrl
githubRepo, err := client.Repos.Find(owner, name)
if err != nil {
return err
return fmt.Errorf("Unable to find GitHub repository %s/%s.", owner, name)
}

repo, err := NewGitHubRepo(settings.GitHubDomain, owner, name, githubRepo.Private)
Expand All @@ -104,13 +103,12 @@ func RepoCreateGithub(w http.ResponseWriter, r *http.Request, u *User) error {
if len(teamName) > 0 {
team, err := database.GetTeamSlug(teamName)
if err != nil {
log.Printf("error retrieving team %s", teamName)
return err
return fmt.Errorf("Unable to find Team %s.", teamName)
}

// user must be an admin member of the team
if ok, _ := database.IsMemberAdmin(u.ID, team.ID); !ok {
return fmt.Errorf("Forbidden")
return fmt.Errorf("Invalid permission to access Team %s.", teamName)
}

repo.TeamID = team.ID
Expand All @@ -125,7 +123,7 @@ func RepoCreateGithub(w http.ResponseWriter, r *http.Request, u *User) error {
// create the github key, or update if one already exists
_, err := client.RepoKeys.CreateUpdate(owner, name, repo.PublicKey, keyName)
if err != nil {
return fmt.Errorf("Unable to add Public Key to your GitHub repository")
return fmt.Errorf("Unable to add Public Key to your GitHub repository.")
}
} else {

Expand All @@ -137,13 +135,12 @@ func RepoCreateGithub(w http.ResponseWriter, r *http.Request, u *User) error {

// add the hook
if _, err := client.Hooks.CreateUpdate(owner, name, link); err != nil {
return fmt.Errorf("Unable to add Hook to your GitHub repository. %s", err.Error())
return fmt.Errorf("Unable to add Hook to your GitHub repository.")
}

// Save to the database
if err := database.SaveRepo(repo); err != nil {
log.Print("error saving new repository to the database")
return err
return fmt.Errorf("Error saving repository to the database. %s", err)
}

return RenderText(w, http.StatusText(http.StatusOK), http.StatusOK)
Expand Down
Loading

0 comments on commit d70a6bb

Please sign in to comment.