~emersion/hut

7033817939783abc7e46429c8cd2091bfcea7ff7 — delthas 6 months ago c778123
export/git: add readme and head
3 files changed, 41 insertions(+), 2 deletions(-)

M export/git.go
M srht/gitsrht/gql.go
M srht/gitsrht/operations.graphql
M export/git.go => export/git.go +12 -1
@@ 8,6 8,7 @@ import (
	"os"
	"os/exec"
	"path"
	"strings"

	"git.sr.ht/~emersion/gqlclient"



@@ 29,6 30,8 @@ type GitRepoInfo struct {
	Info
	Description *string            `json:"description"`
	Visibility  gitsrht.Visibility `json:"visibility"`
	Readme      *string            `json:"readme"`
	Head        *string            `json:"head"`
}

func (ex *GitExporter) Export(ctx context.Context, dir string) error {


@@ 45,7 48,7 @@ func (ex *GitExporter) Export(ctx context.Context, dir string) error {

	var cursor *gitsrht.Cursor
	for {
		repos, err := gitsrht.Repositories(ex.client, ctx, cursor)
		repos, err := gitsrht.ExportRepositories(ex.client, ctx, cursor)
		if err != nil {
			return err
		}


@@ 71,6 74,12 @@ func (ex *GitExporter) Export(ctx context.Context, dir string) error {
				return err
			}

			var head *string
			if repo.HEAD != nil {
				h := strings.TrimPrefix(repo.HEAD.Name, "refs/heads/")
				head = &h
			}

			repoInfo := GitRepoInfo{
				Info: Info{
					Service: "git.sr.ht",


@@ 78,6 87,8 @@ func (ex *GitExporter) Export(ctx context.Context, dir string) error {
				},
				Description: repo.Description,
				Visibility:  repo.Visibility,
				Readme:      repo.Readme,
				Head:        head,
			}
			if err := writeJSON(infoPath, &repoInfo); err != nil {
				return err

M srht/gitsrht/gql.go => srht/gitsrht/gql.go +10 -0
@@ 675,6 675,16 @@ func RepositoriesByUser(client *gqlclient.Client, ctx context.Context, username 
	return respData.User, err
}

func ExportRepositories(client *gqlclient.Client, ctx context.Context, cursor *Cursor) (repositories *RepositoryCursor, err error) {
	op := gqlclient.NewOperation("query exportRepositories ($cursor: Cursor) {\n\trepositories(cursor: $cursor) {\n\t\tresults {\n\t\t\tname\n\t\t\towner {\n\t\t\t\tcanonicalName\n\t\t\t}\n\t\t\tdescription\n\t\t\tvisibility\n\t\t\treadme\n\t\t\tHEAD {\n\t\t\t\tname\n\t\t\t}\n\t\t}\n\t\tcursor\n\t}\n}\n")
	op.Var("cursor", cursor)
	var respData struct {
		Repositories *RepositoryCursor
	}
	err = client.Execute(ctx, op, &respData)
	return respData.Repositories, err
}

func SshSettings(client *gqlclient.Client, ctx context.Context) (version *Version, err error) {
	op := gqlclient.NewOperation("query sshSettings {\n\tversion {\n\t\tsettings {\n\t\t\tsshUser\n\t\t}\n\t}\n}\n")
	var respData struct {

M srht/gitsrht/operations.graphql => srht/gitsrht/operations.graphql +19 -1
@@ 102,12 102,30 @@ fragment repos on RepositoryCursor {
        description
        visibility
        owner {
          canonicalName
            canonicalName
        }
    }
    cursor
}

query exportRepositories($cursor: Cursor) {
    repositories(cursor: $cursor) {
        results {
            name
            owner {
                canonicalName
            }
            description
            visibility
            readme
            HEAD {
                name
            }
        }
        cursor
    }
}

query sshSettings {
    version {
        settings {