UNPKG

838 BJavaScriptView Raw
1// TODO: Remove this file and depend on `new-github-release-url` when we target Node.js 10
2'use strict';
3const {URL} = require('url');
4
5module.exports = (options = {}) => {
6 let repoUrl;
7 if (options.repoUrl) {
8 repoUrl = options.repoUrl;
9 } else if (options.user && options.repo) {
10 repoUrl = `https://github.com/${options.user}/${options.repo}`;
11 } else {
12 throw new Error('You need to specify either the `repoUrl` option or both the `user` and `repo` options');
13 }
14
15 const url = new URL(`${repoUrl}/releases/new`);
16
17 const types = [
18 'tag',
19 'target',
20 'title',
21 'body',
22 'isPrerelease'
23 ];
24
25 for (let type of types) {
26 const value = options[type];
27 if (value === undefined) {
28 continue;
29 }
30
31 if (type === 'isPrerelease') {
32 type = 'prerelease';
33 }
34
35 url.searchParams.set(type, value);
36 }
37
38 return url.toString();
39};