-1
appview/pages/pages.go
-1
appview/pages/pages.go
+4
-11
appview/pages/templates/repo/compare.html
+4
-11
appview/pages/templates/repo/compare.html
···
8
8
{{ end }}
9
9
10
10
{{ define "repoContent" }}
11
-
<section>
11
+
<section id="compare-select">
12
12
<h2 class="font-bold text-sm mb-4 uppercase dark:text-white">
13
13
Compare changes
14
14
</h2>
···
152
152
153
153
if (baseToUse && headToUse) {
154
154
const url = `/{{ .RepoInfo.FullName }}/compare/diff/${baseToUse}/${headToUse}`;
155
-
htmx.ajax('GET', url, { target: '#compare-diff' });
156
-
document.title = `comparing ${baseToUse} and ${headToUse}`;
157
155
158
-
const allowPull = `{{ .AllowPull }}`
159
-
if (allowPull) {
160
-
htmx.ajax('GET',
161
-
`/{{ .RepoInfo.FullName }}/compare/allow-pull/${baseToUse}/${headToUse}`,
162
-
{ target: '#allow-pull'},
163
-
)
164
-
}
156
+
// htmx.ajax('GET', url, { target: '#compare-diff' })
157
+
document.title = `comparing ${baseToUse} and ${headToUse}`;
165
158
}
166
159
}
167
160
</script>
168
-
<section id="allow-pull" class="pt-4"></section>
169
161
{{ end }}
170
162
171
163
{{ define "repoAfter" }}
164
+
<div id="allow-pull"></div>
172
165
<div id="compare-diff"></div>
173
166
{{ end }}
+5
-1
appview/pages/templates/repo/fragments/compareAllowPull.html
+5
-1
appview/pages/templates/repo/fragments/compareAllowPull.html
···
1
1
{{ define "repo/fragments/compareAllowPull" }}
2
-
<div class="flex items-baseline justify-normal gap-4">
2
+
<div
3
+
class="flex items-baseline justify-normal gap-4"
4
+
id="allow-pull"
5
+
hx-oob-swap="true"
6
+
>
3
7
<p>
4
8
This comparison can be turned into a pull request to be reviewed and
5
9
discussed.
+10
-1
appview/pages/templates/repo/index.html
+10
-1
appview/pages/templates/repo/index.html
···
66
66
{{ end }}
67
67
</optgroup>
68
68
</select>
69
+
<div class="flex items-center gap-2">
69
70
{{ $isOwner := and .LoggedInUser .RepoInfo.Roles.IsOwner }}
70
71
{{ $isCollaborator := and .LoggedInUser .RepoInfo.Roles.IsCollaborator }}
71
72
{{ if and (or $isOwner $isCollaborator) .ForkInfo .ForkInfo.IsFork }}
···
99
100
<span>sync</span>
100
101
</button>
101
102
{{ end }}
102
-
</div>
103
+
<a
104
+
href="/{{ .RepoInfo.FullName }}/compare"
105
+
class="btn flex items-center gap-2 no-underline hover:no-underline"
106
+
title="Compare branches or tags"
107
+
>
108
+
{{ i "git-compare" "w-4 h-4" }}
109
+
</a>
110
+
</div>
111
+
</div>
103
112
{{ end }}
104
113
105
114
{{ define "fileTree" }}
+30
-11
appview/state/repo.go
+30
-11
appview/state/repo.go
···
2110
2110
}
2111
2111
}
2112
2112
2113
-
var allowPull bool = false
2114
-
if user != nil {
2115
-
if slices.ContainsFunc(branches.Branches, func(branch types.Branch) bool {
2116
-
return branch.Name == head || branch.Name == base
2117
-
}) {
2118
-
allowPull = true
2119
-
}
2120
-
}
2113
+
repoinfo := f.RepoInfo(s, user)
2121
2114
2122
2115
s.pages.RepoCompare(w, pages.RepoCompareParams{
2123
2116
LoggedInUser: user,
2124
-
RepoInfo: f.RepoInfo(s, user),
2117
+
RepoInfo: repoinfo,
2125
2118
Forks: forks,
2126
2119
Branches: branches.Branches,
2127
2120
Tags: tags.Tags,
2128
2121
Base: base,
2129
2122
Head: head,
2130
-
AllowPull: allowPull,
2131
2123
})
2132
2124
2133
2125
}
···
2179
2171
}
2180
2172
diff := patchutil.AsNiceDiff(formatPatch.Patch, base)
2181
2173
2174
+
branches, err := us.Branches(f.OwnerDid(), f.RepoName)
2175
+
if err != nil {
2176
+
s.pages.Notice(w, "compare-error", "Failed to produce comparison. Try again later.")
2177
+
log.Println("failed to fetch branches", err)
2178
+
return
2179
+
}
2180
+
2181
+
repoinfo := f.RepoInfo(s, user)
2182
+
2182
2183
w.Header().Add("Hx-Push-Url", fmt.Sprintf("/%s/compare/%s...%s", f.OwnerSlashRepo(), base, head))
2184
+
w.Header().Add("Content-Type", "text/html")
2183
2185
s.pages.RepoCompareDiff(w, pages.RepoCompareDiffParams{
2184
2186
LoggedInUser: user,
2185
-
RepoInfo: f.RepoInfo(s, user),
2187
+
RepoInfo: repoinfo,
2186
2188
Diff: diff,
2187
2189
})
2190
+
2191
+
// checks if pull is allowed and performs an htmx oob-swap
2192
+
// by writing to the same http.ResponseWriter
2193
+
if user != nil {
2194
+
if slices.ContainsFunc(branches.Branches, func(branch types.Branch) bool {
2195
+
return branch.Name == head || branch.Name == base
2196
+
}) {
2197
+
if repoinfo.Roles.IsPushAllowed() {
2198
+
s.pages.RepoCompareAllowPullFragment(w, pages.RepoCompareAllowPullParams{
2199
+
LoggedInUser: user,
2200
+
RepoInfo: repoinfo,
2201
+
Base: base,
2202
+
Head: head,
2203
+
})
2204
+
}
2205
+
}
2206
+
}
2188
2207
}