~edwargix/git.sr.ht

5a74fbcf4253888aab3fd56877581943684e3918 — Julien Moutinho 2 years ago 0c9fd38
gitsrht-update-hook: update go-redis to support Unix sockets
M gitsrht-update-hook/options.go => gitsrht-update-hook/options.go +6 -5
@@ 1,13 1,14 @@
package main

import (
	"context"
	"fmt"
	"os"
	"strconv"
	"strings"
	"time"

	goredis "github.com/go-redis/redis"
	goredis "github.com/go-redis/redis/v8"
)

var options map[string]string


@@ 35,10 36,10 @@ func loadOptions() {
	var n int
	if nopts, ok := os.LookupEnv("GIT_PUSH_OPTION_COUNT"); ok {
		n, _ = strconv.Atoi(nopts)
		redis.Set(fmt.Sprintf("git.sr.ht.options.%s", uuid),
		redis.Set(context.Background(), fmt.Sprintf("git.sr.ht.options.%s", uuid),
			nopts, 10*time.Minute)
	} else {
		nopts, err := redis.Get(fmt.Sprintf(
		nopts, err := redis.Get(context.Background(), fmt.Sprintf(
			"git.sr.ht.options.%s", uuid)).Result()
		if err != nil {
			return


@@ 51,12 52,12 @@ func loadOptions() {
		opt, ok := os.LookupEnv(fmt.Sprintf("GIT_PUSH_OPTION_%d", i))
		optkey := fmt.Sprintf("git.sr.ht.options.%s.%d", uuid, i)
		if !ok {
			opt, err = redis.Get(optkey).Result()
			opt, err = redis.Get(context.Background(), optkey).Result()
			if err != nil {
				return
			}
		} else {
			redis.Set(optkey, opt, 10*time.Minute)
			redis.Set(context.Background(), optkey, opt, 10*time.Minute)
		}
		parts := strings.SplitN(opt, "=", 2)
		if len(parts) == 1 {

M gitsrht-update-hook/post-update.go => gitsrht-update-hook/post-update.go +3 -2
@@ 1,6 1,7 @@
package main

import (
	ctx "context"
	"database/sql"
	"encoding/json"
	"fmt"


@@ 15,7 16,7 @@ import (
	"github.com/go-git/go-git/v5/plumbing"
	"github.com/go-git/go-git/v5/plumbing/object"
	"github.com/go-git/go-git/v5/plumbing/storer"
	goredis "github.com/go-redis/redis"
	goredis "github.com/go-redis/redis/v8"
	_ "github.com/lib/pq"
)



@@ 220,7 221,7 @@ func postUpdate() {
		var oldref, newref string
		var oldobj, newobj object.Object
		updateKey := fmt.Sprintf("update.%s.%s", pushUuid, refname)
		update, err := redis.Get(updateKey).Result()
		update, err := redis.Get(ctx.Background(), updateKey).Result()
		if update == "" || err != nil {
			logger.Println("redis.Get: missing key")
			continue

M gitsrht-update-hook/update.go => gitsrht-update-hook/update.go +3 -2
@@ 1,11 1,12 @@
package main

import (
	"context"
	"fmt"
	"os"
	"time"

	goredis "github.com/go-redis/redis"
	goredis "github.com/go-redis/redis/v8"
)

// XXX: This is run once for every single ref that's pushed. If someone pushes


@@ 31,6 32,6 @@ func update() {
		logger.Fatalf("Failed to parse redis host: %v", err)
	}
	redis := goredis.NewClient(ropts)
	redis.Set(fmt.Sprintf("update.%s.%s", pushUuid, refname),
	redis.Set(context.Background(), fmt.Sprintf("update.%s.%s", pushUuid, refname),
		fmt.Sprintf("%s:%s", oldref, newref), 10*time.Minute)
}