mirror of
https://github.com/harness/drone.git
synced 2025-05-10 02:50:58 +08:00
parent
abba5e1cf4
commit
077cd2c74d
@ -7,6 +7,7 @@ package space
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
apiauth "github.com/harness/gitness/internal/api/auth"
|
apiauth "github.com/harness/gitness/internal/api/auth"
|
||||||
"github.com/harness/gitness/internal/api/usererror"
|
"github.com/harness/gitness/internal/api/usererror"
|
||||||
"github.com/harness/gitness/internal/auth"
|
"github.com/harness/gitness/internal/auth"
|
||||||
@ -53,7 +54,7 @@ func (c *Controller) Export(ctx context.Context, session *auth.Session, spaceRef
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = dbtx.New(c.db).WithTx(ctx, func(ctx context.Context) error {
|
err = dbtx.New(c.db).WithTx(ctx, func(ctx context.Context) error {
|
||||||
err = c.exporter.RunMany(ctx, space.ID, providerInfo, repos)
|
err = c.exporter.RunManyForSpace(ctx, space.ID, repos, providerInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to start export repository job: %w", err)
|
return fmt.Errorf("failed to start export repository job: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
apiauth "github.com/harness/gitness/internal/api/auth"
|
apiauth "github.com/harness/gitness/internal/api/auth"
|
||||||
|
"github.com/harness/gitness/internal/api/usererror"
|
||||||
"github.com/harness/gitness/internal/auth"
|
"github.com/harness/gitness/internal/auth"
|
||||||
"github.com/harness/gitness/types"
|
"github.com/harness/gitness/types"
|
||||||
"github.com/harness/gitness/types/enum"
|
"github.com/harness/gitness/types/enum"
|
||||||
@ -17,19 +18,24 @@ type ExportProgressOutput struct {
|
|||||||
func (c *Controller) ExportProgress(ctx context.Context,
|
func (c *Controller) ExportProgress(ctx context.Context,
|
||||||
session *auth.Session,
|
session *auth.Session,
|
||||||
spaceRef string,
|
spaceRef string,
|
||||||
) (ExportProgressOutput, error) {
|
) (*ExportProgressOutput, error) {
|
||||||
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ExportProgressOutput{}, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = apiauth.CheckSpace(ctx, c.authorizer, session, space, enum.PermissionSpaceView, false); err != nil {
|
if err = apiauth.CheckSpace(ctx, c.authorizer, session, space, enum.PermissionSpaceView, false); err != nil {
|
||||||
return ExportProgressOutput{}, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
progress, err := c.exporter.GetProgress(ctx, space)
|
progress, err := c.exporter.GetProgressForSpace(ctx, space.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ExportProgressOutput{}, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return ExportProgressOutput{Repos: progress}, nil
|
|
||||||
|
if len(progress) == 0 {
|
||||||
|
return nil, usererror.NotFound("No ongoing export found for space.")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &ExportProgressOutput{Repos: progress}, nil
|
||||||
}
|
}
|
||||||
|
@ -121,6 +121,11 @@ func Forbidden(message string) *Error {
|
|||||||
return New(http.StatusForbidden, message)
|
return New(http.StatusForbidden, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NotFound returns a new user facing not found error.
|
||||||
|
func NotFound(message string) *Error {
|
||||||
|
return New(http.StatusNotFound, message)
|
||||||
|
}
|
||||||
|
|
||||||
// ConflictWithPayload returns a new user facing conflict error with payload.
|
// ConflictWithPayload returns a new user facing conflict error with payload.
|
||||||
func ConflictWithPayload(message string, values ...map[string]any) *Error {
|
func ConflictWithPayload(message string, values ...map[string]any) *Error {
|
||||||
return NewWithPayload(http.StatusConflict, message, values...)
|
return NewWithPayload(http.StatusConflict, message, values...)
|
||||||
|
@ -9,14 +9,15 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/harness/gitness/encrypt"
|
"github.com/harness/gitness/encrypt"
|
||||||
"github.com/harness/gitness/internal/api/controller/repo"
|
"github.com/harness/gitness/internal/api/controller/repo"
|
||||||
"github.com/harness/gitness/internal/sse"
|
"github.com/harness/gitness/internal/sse"
|
||||||
"github.com/harness/gitness/types/enum"
|
"github.com/harness/gitness/types/enum"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"net/url"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/harness/gitness/gitrpc"
|
"github.com/harness/gitness/gitrpc"
|
||||||
"github.com/harness/gitness/internal/services/job"
|
"github.com/harness/gitness/internal/services/job"
|
||||||
@ -64,7 +65,12 @@ func (r *Repository) Register(executor *job.Executor) error {
|
|||||||
return executor.Register(jobType, r)
|
return executor.Register(jobType, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) RunMany(ctx context.Context, spaceId int64, harnessCodeInfo *HarnessCodeInfo, repos []*types.Repository) error {
|
func (r *Repository) RunManyForSpace(
|
||||||
|
ctx context.Context,
|
||||||
|
spaceId int64,
|
||||||
|
repos []*types.Repository,
|
||||||
|
harnessCodeInfo *HarnessCodeInfo,
|
||||||
|
) error {
|
||||||
jobGroupId := getJobGroupId(spaceId)
|
jobGroupId := getJobGroupId(spaceId)
|
||||||
jobDefinitions := make([]job.Definition, len(repos))
|
jobDefinitions := make([]job.Definition, len(repos))
|
||||||
for i, repository := range repos {
|
for i, repository := range repos {
|
||||||
@ -190,14 +196,11 @@ func (r *Repository) getJobInput(data string) (Input, error) {
|
|||||||
return input, nil
|
return input, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repository) GetProgress(ctx context.Context, space *types.Space) ([]types.JobProgress, error) {
|
func (r *Repository) GetProgressForSpace(ctx context.Context, spaceID int64) ([]types.JobProgress, error) {
|
||||||
spaceId := getJobGroupId(space.ID)
|
spaceId := getJobGroupId(spaceID)
|
||||||
progress, err := r.scheduler.GetJobProgressForGroup(ctx, spaceId)
|
progress, err := r.scheduler.GetJobProgressForGroup(ctx, spaceId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("failed to get job progress for group: %w", err)
|
||||||
}
|
|
||||||
if progress == nil || len(progress) == 0 {
|
|
||||||
return []types.JobProgress{job.FailProgress()}, nil
|
|
||||||
}
|
}
|
||||||
return progress, nil
|
return progress, nil
|
||||||
}
|
}
|
||||||
|
@ -85,9 +85,10 @@ func (s *JobStore) ListByGroupID(ctx context.Context, groupId string) ([]*types.
|
|||||||
db := dbtx.GetAccessor(ctx, s.db)
|
db := dbtx.GetAccessor(ctx, s.db)
|
||||||
|
|
||||||
dst := make([]*types.Job, 0)
|
dst := make([]*types.Job, 0)
|
||||||
if err := db.GetContext(ctx, &dst, sqlQuery, groupId); err != nil {
|
if err := db.SelectContext(ctx, &dst, sqlQuery, groupId); err != nil {
|
||||||
return nil, database.ProcessSQLErrorf(err, "Failed to find job by group id")
|
return nil, database.ProcessSQLErrorf(err, "Failed to find job by group id")
|
||||||
}
|
}
|
||||||
|
|
||||||
return dst, nil
|
return dst, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user