~emersion/hut

4b6943c85e5b6f71ef7924ddbbe9f7310dec5ddd — delthas 5 months ago 7033817
export/hg: add readme and nonPublishing
3 files changed, 36 insertions(+), 6 deletions(-)

M export/hg.go
M srht/hgsrht/gql.go
M srht/hgsrht/operations.graphql
M export/hg.go => export/hg.go +9 -5
@@ 29,8 29,10 @@ func NewHgExporter(client *gqlclient.Client, baseURL string) *HgExporter {
// export (i.e. the ones filled in by the GraphQL query)
type HgRepoInfo struct {
	Info
	Description *string           `json:"description"`
	Visibility  hgsrht.Visibility `json:"visibility"`
	Description   *string           `json:"description"`
	Visibility    hgsrht.Visibility `json:"visibility"`
	Readme        *string           `json:"readme"`
	NonPublishing bool              `json:"nonPublishing"`
}

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


@@ 41,7 43,7 @@ func (ex *HgExporter) Export(ctx context.Context, dir string) error {

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


@@ 73,8 75,10 @@ func (ex *HgExporter) Export(ctx context.Context, dir string) error {
					Service: "hg.sr.ht",
					Name:    repo.Name,
				},
				Description: repo.Description,
				Visibility:  repo.Visibility,
				Description:   repo.Description,
				Visibility:    repo.Visibility,
				Readme:        repo.Readme,
				NonPublishing: repo.NonPublishing,
			}
			if err := writeJSON(infoPath, &repoInfo); err != nil {
				return err

M srht/hgsrht/gql.go => srht/hgsrht/gql.go +10 -0
@@ 439,6 439,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\tnonPublishing\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 UserWebhooks(client *gqlclient.Client, ctx context.Context, cursor *Cursor) (userWebhooks *WebhookSubscriptionCursor, err error) {
	op := gqlclient.NewOperation("query userWebhooks ($cursor: Cursor) {\n\tuserWebhooks(cursor: $cursor) {\n\t\tresults {\n\t\t\tid\n\t\t\turl\n\t\t}\n\t\tcursor\n\t}\n}\n")
	op.Var("cursor", cursor)

M srht/hgsrht/operations.graphql => srht/hgsrht/operations.graphql +17 -1
@@ 34,12 34,28 @@ fragment repos on RepositoryCursor {
        description
        visibility
        owner {
          canonicalName
            canonicalName
        }
    }
    cursor
}

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

query userWebhooks($cursor: Cursor) {
    userWebhooks(cursor: $cursor) {
        results {