-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
52 lines (49 loc) · 1.21 KB
/
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
47
48
49
50
51
52
const got = require('got');
const VERSION = 'v2';
const ENDPOINT = `https://hub.docker.com/${VERSION}/search/repositories/`;
/**
* Retrieve the repository URL for the given item
*
* If the result is an official repo, append the "_" prefix path.
*
* @param {Object} result
* @return {String}
*/
const getRepositoryUrl = (result) => {
const repo = result.is_official ? `_/${result.repo_name}` : result.repo_name;
return `https://hub.docker.com/r/${repo}`;
};
module.exports = {
keyword: 'docker',
action: 'openurl',
helper: {
title: 'Search for images in the Docker Registry',
subtitle: 'Example: docker node',
icon: {
path: './icon.png',
},
},
query: q => new Promise((resolve) => {
const opts = {
query: {
query: q,
},
json: true,
};
got(ENDPOINT, opts)
.then((res) => {
if (res.body) {
const items = res.body.results
.map(i => Object.assign({}, {
title: i.repo_name,
subtitle: i.short_description,
arg: getRepositoryUrl(i),
icon: {
path: './icon.png',
},
}));
resolve({ items });
}
});
}),
};