+19
-12
knotserver/git/post_receive.go
+19
-12
knotserver/git/post_receive.go
···
3
import (
4
"bufio"
5
"context"
6
"fmt"
7
"io"
8
"strings"
···
57
ByEmail map[string]int
58
}
59
60
-
func (g *GitRepo) RefUpdateMeta(line PostReceiveLine) RefUpdateMeta {
61
commitCount, err := g.newCommitCount(line)
62
-
if err != nil {
63
-
// TODO: log this
64
-
}
65
66
isDefaultRef, err := g.isDefaultBranch(line)
67
-
if err != nil {
68
-
// TODO: log this
69
-
}
70
71
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
72
defer cancel()
73
breakdown, err := g.AnalyzeLanguages(ctx)
74
-
if err != nil {
75
-
// TODO: log this
76
-
}
77
78
return RefUpdateMeta{
79
CommitCount: commitCount,
80
IsDefaultRef: isDefaultRef,
81
LangBreakdown: breakdown,
82
-
}
83
}
84
85
func (g *GitRepo) newCommitCount(line PostReceiveLine) (CommitCount, error) {
···
95
args := []string{fmt.Sprintf("--max-count=%d", 100)}
96
97
if line.OldSha.IsZero() {
98
-
// just git rev-list <newsha>
99
args = append(args, line.NewSha.String())
100
} else {
101
// git rev-list <oldsha>..<newsha>
102
args = append(args, fmt.Sprintf("%s..%s", line.OldSha.String(), line.NewSha.String()))
···
3
import (
4
"bufio"
5
"context"
6
+
"errors"
7
"fmt"
8
"io"
9
"strings"
···
58
ByEmail map[string]int
59
}
60
61
+
func (g *GitRepo) RefUpdateMeta(line PostReceiveLine) (RefUpdateMeta, error) {
62
+
var errs error
63
+
64
commitCount, err := g.newCommitCount(line)
65
+
errors.Join(errs, err)
66
67
isDefaultRef, err := g.isDefaultBranch(line)
68
+
errors.Join(errs, err)
69
70
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
71
defer cancel()
72
breakdown, err := g.AnalyzeLanguages(ctx)
73
+
errors.Join(errs, err)
74
75
return RefUpdateMeta{
76
CommitCount: commitCount,
77
IsDefaultRef: isDefaultRef,
78
LangBreakdown: breakdown,
79
+
}, errs
80
}
81
82
func (g *GitRepo) newCommitCount(line PostReceiveLine) (CommitCount, error) {
···
92
args := []string{fmt.Sprintf("--max-count=%d", 100)}
93
94
if line.OldSha.IsZero() {
95
+
// git rev-list <newsha> ^other-branches --not ^this-branch
96
args = append(args, line.NewSha.String())
97
+
98
+
branches, _ := g.Branches()
99
+
for _, b := range branches {
100
+
if !strings.Contains(line.Ref, b.Name) {
101
+
args = append(args, fmt.Sprintf("^%s", b.Name))
102
+
}
103
+
}
104
+
105
+
args = append(args, "--not")
106
+
args = append(args, fmt.Sprintf("^%s", line.Ref))
107
} else {
108
// git rev-list <oldsha>..<newsha>
109
args = append(args, fmt.Sprintf("%s..%s", line.OldSha.String(), line.NewSha.String()))
+5
-2
knotserver/internal.go
+5
-2
knotserver/internal.go
···
3
import (
4
"context"
5
"encoding/json"
6
"fmt"
7
"log/slog"
8
"net/http"
···
145
return fmt.Errorf("failed to open git repo at ref %s: %w", line.Ref, err)
146
}
147
148
-
meta := gr.RefUpdateMeta(line)
149
150
metaRecord := meta.AsRecord()
151
···
169
EventJson: string(eventJson),
170
}
171
172
-
return h.db.InsertEvent(event, h.n)
173
}
174
175
func (h *InternalHandle) triggerPipeline(clientMsgs *[]string, line git.PostReceiveLine, gitUserDid, repoDid, repoName string, pushOptions PushOptions) error {
···
3
import (
4
"context"
5
"encoding/json"
6
+
"errors"
7
"fmt"
8
"log/slog"
9
"net/http"
···
146
return fmt.Errorf("failed to open git repo at ref %s: %w", line.Ref, err)
147
}
148
149
+
var errs error
150
+
meta, err := gr.RefUpdateMeta(line)
151
+
errors.Join(errs, err)
152
153
metaRecord := meta.AsRecord()
154
···
172
EventJson: string(eventJson),
173
}
174
175
+
return errors.Join(errs, h.db.InsertEvent(event, h.n))
176
}
177
178
func (h *InternalHandle) triggerPipeline(clientMsgs *[]string, line git.PostReceiveLine, gitUserDid, repoDid, repoName string, pushOptions PushOptions) error {