Skip to content

Commit af87f71

Browse files
committed
when adding a subscriptiong, automatically turn urls to modules into import paths
for #23 reported by emicklei
1 parent 0f2eb89 commit af87f71

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

index.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ var api;
413413
return v;
414414
}
415415
}
416-
error('unknkown value ' + v + ' for named strings ' + t.Name);
416+
error('unknown value ' + v + ' for named strings ' + t.Name);
417417
}
418418
else if (api.intsTypes[nt.Name]) {
419419
const t = nt;
@@ -428,7 +428,7 @@ var api;
428428
return v;
429429
}
430430
}
431-
error('unknkown value ' + v + ' for named ints ' + t.Name);
431+
error('unknown value ' + v + ' for named ints ' + t.Name);
432432
}
433433
else {
434434
throw new Error('unexpected named type ' + nt);
@@ -1006,7 +1006,11 @@ const subscriptionPopup = (sub, subscriptions, render) => {
10061006
dom._kids(modulegomod, dom.label('Contents of go.mod', gomod = dom.textarea(attr.required(''), attr.rows('12'))), dom.div(dom._class('explain'), 'Paste the contents of your go.mod. Subscriptions will be created for all direct dependencies.'), dom.label(indirect = dom.input(attr.type('checkbox')), ' Also subscribe to indirect dependencies'), dom.br());
10071007
dom._kids(submitbtn, 'Add subscriptions for dependencies');
10081008
}),
1009-
]), dom.div(module = dom.input(attr.required(''), attr.value(sub.Module)), 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',
1009+
]), dom.div(module = dom.input(attr.required(''), attr.value(sub.Module), function change() {
1010+
// User may input a URL, better fix it for them instead of making the user fix it.
1011+
module.value = module.value.replace(/^https?:\/\//, '');
1012+
module.value = module.value.replace(/\/*$/, '');
1013+
}), 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',
10101014
// explicit String to prevent special scriptswitch handling
10111015
comment = dom.textarea(new String(sub.Comment))), dom.br(), dom.div(submitbtn = dom.submitbutton(sub.ID ? 'Save subscription' : 'Add subscription')))));
10121016
module.focus();

index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,11 @@ const subscriptionPopup = (sub: api.Subscription, subscriptions: api.Subscriptio
280280
],
281281
),
282282
dom.div(
283-
module=dom.input(attr.required(''), attr.value(sub.Module)),
283+
module=dom.input(attr.required(''), attr.value(sub.Module), function change() {
284+
// User may input a URL, better fix it for them instead of making the user fix it.
285+
module.value = module.value.replace(/^https?:\/\//, '')
286+
module.value = module.value.replace(/\/*$/, '')
287+
}),
284288
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.'),
285289
),
286290
),

0 commit comments

Comments
 (0)