~edwargix/git.sr.ht

0e2f1e4e0ff078de5fdc18e96a86c0066aba1036 — Simon Ser 2 years ago 1722324
go fmt
M api/graph/model/acl.go => api/graph/model/acl.go +9 -9
@@ 16,8 16,8 @@ import (

// TODO: Drop updated column from database
type ACL struct {
	ID         int        `json:"id"`
	Created    time.Time  `json:"created"`
	ID      int       `json:"id"`
	Created time.Time `json:"created"`

	RawAccessMode string
	RepoID        int


@@ 54,14 54,14 @@ func (acl *ACL) Fields() *database.ModelFields {
	}
	acl.fields = &database.ModelFields{
		Fields: []*database.FieldMap{
			{ "id", "id", &acl.ID },
			{ "created", "created", &acl.Created },
			{ "mode", "mode", &acl.RawAccessMode },
			{"id", "id", &acl.ID},
			{"created", "created", &acl.Created},
			{"mode", "mode", &acl.RawAccessMode},

			// Always fetch:
			{ "id", "", &acl.ID },
			{ "repo_id", "", &acl.RepoID },
			{ "user_id", "", &acl.UserID },
			{"id", "", &acl.ID},
			{"repo_id", "", &acl.RepoID},
			{"user_id", "", &acl.UserID},
		},
	}
	return acl.fields


@@ 77,7 77,7 @@ func (acl *ACL) QueryWithCursor(ctx context.Context,

	if cur.Next != "" {
		next, _ := strconv.Atoi(cur.Next)
		q = q.Where(database.WithAlias(acl.alias, "id") + "<= ?", next)
		q = q.Where(database.WithAlias(acl.alias, "id")+"<= ?", next)
	}
	q = q.
		OrderBy(database.WithAlias(acl.alias, "id") + " DESC").

M api/graph/model/artifact.go => api/graph/model/artifact.go +14 -14
@@ 13,11 13,11 @@ import (
)

type Artifact struct {
	ID         int         `json:"id"`
	Created    time.Time   `json:"created"`
	Filename   string      `json:"filename"`
	Checksum   string      `json:"checksum"`
	Size       int         `json:"size"`
	ID       int       `json:"id"`
	Created  time.Time `json:"created"`
	Filename string    `json:"filename"`
	Checksum string    `json:"checksum"`
	Size     int       `json:"size"`

	Commit string



@@ 44,16 44,16 @@ func (a *Artifact) Fields() *database.ModelFields {
	}
	a.fields = &database.ModelFields{
		Fields: []*database.FieldMap{
			{ "id", "id", &a.ID },
			{ "created", "created", &a.Created },
			{ "filename", "filename", &a.Filename },
			{ "checksum", "checksum", &a.Checksum },
			{ "size", "size", &a.Size },
			{"id", "id", &a.ID},
			{"created", "created", &a.Created},
			{"filename", "filename", &a.Filename},
			{"checksum", "checksum", &a.Checksum},
			{"size", "size", &a.Size},

			// Always fetch:
			{ "id", "", &a.ID },
			{ "commit", "", &a.Commit },
			{ "filename", "", &a.Filename },
			{"id", "", &a.ID},
			{"commit", "", &a.Commit},
			{"filename", "", &a.Filename},
		},
	}
	return a.fields


@@ 69,7 69,7 @@ func (a *Artifact) QueryWithCursor(ctx context.Context,

	if cur.Next != "" {
		next, _ := strconv.Atoi(cur.Next)
		q = q.Where(database.WithAlias(a.alias, "id") + "<= ?", next)
		q = q.Where(database.WithAlias(a.alias, "id")+"<= ?", next)
	}
	q = q.
		OrderBy(database.WithAlias(a.alias, "id") + " DESC").

M api/graph/model/blob.go => api/graph/model/blob.go +6 -6
@@ 16,12 16,12 @@ type BinaryBlob struct {

	Base64 string `json:"base64"`

	blob  *object.Blob
	repo  *RepoWrapper
	blob *object.Blob
	repo *RepoWrapper
}

func (BinaryBlob) IsObject() {}
func (BinaryBlob) IsBlob() {}
func (BinaryBlob) IsBlob()   {}

type TextBlob struct {
	Type    ObjectType `json:"type"`


@@ 31,12 31,12 @@ type TextBlob struct {

	Text string `json:"text"`

	blob  *object.Blob
	repo  *RepoWrapper
	blob *object.Blob
	repo *RepoWrapper
}

func (TextBlob) IsObject() {}
func (TextBlob) IsBlob() {}
func (TextBlob) IsBlob()   {}

func BlobFromObject(repo *RepoWrapper, obj *object.Blob) Object {
	reader, err := obj.Reader()

M api/graph/model/repository.go => api/graph/model/repository.go +29 -29
@@ 4,28 4,28 @@ import (
	"context"
	"database/sql"
	"fmt"
	"time"
	"strconv"
	"time"

	sq "github.com/Masterminds/squirrel"
	"github.com/go-git/go-git/v5"
	"github.com/go-git/go-git/v5/plumbing"
	sq "github.com/Masterminds/squirrel"

	"git.sr.ht/~sircmpwn/core-go/database"
	"git.sr.ht/~sircmpwn/core-go/model"
)

type Repository struct {
	ID             int        `json:"id"`
	Created        time.Time  `json:"created"`
	Updated        time.Time  `json:"updated"`
	Name           string     `json:"name"`
	Description    *string    `json:"description"`
	UpstreamURL    *string    `json:"upstreamUrl"`
	Readme         *string    `json:"readme"`

	Path    string
	OwnerID int
	ID          int       `json:"id"`
	Created     time.Time `json:"created"`
	Updated     time.Time `json:"updated"`
	Name        string    `json:"name"`
	Description *string   `json:"description"`
	UpstreamURL *string   `json:"upstreamUrl"`
	Readme      *string   `json:"readme"`

	Path          string
	OwnerID       int
	RawVisibility string

	alias  string


@@ 35,9 35,9 @@ type Repository struct {

func (r *Repository) Visibility() Visibility {
	visMap := map[string]Visibility{
		"public": VisibilityPublic,
		"public":   VisibilityPublic,
		"unlisted": VisibilityUnlisted,
		"private": VisibilityPrivate,
		"private":  VisibilityPrivate,
	}
	vis, ok := visMap[r.RawVisibility]
	if !ok {


@@ 90,20 90,20 @@ func (r *Repository) Fields() *database.ModelFields {
	}
	r.fields = &database.ModelFields{
		Fields: []*database.FieldMap{
			{ "id", "id", &r.ID },
			{ "created", "created", &r.Created },
			{ "updated", "updated", &r.Updated },
			{ "name", "name", &r.Name },
			{ "description", "description", &r.Description },
			{ "visibility", "visibility", &r.RawVisibility },
			{ "upstream_uri", "upstreamUrl", &r.UpstreamURL },
			{ "readme", "readme", &r.Readme },
			{"id", "id", &r.ID},
			{"created", "created", &r.Created},
			{"updated", "updated", &r.Updated},
			{"name", "name", &r.Name},
			{"description", "description", &r.Description},
			{"visibility", "visibility", &r.RawVisibility},
			{"upstream_uri", "upstreamUrl", &r.UpstreamURL},
			{"readme", "readme", &r.Readme},

			// Always fetch:
			{ "id", "", &r.ID },
			{ "path", "", &r.Path },
			{ "owner_id", "", &r.OwnerID },
			{ "updated", "", &r.Updated },
			{"id", "", &r.ID},
			{"path", "", &r.Path},
			{"owner_id", "", &r.OwnerID},
			{"updated", "", &r.Updated},
		},
	}
	return r.fields


@@ 120,7 120,7 @@ func (r *Repository) QueryWithCursor(ctx context.Context,
	if cur.Next != "" {
		ts, _ := strconv.ParseInt(cur.Next, 10, 64)
		updated := time.Unix(ts, 0)
		q = q.Where(database.WithAlias(r.alias, "updated") + "<= ?", updated)
		q = q.Where(database.WithAlias(r.alias, "updated")+"<= ?", updated)
	}
	q = q.
		OrderBy(database.WithAlias(r.alias, "updated") + " DESC").


@@ 160,7 160,7 @@ func (r *Repository) DefaultSearch(query sq.SelectBuilder,
	desc := database.WithAlias(r.alias, "description")
	return query.
		Where(sq.Or{
			sq.Expr(name + ` ILIKE '%' || ? || '%'`, term),
			sq.Expr(desc + ` ILIKE '%' || ? || '%'`, term),
			sq.Expr(name+` ILIKE '%' || ? || '%'`, term),
			sq.Expr(desc+` ILIKE '%' || ? || '%'`, term),
		}), nil
}

M api/graph/model/user.go => api/graph/model/user.go +10 -10
@@ 45,18 45,18 @@ func (u *User) Fields() *database.ModelFields {
	}
	u.fields = &database.ModelFields{
		Fields: []*database.FieldMap{
			{ "id", "id", &u.ID },
			{ "created", "created", &u.Created },
			{ "updated", "updated", &u.Updated },
			{ "username", "username", &u.Username },
			{ "email", "email", &u.Email },
			{ "url", "url", &u.URL },
			{ "location", "location", &u.Location },
			{ "bio", "bio", &u.Bio },
			{"id", "id", &u.ID},
			{"created", "created", &u.Created},
			{"updated", "updated", &u.Updated},
			{"username", "username", &u.Username},
			{"email", "email", &u.Email},
			{"url", "url", &u.URL},
			{"location", "location", &u.Location},
			{"bio", "bio", &u.Bio},

			// Always fetch:
			{ "id", "", &u.ID },
			{ "username", "", &u.Username },
			{"id", "", &u.ID},
			{"username", "", &u.Username},
		},
	}
	return u.fields

M api/graph/resolver.go => api/graph/resolver.go +1 -1
@@ 6,7 6,7 @@ import (

//go:generate go run github.com/99designs/gqlgen

type Resolver struct {}
type Resolver struct{}

var (
	repoNameRE = regexp.MustCompile(`^[A-Za-z0-9._-]+$`)

M api/loaders/middleware.go => api/loaders/middleware.go +10 -10
@@ 40,8 40,8 @@ func fetchUsersByID(ctx context.Context) func(ids []int) ([]*model.User, []error
		users := make([]*model.User, len(ids))
		if err := database.WithTx(ctx, &sql.TxOptions{
			Isolation: 0,
			ReadOnly: true,
		}, func (tx *sql.Tx) error {
			ReadOnly:  true,
		}, func(tx *sql.Tx) error {
			var (
				err  error
				rows *sql.Rows


@@ 83,8 83,8 @@ func fetchUsersByName(ctx context.Context) func(names []string) ([]*model.User, 
		users := make([]*model.User, len(names))
		if err := database.WithTx(ctx, &sql.TxOptions{
			Isolation: 0,
			ReadOnly: true,
		}, func (tx *sql.Tx) error {
			ReadOnly:  true,
		}, func(tx *sql.Tx) error {
			var (
				err  error
				rows *sql.Rows


@@ 126,8 126,8 @@ func fetchRepositoriesByID(ctx context.Context) func(ids []int) ([]*model.Reposi
		repos := make([]*model.Repository, len(ids))
		if err := database.WithTx(ctx, &sql.TxOptions{
			Isolation: 0,
			ReadOnly: true,
		}, func (tx *sql.Tx) error {
			ReadOnly:  true,
		}, func(tx *sql.Tx) error {
			var (
				err  error
				rows *sql.Rows


@@ 178,8 178,8 @@ func fetchRepositoriesByName(ctx context.Context) func(names []string) ([]*model
		repos := make([]*model.Repository, len(names))
		if err := database.WithTx(ctx, &sql.TxOptions{
			Isolation: 0,
			ReadOnly: true,
		}, func (tx *sql.Tx) error {
			ReadOnly:  true,
		}, func(tx *sql.Tx) error {
			var (
				err  error
				rows *sql.Rows


@@ 225,8 225,8 @@ func fetchRepositoriesByOwnerRepoName(ctx context.Context) func(names [][2]strin
		repos := make([]*model.Repository, len(names))
		if err := database.WithTx(ctx, &sql.TxOptions{
			Isolation: 0,
			ReadOnly: true,
		}, func (tx *sql.Tx) error {
			ReadOnly:  true,
		}, func(tx *sql.Tx) error {
			var (
				err    error
				rows   *sql.Rows

M api/webhooks/webhooks.go => api/webhooks/webhooks.go +3 -3
@@ 45,9 45,9 @@ type RepoWebhookPayload struct {
	Visibility  string    `json:"visibility"`

	Owner struct {
		CanonicalName string  `json:"canonical_name"`
		Name          string  `json:"name"`
	}`json:"owner"`
		CanonicalName string `json:"canonical_name"`
		Name          string `json:"name"`
	} `json:"owner"`
}

func DeliverLegacyRepoCreate(ctx context.Context, repo *model.Repository) {