+93
-3
appview/pages/templates/repo/pulls/pulls.html
+93
-3
appview/pages/templates/repo/pulls/pulls.html
···
1
1
{{ define "title" }}pulls · {{ .RepoInfo.FullName }}{{ end }}
2
2
3
3
{{ define "repoContent" }}
4
-
<p class="text-gray-400">
5
-
Support for pull requests is actively being worked on. Stay tuned!
6
-
</p>
4
+
<div class="flex justify-between items-center">
5
+
<p>
6
+
filtering
7
+
<select
8
+
class="border px-1 bg-white border-gray-200"
9
+
onchange="window.location.href = '/{{ .RepoInfo.FullName }}/pulls?state=' + this.value"
10
+
>
11
+
<option value="open" {{ if .FilteringByOpen }}selected{{ end }}>
12
+
open
13
+
</option>
14
+
<option
15
+
value="closed"
16
+
{{ if eq .FilteringState "closed" }}selected{{ end }}
17
+
>
18
+
closed
19
+
</option>
20
+
<option
21
+
value="merged"
22
+
{{ if eq .FilteringState "merged" }}selected{{ end }}
23
+
>
24
+
merged
25
+
</option>
26
+
</select>
27
+
pull requests
28
+
</p>
29
+
<a
30
+
href="/{{ .RepoInfo.FullName }}/pulls/new"
31
+
class="btn text-sm flex items-center gap-2 no-underline hover:no-underline"
32
+
>
33
+
<i data-lucide="git-pull-request" class="w-5 h-5"></i>
34
+
<span>new pull request</span>
35
+
</a>
36
+
</div>
37
+
<div class="error" id="pulls"></div>
38
+
{{ end }}
39
+
40
+
{{ define "repoAfter" }}
41
+
<div class="flex flex-col gap-2 mt-8">
42
+
{{ range .Pulls }}
43
+
<div class="rounded drop-shadow-sm bg-white px-6 py-4">
44
+
<div class="pb-2">
45
+
<a
46
+
href="/{{ $.RepoInfo.FullName }}/pulls/{{ .PullId }}"
47
+
class="no-underline hover:underline"
48
+
>
49
+
{{ .Title }}
50
+
<span class="text-gray-500">#{{ .PullId }}</span>
51
+
</a>
52
+
</div>
53
+
<p class="text-sm text-gray-500">
54
+
{{ $bgColor := "bg-gray-800" }}
55
+
{{ $icon := "ban" }}
56
+
{{ $state := "closed" }}
57
+
58
+
{{ if eq .Open 1 }}
59
+
{{ $bgColor = "bg-green-600" }}
60
+
{{ $icon = "git-pull-request" }}
61
+
{{ $state = "open" }}
62
+
{{ else if eq .Open 2 }}
63
+
{{ $bgColor = "bg-purple-600" }}
64
+
{{ $icon = "git-merge" }}
65
+
{{ $state = "merged" }}
66
+
{{ end }}
67
+
68
+
69
+
<span
70
+
class="inline-flex items-center rounded px-2 py-[5px] {{ $bgColor }} text-sm"
71
+
>
72
+
<i
73
+
data-lucide="{{ $icon }}"
74
+
class="w-3 h-3 mr-1.5 text-white"
75
+
></i>
76
+
<span class="text-white">{{ $state }}</span>
77
+
</span>
78
+
79
+
<span>
80
+
{{ $owner := index $.DidHandleMap .OwnerDid }}
81
+
<a href="/{{ $owner }}">{{ $owner }}</a>
82
+
</span>
83
+
84
+
<span class="before:content-['·']">
85
+
<time>
86
+
{{ .Created | timeFmt }}
87
+
</time>
88
+
</span>
89
+
90
+
<span class="before:content-['·']">
91
+
targeting branch <code>{{ .TargetBranch }}</code>
92
+
</span>
93
+
</p>
94
+
</div>
95
+
{{ end }}
96
+
</div>
7
97
{{ end }}
+60
-5
appview/state/repo.go
+60
-5
appview/state/repo.go
···
253
253
return
254
254
}
255
255
256
-
err = db.EditPatch(s.db, f.RepoAt, prIdInt, patch)
256
+
// Get pull information before updating to get the atproto record URI
257
+
pull, _, err := db.GetPullWithComments(s.db, f.RepoAt, prIdInt)
258
+
if err != nil {
259
+
log.Println("failed to get pull information", err)
260
+
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
261
+
return
262
+
}
263
+
264
+
// Start a transaction for database operations
265
+
tx, err := s.db.BeginTx(r.Context(), nil)
266
+
if err != nil {
267
+
log.Println("failed to start transaction", err)
268
+
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
269
+
return
270
+
}
271
+
272
+
// Set up deferred rollback that will be overridden by commit if successful
273
+
defer tx.Rollback()
274
+
275
+
// Update patch in the database within transaction
276
+
err = db.EditPatch(tx, f.RepoAt, prIdInt, patch)
257
277
if err != nil {
258
278
log.Println("failed to update patch", err)
259
279
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
260
280
return
261
281
}
262
282
263
-
// Get target branch after patch update
264
-
pull, _, err := db.GetPullWithComments(s.db, f.RepoAt, prIdInt)
283
+
// Update the atproto record
284
+
client, _ := s.auth.AuthorizedClient(r)
285
+
pullAt := pull.PullAt
286
+
287
+
// Get the existing record first
288
+
ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoPullNSID, user.Did, pullAt.RecordKey().String())
289
+
if err != nil {
290
+
log.Println("failed to get existing pull record", err)
291
+
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
292
+
return
293
+
}
294
+
295
+
// Update the record
296
+
_, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{
297
+
Collection: tangled.RepoPullNSID,
298
+
Repo: user.Did,
299
+
Rkey: pullAt.RecordKey().String(),
300
+
SwapRecord: ex.Cid,
301
+
Record: &lexutil.LexiconTypeDecoder{
302
+
Val: &tangled.RepoPull{
303
+
Title: pull.Title,
304
+
PullId: int64(pull.PullId),
305
+
TargetRepo: string(f.RepoAt),
306
+
TargetBranch: pull.TargetBranch,
307
+
Patch: patch,
308
+
},
309
+
},
310
+
})
311
+
265
312
if err != nil {
266
-
log.Println("failed to get pull information", err)
267
-
s.pages.Notice(w, "pull-success", "Patch updated successfully.")
313
+
log.Println("failed to update pull record in atproto", err)
314
+
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
315
+
return
316
+
}
317
+
318
+
// Commit the transaction now that both operations have succeeded
319
+
err = tx.Commit()
320
+
if err != nil {
321
+
log.Println("failed to commit transaction", err)
322
+
s.pages.Notice(w, "pull-error", "Failed to edit patch. Try again later.")
268
323
return
269
324
}
270
325