forked from sindresorhus/new-github-issue-url
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (37 loc) · 964 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
module.exports = (options = {}) => {
let repoUrl;
if (options.repoUrl) {
repoUrl = options.repoUrl;
} else if (options.user && options.repo) {
repoUrl = `https://github.com/${options.user}/${options.repo}`;
} else {
throw new Error('You need to specify either the `repoUrl` option or both the `user` and `repo` options');
}
const url = new URL(`${repoUrl}/issues/new`);
const types = [
'body',
'title',
'labels',
'template',
'milestone',
'assignee',
'projects'
];
for (const type of types) {
let value = options[type];
if (value === undefined) {
continue;
}
if (type === 'labels' || type === 'projects') {
if (!Array.isArray(value)) {
throw new TypeError(`The \`${type}\` option should be an array`);
}
value = value.join(',');
}
url.searchParams.set(type, value);
}
return url.toString();
};
// TODO: Remove this for the next major release
module.exports.default = module.exports;