Skip to content

Commit f8519ed

Browse files
committed
don't allow making subscriptions that match pseudoversions but not prerelease versions
they will never match
1 parent be1d8c0 commit f8519ed

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

api.go

+6
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,9 @@ func (API) SubscriptionCreate(ctx context.Context, sub Subscription) Subscriptio
977977
reqInfo := ctx.Value(requestInfoCtxKey).(requestInfo)
978978

979979
xcheckModule(sub.Module)
980+
if sub.Pseudo && !sub.Prerelease {
981+
xusererrorf("subscription for pseudoversions without prerelease versions will never match")
982+
}
980983

981984
sub.ID = 0
982985
sub.UserID = reqInfo.UserID
@@ -1056,6 +1059,9 @@ func (API) SubscriptionSave(ctx context.Context, sub Subscription) {
10561059
reqInfo := ctx.Value(requestInfoCtxKey).(requestInfo)
10571060

10581061
xcheckModule(sub.Module)
1062+
if sub.Pseudo && !sub.Prerelease {
1063+
xusererrorf("subscription for pseudoversions without prerelease versions will never match")
1064+
}
10591065

10601066
err := database.Write(ctx, func(tx *bstore.Tx) error {
10611067
exists, err := bstore.QueryTx[Subscription](tx).FilterNonzero(Subscription{ID: sub.ID, UserID: reqInfo.UserID}).Exists()

index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,11 @@ const subscriptionPopup = (sub, subscriptions, hookconfigs, render) => {
10511051
// User may input a URL, better fix it for them instead of making the user fix it.
10521052
module.value = module.value.replace(/^https?:\/\//, '');
10531053
module.value = module.value.replace(/\/*$/, '');
1054-
}), dom.div(dom._class('explain'), 'Enter a single module as you would use in a Go import statement.', dom.br(), 'Example: github.com/mjl-/gopherwatch, github.com/mjl- or golang.org.'))), dom.br(), dom.b('Notify about ...'), dom.label(belowModule = dom.input(attr.type('checkbox'), sub.BelowModule ? attr.checked('') : []), ' ', dom.span('Sub modules', attr.title('E.g. if subscribed to github.com/mjl-, whether to match github.com/mjl-/gopherwatch.'))), dom.label(olderVersions = dom.input(attr.type('checkbox'), sub.OlderVersions ? attr.checked('') : []), ' ', dom.span('Older versions than already seen', attr.title('Can happen when an old version (tag) is requested through the Go module proxy after a later tag, not uncommon after forking a repository and pushing all historic tags.'))), dom.label(prerelease = dom.input(attr.type('checkbox'), sub.Prerelease ? attr.checked('') : []), ' Prereleases such as v1.2.3-beta1'), dom.label(pseudo = dom.input(attr.type('checkbox'), sub.Pseudo ? attr.checked('') : []), ' Pseudo versions, such as v0.0.0-20240222094833-a1bd684a916b'), dom.br(), dom.label('Comment',
1054+
}), dom.div(dom._class('explain'), 'Enter a single module as you would use in a Go import statement.', dom.br(), 'Example: github.com/mjl-/gopherwatch, github.com/mjl- or golang.org.'))), dom.br(), dom.b('Notify about ...'), dom.label(belowModule = dom.input(attr.type('checkbox'), sub.BelowModule ? attr.checked('') : []), ' ', dom.span('Sub modules', attr.title('E.g. if subscribed to github.com/mjl-, whether to match github.com/mjl-/gopherwatch.'))), dom.label(olderVersions = dom.input(attr.type('checkbox'), sub.OlderVersions ? attr.checked('') : []), ' ', dom.span('Older versions than already seen', attr.title('Can happen when an old version (tag) is requested through the Go module proxy after a later tag, not uncommon after forking a repository and pushing all historic tags.'))), dom.label(prerelease = dom.input(attr.type('checkbox'), sub.Prerelease ? attr.checked('') : []), ' Prereleases such as v1.2.3-beta1'), dom.label(pseudo = dom.input(attr.type('checkbox'), sub.Pseudo ? attr.checked('') : [], function change() {
1055+
if (pseudo.checked) {
1056+
prerelease.checked = true;
1057+
}
1058+
}), ' Pseudo versions, such as v0.0.0-20240222094833-a1bd684a916b'), attr.title('Pseudo versions are always prereleases. In order to match a pseudoversion, prerelease must also be checked.'), dom.br(), dom.label('Comment',
10551059
// explicit String to prevent special scriptswitch handling
10561060
comment = dom.textarea(new String(sub.Comment))), dom.br(), dom.label('Delivery method', dom.div(webhookconfig = dom.select(dom.option('Email', attr.value('0')), hookconfigs.map(hc => dom.option('Webhook ' + hc.Name, attr.value('' + hc.ID), sub.HookConfigID === hc.ID ? attr.selected('') : []))))), dom.br(), dom.div(submitbtn = dom.submitbutton(sub.ID ? 'Save subscription' : 'Add subscription')))));
10571061
module.focus();

index.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,18 @@ const subscriptionPopup = (sub: api.Subscription, subscriptions: api.Subscriptio
296296
dom.label(belowModule=dom.input(attr.type('checkbox'), sub.BelowModule ? attr.checked('') : []), ' ', dom.span('Sub modules', attr.title('E.g. if subscribed to github.com/mjl-, whether to match github.com/mjl-/gopherwatch.'))),
297297
dom.label(olderVersions=dom.input(attr.type('checkbox'), sub.OlderVersions ? attr.checked('') : []), ' ', dom.span('Older versions than already seen', attr.title('Can happen when an old version (tag) is requested through the Go module proxy after a later tag, not uncommon after forking a repository and pushing all historic tags.'))),
298298
dom.label(prerelease=dom.input(attr.type('checkbox'), sub.Prerelease ? attr.checked('') : []), ' Prereleases such as v1.2.3-beta1'),
299-
dom.label(pseudo=dom.input(attr.type('checkbox'), sub.Pseudo ? attr.checked('') : []), ' Pseudo versions, such as v0.0.0-20240222094833-a1bd684a916b'),
299+
dom.label(
300+
pseudo=dom.input(
301+
attr.type('checkbox'),
302+
sub.Pseudo ? attr.checked('') : [],
303+
function change() {
304+
if (pseudo.checked) {
305+
prerelease.checked = true
306+
}
307+
},
308+
),
309+
' Pseudo versions, such as v0.0.0-20240222094833-a1bd684a916b'),
310+
attr.title('Pseudo versions are always prereleases. In order to match a pseudoversion, prerelease must also be checked.'),
300311
dom.br(),
301312
dom.label(
302313
'Comment',

0 commit comments

Comments
 (0)