~edwargix/git.sr.ht

d0c8853244c5070775ef09355006fd3c4881dbca — Adnan Maolood 2 years ago ffb36c0
gitsrht-update-hook/post-update: Always execute updateRepository

Always execute the updateRepository GraphQL mutation so that the
repository updated timestamp will be set.
1 files changed, 25 insertions(+), 27 deletions(-)

M gitsrht-update-hook/post-update.go
M gitsrht-update-hook/post-update.go => gitsrht-update-hook/post-update.go +25 -27
@@ 63,35 63,33 @@ func fetchInfoForPush(db *sql.DB, username string, repoId int, repoName string,
		Errors []gqlerror.Error `json:"errors"`
	}

	if newDescription != nil || newVisibility != nil {
		input := RepoInput{newDescription, newVisibility}
		resp := Response{}

		ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
		defer cancel()
		ctx = coreconfig.Context(ctx, config, "git.sr.ht")
		err := client.Execute(ctx, username, "git.sr.ht", client.GraphQLQuery{
			Query: `
			mutation UpdateRepository($id: Int!, $input: RepoInput!) {
				updateRepository(id: $id, input: $input) { id }
			}`,
			Variables: map[string]interface{}{
				"id":    repoId,
				"input": input,
			},
		}, &resp)
		if err != nil {
			return dbinfo, err
		} else if len(resp.Errors) > 0 {
			for _, err := range resp.Errors {
				logger.Printf("Error updating repository: %s", err.Error())
			}
			return dbinfo, fmt.Errorf("Failed to update repository: %s", resp.Errors[0].Message)
	input := RepoInput{newDescription, newVisibility}
	resp := Response{}

	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
	defer cancel()
	ctx = coreconfig.Context(ctx, config, "git.sr.ht")
	err := client.Execute(ctx, username, "git.sr.ht", client.GraphQLQuery{
		Query: `
		mutation UpdateRepository($id: Int!, $input: RepoInput!) {
			updateRepository(id: $id, input: $input) { id }
		}`,
		Variables: map[string]interface{}{
			"id":    repoId,
			"input": input,
		},
	}, &resp)
	if err != nil {
		return dbinfo, err
	} else if len(resp.Errors) > 0 {
		for _, err := range resp.Errors {
			logger.Printf("Error updating repository: %s", err.Error())
		}
		return dbinfo, fmt.Errorf("Failed to update repository: %s", resp.Errors[0].Message)
	}

		if newVisibility != nil {
			dbinfo.Visibility = *newVisibility
		}
	if newVisibility != nil {
		dbinfo.Visibility = *newVisibility
	}

	// With this query, we: