Skip to content

Commit 89d4a09

Browse files
committed
refactor: remove context from gogs
1 parent 3ec351f commit 89d4a09

File tree

3 files changed

+17
-26
lines changed

3 files changed

+17
-26
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ replace github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142
318318

319319
replace github.com/nektos/act => gitea.com/gitea/act v0.261.3
320320

321+
replace github.com/gogs/go-gogs-client => github.com/TheFox0x7/go-gogs-client v0.0.0-20250205203315-0e70fbf458bf
322+
321323
// TODO: the only difference is in `PutObject`: the fork doesn't use `NewVerifyingReader(r, sha256.New(), oid, expectedSize)`, need to figure out why
322324
replace github.com/charmbracelet/git-lfs-transfer => gitea.com/gitea/git-lfs-transfer v0.2.0
323325

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ github.com/RoaringBitmap/roaring v1.9.4 h1:yhEIoH4YezLYT04s1nHehNO64EKFTop/wBhxv
8181
github.com/RoaringBitmap/roaring v1.9.4/go.mod h1:6AXUsoIEzDTFFQCe1RbGA6uFONMhvejWj5rqITANK90=
8282
github.com/SaveTheRbtz/zstd-seekable-format-go/pkg v0.7.3 h1:BP0HiyNT3AQEYi+if3wkRcIdQFHtsw6xX3Kx0glckgA=
8383
github.com/SaveTheRbtz/zstd-seekable-format-go/pkg v0.7.3/go.mod h1:hMNtySovKkn2gdDuLqnqveP+mfhUSaBdoBcr2I7Zt0E=
84+
github.com/TheFox0x7/go-gogs-client v0.0.0-20250205203315-0e70fbf458bf h1:ZEY0JnHJlOOAwOQuA8HRtkvs86DWbFPivqnNDFtk/vo=
85+
github.com/TheFox0x7/go-gogs-client v0.0.0-20250205203315-0e70fbf458bf/go.mod h1:E7sa6iZuHNhgy84Z+wN9618wGcsHjqKFo5lq0B0FpQ4=
8486
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
8587
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
8688
github.com/alecthomas/chroma/v2 v2.2.0/go.mod h1:vf4zrexSH54oEjJ7EdB65tGNHmH3pGZmVkgTP5RHvAs=
@@ -371,8 +373,6 @@ github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
371373
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
372374
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f h1:3BSP1Tbs2djlpprl7wCLuiqMaUh5SJkkzI2gDs+FgLs=
373375
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f/go.mod h1:Pcatq5tYkCW2Q6yrR2VRHlbHpZ/R4/7qyL1TCF7vl14=
374-
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85 h1:UjoPNDAQ5JPCjlxoJd6K8ALZqSDDhk2ymieAZOVaDg0=
375-
github.com/gogs/go-gogs-client v0.0.0-20210131175652-1d7215cd8d85/go.mod h1:fR6z1Ie6rtF7kl/vBYMfgD5/G5B1blui7z426/sj2DU=
376376
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
377377
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
378378
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=

services/migrations/gogs.go

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ func (f *GogsDownloaderFactory) GitServiceType() structs.GitServiceType {
6060
// from gogs via API
6161
type GogsDownloader struct {
6262
base.NullDownloader
63-
ctx context.Context
6463
client *gogs.Client
6564
baseURL string
6665
repoOwner string
@@ -85,9 +84,8 @@ func (g *GogsDownloader) LogString() string {
8584
}
8685

8786
// NewGogsDownloader creates a gogs Downloader via gogs API
88-
func NewGogsDownloader(ctx context.Context, baseURL, userName, password, token, repoOwner, repoName string) *GogsDownloader {
87+
func NewGogsDownloader(_ context.Context, baseURL, userName, password, token, repoOwner, repoName string) *GogsDownloader {
8988
downloader := GogsDownloader{
90-
ctx: ctx,
9189
baseURL: baseURL,
9290
userName: userName,
9391
password: password,
@@ -108,24 +106,15 @@ func NewGogsDownloader(ctx context.Context, baseURL, userName, password, token,
108106
downloader.transport = transport
109107

110108
client = gogs.NewClient(baseURL, "")
111-
client.SetHTTPClient(&http.Client{
112-
Transport: &downloader,
113-
})
114109
}
115110

116111
downloader.client = client
117112
return &downloader
118113
}
119114

120-
// RoundTrip wraps the provided request within this downloader's context and passes it to our internal http.Transport.
121-
// This implements http.RoundTripper and makes the gogs client requests cancellable even though it is not cancellable itself
122-
func (g *GogsDownloader) RoundTrip(req *http.Request) (*http.Response, error) {
123-
return g.transport.RoundTrip(req.WithContext(g.ctx))
124-
}
125-
126115
// GetRepoInfo returns a repository information
127-
func (g *GogsDownloader) GetRepoInfo(_ context.Context) (*base.Repository, error) {
128-
gr, err := g.client.GetRepo(g.repoOwner, g.repoName)
116+
func (g *GogsDownloader) GetRepoInfo(ctx context.Context) (*base.Repository, error) {
117+
gr, err := g.client.GetRepo(ctx, g.repoOwner, g.repoName)
129118
if err != nil {
130119
return nil, err
131120
}
@@ -143,11 +132,11 @@ func (g *GogsDownloader) GetRepoInfo(_ context.Context) (*base.Repository, error
143132
}
144133

145134
// GetMilestones returns milestones
146-
func (g *GogsDownloader) GetMilestones(_ context.Context) ([]*base.Milestone, error) {
135+
func (g *GogsDownloader) GetMilestones(ctx context.Context) ([]*base.Milestone, error) {
147136
perPage := 100
148137
milestones := make([]*base.Milestone, 0, perPage)
149138

150-
ms, err := g.client.ListRepoMilestones(g.repoOwner, g.repoName)
139+
ms, err := g.client.ListRepoMilestones(ctx, g.repoOwner, g.repoName)
151140
if err != nil {
152141
return nil, err
153142
}
@@ -166,10 +155,10 @@ func (g *GogsDownloader) GetMilestones(_ context.Context) ([]*base.Milestone, er
166155
}
167156

168157
// GetLabels returns labels
169-
func (g *GogsDownloader) GetLabels(_ context.Context) ([]*base.Label, error) {
158+
func (g *GogsDownloader) GetLabels(ctx context.Context) ([]*base.Label, error) {
170159
perPage := 100
171160
labels := make([]*base.Label, 0, perPage)
172-
ls, err := g.client.ListRepoLabels(g.repoOwner, g.repoName)
161+
ls, err := g.client.ListRepoLabels(ctx, g.repoOwner, g.repoName)
173162
if err != nil {
174163
return nil, err
175164
}
@@ -182,7 +171,7 @@ func (g *GogsDownloader) GetLabels(_ context.Context) ([]*base.Label, error) {
182171
}
183172

184173
// GetIssues returns issues according start and limit, perPage is not supported
185-
func (g *GogsDownloader) GetIssues(_ context.Context, page, _ int) ([]*base.Issue, bool, error) {
174+
func (g *GogsDownloader) GetIssues(ctx context.Context, page, _ int) ([]*base.Issue, bool, error) {
186175
var state string
187176
if g.openIssuesFinished {
188177
state = string(gogs.STATE_CLOSED)
@@ -192,7 +181,7 @@ func (g *GogsDownloader) GetIssues(_ context.Context, page, _ int) ([]*base.Issu
192181
g.openIssuesPages = page
193182
}
194183

195-
issues, isEnd, err := g.getIssues(page, state)
184+
issues, isEnd, err := g.getIssues(ctx, page, state)
196185
if err != nil {
197186
return nil, false, err
198187
}
@@ -207,10 +196,10 @@ func (g *GogsDownloader) GetIssues(_ context.Context, page, _ int) ([]*base.Issu
207196
return issues, false, nil
208197
}
209198

210-
func (g *GogsDownloader) getIssues(page int, state string) ([]*base.Issue, bool, error) {
199+
func (g *GogsDownloader) getIssues(ctx context.Context, page int, state string) ([]*base.Issue, bool, error) {
211200
allIssues := make([]*base.Issue, 0, 10)
212201

213-
issues, err := g.client.ListRepoIssues(g.repoOwner, g.repoName, gogs.ListIssueOption{
202+
issues, err := g.client.ListRepoIssues(ctx, g.repoOwner, g.repoName, gogs.ListIssueOption{
214203
Page: page,
215204
State: state,
216205
})
@@ -229,10 +218,10 @@ func (g *GogsDownloader) getIssues(page int, state string) ([]*base.Issue, bool,
229218
}
230219

231220
// GetComments returns comments according issueNumber
232-
func (g *GogsDownloader) GetComments(_ context.Context, commentable base.Commentable) ([]*base.Comment, bool, error) {
221+
func (g *GogsDownloader) GetComments(ctx context.Context, commentable base.Commentable) ([]*base.Comment, bool, error) {
233222
allComments := make([]*base.Comment, 0, 100)
234223

235-
comments, err := g.client.ListIssueComments(g.repoOwner, g.repoName, commentable.GetForeignIndex())
224+
comments, err := g.client.ListIssueComments(ctx, g.repoOwner, g.repoName, commentable.GetForeignIndex())
236225
if err != nil {
237226
return nil, false, fmt.Errorf("error while listing repos: %w", err)
238227
}

0 commit comments

Comments
 (0)