From d0c8853244c5070775ef09355006fd3c4881dbca Mon Sep 17 00:00:00 2001 From: Adnan Maolood Date: Tue, 15 Feb 2022 07:07:45 -0500 Subject: [PATCH] gitsrht-update-hook/post-update: Always execute updateRepository Always execute the updateRepository GraphQL mutation so that the repository updated timestamp will be set. --- gitsrht-update-hook/post-update.go | 52 ++++++++++++++---------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/gitsrht-update-hook/post-update.go b/gitsrht-update-hook/post-update.go index c13b57d..4278e31 100644 --- a/gitsrht-update-hook/post-update.go +++ b/gitsrht-update-hook/post-update.go @@ -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: -- 2.38.4