Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions app/gitopia.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ package app
import (
"context"

"github.com/pkg/errors"
"github.com/spf13/viper"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz"
"github.com/gitopia/git-server/logger"
"github.com/gitopia/gitopia/x/gitopia/types"
"github.com/pkg/errors"
"github.com/spf13/viper"
"github.com/tendermint/starport/starport/pkg/cosmosaccount"
"github.com/tendermint/starport/starport/pkg/cosmosclient"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/authz"
)

const (
Expand All @@ -37,7 +35,8 @@ func NewGitopiaClient(ctx context.Context, account string) (GitopiaClient, error
client, err := cosmosclient.New(ctx,
cosmosclient.WithNodeAddress(viper.GetString("tm_addr")),
//cosmosclient.WithKeyringServiceName("cosmos"), // not suported on macos
cosmosclient.WithKeyringBackend(cosmosaccount.KeyringOS),
cosmosclient.WithKeyringBackend(cosmosaccount.KeyringTest),
cosmosclient.WithHome(viper.GetString("keyring_dir")),
cosmosclient.WithAddressPrefix(GITOPIA_ACC_ADDRESS_PREFIX),
)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion config_dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ gitopia_grpc_url = "grpc.gitopia.dev:9090"
git_dir = "/var/repos"
attachment_dir = "/var/attachments"
tm_addr = "http://grpc.gitopia.dev:26657"
key_name = "git-server"
key_name = "git-server"
keyring_dir = "/home/ubuntu/git-server"
3 changes: 2 additions & 1 deletion config_local.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ gitopia_grpc_url = "localhost:9090"
git_dir = "/var/repos"
attachment_dir = "/var/attachments"
tm_addr = "http://localhost:26657"
key_name = "git-server"
key_name = "git-server"
keyring_dir = ""
3 changes: 2 additions & 1 deletion config_prod.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ gitopia_grpc_url = "grpc.gitopia.com:9090"
git_dir = "/var/repos"
attachment_dir = "/var/attachments"
tm_addr = "http://grpc.gitopia.com:26657"
key_name = "git-server"
key_name = "git-server"
keyring_dir = "/home/ubuntu/git-server"
43 changes: 15 additions & 28 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,13 @@ import (
"google.golang.org/grpc/credentials/insecure"
)

const MAX_UPLOAD_SIZE = 2 * 1024 * 1024 * 1024 // 2GB

type uploadAttachmentResponse struct {
Sha string `json:"sha"`
Size int64 `json:"size"`
}

type forkRepositoryPostBody struct {
SourceRepositoryID uint64 `json:"source_repository_id"`
TargetRepositoryID uint64 `json:"target_repository_id"`
}

type forkRepositoryResponseData struct {
Forked bool `json:"forked"`
}

type forkRepositoryResponse struct {
Data forkRepositoryResponseData `json:"data"`
Error string `json:"error"`
}

type pullRequestCheckResponseData struct {
IsMergeable bool `json:"is_mergeable"`
}
Expand All @@ -50,17 +38,12 @@ type pullRequestCheckResponse struct {
Error string `json:"error"`
}

type pullRequestMergeResponseData struct {
Merged bool `json:"merged"`
MergeCommitSha string `json:"merge_commit_sha"`
}

type pullRequestMergeResponse struct {
Data pullRequestMergeResponseData `json:"data"`
Error string `json:"error"`
}

func uploadAttachmentHandler(w http.ResponseWriter, r *http.Request) {
r.Body = http.MaxBytesReader(w, r.Body, MAX_UPLOAD_SIZE)
if err := r.ParseMultipartForm(MAX_UPLOAD_SIZE); err != nil {
http.Error(w, "The uploaded file is too big. Please choose an file that's less than 2GB in size", http.StatusBadRequest)
return
}

err := r.ParseMultipartForm(32 << 20)
if err != nil {
Expand All @@ -85,11 +68,19 @@ func uploadAttachmentHandler(w http.ResponseWriter, r *http.Request) {

sha := sha256.New()
_, err = io.Copy(io.MultiWriter(sha, tmpFile), file)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

attachmentDir := viper.GetString("attachment_dir")
shaString := hex.EncodeToString(sha.Sum(nil))
filePath := fmt.Sprintf("%s/%s", attachmentDir, shaString)
localFile, err := os.Create(filePath)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer localFile.Close()

tmpFile.Seek(0, io.SeekStart)
Expand All @@ -108,8 +99,6 @@ func uploadAttachmentHandler(w http.ResponseWriter, r *http.Request) {
}

json.NewEncoder(w).Encode(resp)

return
}

func getAttachmentHandler(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -170,8 +159,6 @@ func getAttachmentHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}

return
}

func (s *Server) pullRequestCommitsHandler(w http.ResponseWriter, r *http.Request) {
Expand Down
12 changes: 11 additions & 1 deletion handler/mergePullRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,17 @@ func (h *InvokeMergePullRequestEventHandler) Process(ctx context.Context, event
return err
}

message := fmt.Sprintf("Merge pull request #%v from %s/%s", resp.Iid, event.Creator, resp.Head.Branch)
headRepositoryName, err := h.gc.RepositoryName(ctx, resp.Head.RepositoryId)
if err != nil {
err = errors.WithMessage(err, "query error")
err2 := h.gc.UpdateTask(ctx, event.Creator, event.TaskId, types.StateFailure, err.Error())
if err2 != nil {
return errors.WithMessage(err2, "update task error")
}
return err
}

message := fmt.Sprintf("Merge pull request #%v from %s/%s", resp.Iid, headRepositoryName, resp.Head.Branch)

quarantineRepoPath, err := utils.CreateQuarantineRepo(resp.Base.RepositoryId, resp.Head.RepositoryId, resp.Base.Branch, resp.Head.Branch)
if err != nil {
Expand Down