2019-08-13 19:37:22 +03:00
|
|
|
var Promise = require('promise')
|
|
|
|
var requestPromise = require('./helpers/requestPromise.js')
|
|
|
|
var BasePlugin = require('./base.js')
|
|
|
|
const logger = require('../logger')
|
2017-03-12 18:36:32 +02:00
|
|
|
|
|
|
|
class Kernel extends BasePlugin {
|
2019-08-13 19:37:22 +03:00
|
|
|
constructor (config) {
|
|
|
|
super(config)
|
|
|
|
this.name = 'Kernel'
|
|
|
|
}
|
|
|
|
getKernelData (queryText) {
|
|
|
|
var urlArgs = {}
|
|
|
|
var url = 'https://www.kernel.org/releases.json'
|
2017-03-12 18:36:32 +02:00
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
var promise = requestPromise(url, urlArgs)
|
2017-03-12 18:36:32 +02:00
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
return promise
|
2017-03-12 18:36:32 +02:00
|
|
|
}
|
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
test (input) {
|
2017-03-12 18:36:32 +02:00
|
|
|
// Kernel version
|
2019-08-13 19:37:22 +03:00
|
|
|
if (input.match(/^\.kernel( (.+))?/i)) {
|
|
|
|
return true
|
2017-03-12 18:36:32 +02:00
|
|
|
}
|
2019-08-13 19:37:22 +03:00
|
|
|
return false
|
2017-03-12 18:36:32 +02:00
|
|
|
}
|
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
result (input) {
|
|
|
|
var that = this
|
|
|
|
var resultPromise = new Promise(function (resolve, reject) {
|
|
|
|
var res = input.match(/^\.kernel( (.+))?/i)
|
|
|
|
if (res !== null) {
|
|
|
|
var version = res[2]
|
|
|
|
logger.info('Search kernel version ' + res[2])
|
2017-03-12 18:36:32 +02:00
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
that.getKernelData().then(function (data) {
|
|
|
|
var text = 'kernel: '
|
2017-03-12 18:36:32 +02:00
|
|
|
|
|
|
|
// Store current versions!
|
2019-08-13 19:37:22 +03:00
|
|
|
var releaseToVersion = {}
|
|
|
|
data.releases.forEach(function (val) {
|
|
|
|
var regex = /([0-9]+?)(\.([0-9]+))?(\.([0-9]+))?/
|
|
|
|
var result = val.version.match(regex)
|
2017-03-12 18:36:32 +02:00
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
var major = result[1]
|
|
|
|
var minor = result[3]
|
2017-03-12 18:36:32 +02:00
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
if (typeof major !== 'undefined' && typeof minor !== 'undefined') {
|
|
|
|
var releaseWithVersion = val.moniker + '-' + major + '-' + minor
|
|
|
|
var release = val.moniker + ''
|
2017-03-12 18:36:32 +02:00
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
if (typeof releaseToVersion[releaseWithVersion] !== 'undefined') {
|
|
|
|
if (releaseToVersion[releaseWithVersion] !== val.version) {
|
2017-03-12 18:36:32 +02:00
|
|
|
// new release
|
|
|
|
}
|
|
|
|
}
|
2019-08-13 19:37:22 +03:00
|
|
|
if (typeof releaseToVersion[release] === 'undefined') {
|
|
|
|
releaseToVersion[release] = val.version
|
2017-03-12 18:36:32 +02:00
|
|
|
}
|
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
releaseToVersion[releaseWithVersion] = val.version
|
2017-03-12 18:36:32 +02:00
|
|
|
}
|
2019-08-13 19:37:22 +03:00
|
|
|
}, function (error) {
|
|
|
|
reject(error)
|
|
|
|
})
|
2017-03-12 18:36:32 +02:00
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
if (typeof releaseToVersion[version] !== 'undefined') {
|
|
|
|
text += 'Viimeisin versio on ' + releaseToVersion[version] + ' (' + version + ')'
|
2017-03-12 18:36:32 +02:00
|
|
|
} else {
|
2019-08-13 19:37:22 +03:00
|
|
|
text += 'Viimeisin vakaa versio on ' + data.latest_stable.version
|
2017-03-12 18:36:32 +02:00
|
|
|
}
|
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
resolve(text)
|
|
|
|
}, function (error) {
|
|
|
|
reject(error)
|
|
|
|
})
|
2017-03-12 18:36:32 +02:00
|
|
|
}
|
2019-08-13 19:37:22 +03:00
|
|
|
})
|
2017-03-12 18:36:32 +02:00
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
return resultPromise
|
2017-03-12 18:36:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 19:37:22 +03:00
|
|
|
module.exports = Kernel
|