mirror of
https://github.com/harness/drone.git
synced 2025-05-21 11:29:52 +08:00
fix with file content on commit, fix linter, removed unused provider
This commit is contained in:
parent
08f8c14055
commit
7a54ef9d65
@ -6,13 +6,13 @@ package cli
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/harness/gitness/cli/operations/hooks"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/harness/gitness/cli/operations/account"
|
||||
"github.com/harness/gitness/cli/operations/hooks"
|
||||
"github.com/harness/gitness/cli/operations/user"
|
||||
"github.com/harness/gitness/cli/operations/users"
|
||||
"github.com/harness/gitness/cli/server"
|
||||
|
@ -1,7 +1,12 @@
|
||||
// Copyright 2022 Harness Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform Free Trial License
|
||||
// that can be found in the LICENSE.md file for this repository.
|
||||
|
||||
package hooks
|
||||
|
||||
import (
|
||||
"github.com/harness/gitness/client"
|
||||
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
|
@ -1,7 +1,12 @@
|
||||
// Copyright 2022 Harness Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Polyform Free Trial License
|
||||
// that can be found in the LICENSE.md file for this repository.
|
||||
|
||||
package hooks
|
||||
|
||||
import (
|
||||
"github.com/harness/gitness/client"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
@ -7,6 +7,7 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/harness/gitness/gitrpc"
|
||||
server2 "github.com/harness/gitness/gitrpc/server"
|
||||
"github.com/harness/gitness/harness/auth/authn"
|
||||
|
@ -7,6 +7,7 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/harness/gitness/gitrpc"
|
||||
server2 "github.com/harness/gitness/gitrpc/server"
|
||||
"github.com/harness/gitness/internal/api/controller/pullreq"
|
||||
|
@ -26,7 +26,12 @@ type CreateInput struct {
|
||||
}
|
||||
|
||||
// Create creates a new pull request.
|
||||
func (c *Controller) Create(ctx context.Context, session *auth.Session, repoRef string, in *CreateInput) (*types.PullReq, error) {
|
||||
func (c *Controller) Create(
|
||||
ctx context.Context,
|
||||
session *auth.Session,
|
||||
repoRef string,
|
||||
in *CreateInput,
|
||||
) (*types.PullReq, error) {
|
||||
var pr *types.PullReq
|
||||
now := time.Now().UnixMilli()
|
||||
|
||||
|
@ -15,7 +15,12 @@ import (
|
||||
)
|
||||
|
||||
// Find returns a pull request from the provided repository.
|
||||
func (c *Controller) Find(ctx context.Context, session *auth.Session, repoRef string, pullreqNum int64) (*types.PullReq, error) {
|
||||
func (c *Controller) Find(
|
||||
ctx context.Context,
|
||||
session *auth.Session,
|
||||
repoRef string,
|
||||
pullreqNum int64,
|
||||
) (*types.PullReq, error) {
|
||||
if repoRef == "" {
|
||||
return nil, usererror.BadRequest("A valid repository reference must be provided.")
|
||||
}
|
||||
|
@ -15,7 +15,12 @@ import (
|
||||
)
|
||||
|
||||
// List returns a list of pull requests from the provided repository.
|
||||
func (c *Controller) List(ctx context.Context, session *auth.Session, repoRef string, filter *types.PullReqFilter) ([]*types.PullReq, error) {
|
||||
func (c *Controller) List(
|
||||
ctx context.Context,
|
||||
session *auth.Session,
|
||||
repoRef string,
|
||||
filter *types.PullReqFilter,
|
||||
) ([]*types.PullReq, error) {
|
||||
if repoRef == "" {
|
||||
return nil, usererror.BadRequest("A valid repository reference must be provided.")
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/harness/gitness/gitrpc"
|
||||
apiauth "github.com/harness/gitness/internal/api/auth"
|
||||
@ -49,10 +50,11 @@ func (c *Controller) CommitFiles(ctx context.Context, session *auth.Session,
|
||||
|
||||
actions := make([]gitrpc.CommitFileAction, len(in.Actions))
|
||||
for i, action := range in.Actions {
|
||||
payload := strings.ReplaceAll(action.Payload, "\r", "")
|
||||
actions[i] = gitrpc.CommitFileAction{
|
||||
Action: action.Action,
|
||||
Path: action.Path,
|
||||
Payload: []byte(action.Payload),
|
||||
Payload: []byte(payload),
|
||||
Encoding: action.Encoding,
|
||||
SHA: action.SHA,
|
||||
}
|
||||
|
@ -5,12 +5,12 @@
|
||||
package pullreq
|
||||
|
||||
import (
|
||||
"github.com/harness/gitness/types/enum"
|
||||
"net/http"
|
||||
|
||||
"github.com/harness/gitness/internal/api/controller/pullreq"
|
||||
"github.com/harness/gitness/internal/api/render"
|
||||
"github.com/harness/gitness/internal/api/request"
|
||||
"github.com/harness/gitness/types/enum"
|
||||
)
|
||||
|
||||
// HandleList returns a http.HandlerFunc that lists pull requests for a repository.
|
||||
|
@ -6,6 +6,7 @@ package dbtx
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
|
@ -7,10 +7,11 @@ package dbtx
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
// New returns new database Runner interface
|
||||
// New returns new database Runner interface.
|
||||
func New(db *sqlx.DB) Transactor {
|
||||
run := &runnerDB{sqlDB{db}}
|
||||
return run
|
||||
@ -32,5 +33,4 @@ var _ transactor = (*sqlDB)(nil)
|
||||
func (db sqlDB) startTx(ctx context.Context, opts *sql.TxOptions) (Tx, error) {
|
||||
tx, err := db.DB.BeginTxx(ctx, opts)
|
||||
return tx, err
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ package dbtx
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
|
@ -7,6 +7,7 @@ package dbtx
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type runnerDB struct {
|
||||
@ -52,9 +53,9 @@ func (r runnerDB) WithTx(ctx context.Context, txFn func(context.Context) error,
|
||||
|
||||
if !rtx.commit && !rtx.rollback {
|
||||
err = rtx.Commit()
|
||||
if err == sql.ErrTxDone {
|
||||
if errors.Is(err, sql.ErrTxDone) {
|
||||
// Check if the transaction failed because of the context, if yes return the ctx error.
|
||||
if ctxErr := ctx.Err(); ctxErr == context.Canceled || ctxErr == context.DeadlineExceeded {
|
||||
if ctxErr := ctx.Err(); errors.Is(ctxErr, context.Canceled) || errors.Is(ctxErr, context.DeadlineExceeded) {
|
||||
err = ctxErr
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,12 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"testing"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
//nolint:gocognit
|
||||
func TestWithTx(t *testing.T) {
|
||||
errTest := errors.New("dummy error")
|
||||
|
||||
@ -113,7 +115,7 @@ func TestWithTx(t *testing.T) {
|
||||
|
||||
func() {
|
||||
defer func() {
|
||||
recover()
|
||||
_ = recover()
|
||||
}()
|
||||
|
||||
err = run.WithTx(ctx, func(ctx context.Context) error {
|
||||
@ -134,7 +136,7 @@ func TestWithTx(t *testing.T) {
|
||||
t.Error("transaction not finished")
|
||||
}
|
||||
|
||||
if want, got := test.expectErr, err; want != got {
|
||||
if want, got := test.expectErr, err; !errors.Is(got, want) {
|
||||
t.Errorf("expected error %v, but got %v", want, got)
|
||||
}
|
||||
|
||||
|
@ -6,11 +6,11 @@ package dbtx
|
||||
|
||||
import "database/sql"
|
||||
|
||||
// TxDefault represents default transaction options
|
||||
// TxDefault represents default transaction options.
|
||||
var TxDefault = &sql.TxOptions{Isolation: sql.LevelDefault, ReadOnly: false}
|
||||
|
||||
// TxDefaultReadOnly represents default transaction options for read-only transactions
|
||||
// TxDefaultReadOnly represents default transaction options for read-only transactions.
|
||||
var TxDefaultReadOnly = &sql.TxOptions{Isolation: sql.LevelDefault, ReadOnly: true}
|
||||
|
||||
// TxSerializable represents serializable transaction options
|
||||
// TxSerializable represents serializable transaction options.
|
||||
var TxSerializable = &sql.TxOptions{Isolation: sql.LevelSerializable, ReadOnly: false}
|
||||
|
@ -6,6 +6,7 @@ package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/harness/gitness/internal/store"
|
||||
"github.com/harness/gitness/internal/store/database/dbtx"
|
||||
"github.com/harness/gitness/types"
|
||||
@ -66,7 +67,7 @@ WHERE pullreq_id = $1
|
||||
}
|
||||
|
||||
// FindByNumber finds the pull request by repo ID and pull request number.
|
||||
func (s *PullReqStore) FindByNumber(ctx context.Context, repoId, number int64) (*types.PullReq, error) {
|
||||
func (s *PullReqStore) FindByNumber(ctx context.Context, repoID, number int64) (*types.PullReq, error) {
|
||||
const sqlQuery = pullReqSelectBase + `
|
||||
WHERE pullreq_target_repo_id = $1 AND pullreq_number = $2
|
||||
`
|
||||
@ -74,7 +75,7 @@ WHERE pullreq_target_repo_id = $1 AND pullreq_number = $2
|
||||
db := dbtx.GetAccessor(ctx, s.db)
|
||||
|
||||
dst := new(types.PullReq)
|
||||
if err := db.GetContext(ctx, dst, sqlQuery, repoId, number); err != nil {
|
||||
if err := db.GetContext(ctx, dst, sqlQuery, repoID, number); err != nil {
|
||||
return nil, processSQLErrorf(err, "Select query failed")
|
||||
}
|
||||
return dst, nil
|
||||
|
@ -36,10 +36,10 @@ func (s *PullReqStoreSync) Find(ctx context.Context, id int64) (*types.PullReq,
|
||||
}
|
||||
|
||||
// FindByNumber finds the pull request by repo ID and pull request number.
|
||||
func (s *PullReqStoreSync) FindByNumber(ctx context.Context, repoId, number int64) (*types.PullReq, error) {
|
||||
func (s *PullReqStoreSync) FindByNumber(ctx context.Context, repoID, number int64) (*types.PullReq, error) {
|
||||
mutex.RLock()
|
||||
defer mutex.RUnlock()
|
||||
return s.base.FindByNumber(ctx, repoId, number)
|
||||
return s.base.FindByNumber(ctx, repoID, number)
|
||||
}
|
||||
|
||||
// Create creates a new pull request.
|
||||
@ -78,7 +78,11 @@ func (s *PullReqStoreSync) Count(ctx context.Context, repoID int64, opts *types.
|
||||
}
|
||||
|
||||
// List returns a list of pull requests for a repo.
|
||||
func (s *PullReqStoreSync) List(ctx context.Context, repoID int64, opts *types.PullReqFilter) ([]*types.PullReq, error) {
|
||||
func (s *PullReqStoreSync) List(
|
||||
ctx context.Context,
|
||||
repoID int64,
|
||||
opts *types.PullReqFilter,
|
||||
) ([]*types.PullReq, error) {
|
||||
mutex.RLock()
|
||||
defer mutex.RUnlock()
|
||||
return s.base.List(ctx, repoID, opts)
|
||||
|
@ -6,7 +6,6 @@ package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/harness/gitness/internal/store/database/_dbtx"
|
||||
|
||||
"github.com/harness/gitness/internal/store"
|
||||
"github.com/harness/gitness/types"
|
||||
@ -40,10 +39,6 @@ func ProvideDatabase(ctx context.Context, config *types.Config) (*sqlx.DB, error
|
||||
)
|
||||
}
|
||||
|
||||
func ProvideTransactor(ctx context.Context, db *sqlx.DB) _dbtx.Transactor {
|
||||
return _dbtx.New(db.DB)
|
||||
}
|
||||
|
||||
// ProvideUserStore provides a user store.
|
||||
func ProvideUserStore(db *sqlx.DB, uidTransformation store.PrincipalUIDTransformation) store.UserStore {
|
||||
switch db.DriverName() {
|
||||
|
@ -204,7 +204,7 @@ type (
|
||||
Find(ctx context.Context, id int64) (*types.PullReq, error)
|
||||
|
||||
// FindByNumber finds the pull request by repo ID and the pull request number.
|
||||
FindByNumber(ctx context.Context, repoId, number int64) (*types.PullReq, error)
|
||||
FindByNumber(ctx context.Context, repoID, number int64) (*types.PullReq, error)
|
||||
|
||||
// Create a new pull request.
|
||||
Create(ctx context.Context, pullreq *types.PullReq) error
|
||||
|
@ -139,7 +139,7 @@ export interface StringsMap {
|
||||
viewAllBranches: string
|
||||
viewAllTags: string
|
||||
viewCommitDetails: string
|
||||
webhook: string
|
||||
webhookEventsLabel: string
|
||||
yourBranches: string
|
||||
webhook: string
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user