Merge pull request #2325 from haslinghuis/jenkins

Change lexical scope jenkins
10.8-maintenance
Michael Keller 2020-12-28 00:49:21 +01:00 committed by GitHub
commit 760485b00f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 43 additions and 38 deletions

View File

@ -1,6 +1,6 @@
'use strict';
var JenkinsLoader = function (url) {
const JenkinsLoader = function (url) {
this._url = url;
this._jobs = [];
this._cacheExpirationPeriod = 3600 * 1000;
@ -10,23 +10,23 @@ var JenkinsLoader = function (url) {
}
JenkinsLoader.prototype.loadJobs = function (viewName, callback) {
var self = this;
const self = this;
var viewUrl = `${self._url}/view/${viewName}`;
var jobsDataTag = `${viewUrl}_JobsData`;
var cacheLastUpdateTag = `${viewUrl}_JobsLastUpdate`;
const viewUrl = `${self._url}/view/${viewName}`;
const jobsDataTag = `${viewUrl}_JobsData`;
const cacheLastUpdateTag = `${viewUrl}_JobsLastUpdate`;
var wrappedCallback = jobs => {
const wrappedCallback = jobs => {
self._jobs = jobs;
callback(jobs);
};
chrome.storage.local.get([cacheLastUpdateTag, jobsDataTag], function (result) {
var jobsDataTimestamp = $.now();
var cachedJobsData = result[jobsDataTag];
var cachedJobsLastUpdate = result[cacheLastUpdateTag];
const jobsDataTimestamp = $.now();
const cachedJobsData = result[jobsDataTag];
const cachedJobsLastUpdate = result[cacheLastUpdateTag];
var cachedCallback = () => {
const cachedCallback = () => {
if (cachedJobsData) {
GUI.log(i18n.getMessage('buildServerUsingCached', ['jobs']));
}
@ -35,18 +35,18 @@ JenkinsLoader.prototype.loadJobs = function (viewName, callback) {
};
if (!cachedJobsData || !cachedJobsLastUpdate || jobsDataTimestamp - cachedJobsLastUpdate > self._cacheExpirationPeriod) {
var url = `${viewUrl}${self._jobsRequest}`;
const url = `${viewUrl}${self._jobsRequest}`;
$.get(url, jobsInfo => {
GUI.log(i18n.getMessage('buildServerLoaded', ['jobs']));
// remove Betaflight prefix, rename Betaflight job to Development
var jobs = jobsInfo.jobs.map(job => {
const jobs = jobsInfo.jobs.map(job => {
return { title: job.name.replace('Betaflight ', '').replace('Betaflight', 'Development'), name: job.name };
})
// cache loaded info
let object = {}
const object = {}
object[jobsDataTag] = jobs;
object[cacheLastUpdateTag] = $.now();
chrome.storage.local.set(object);
@ -63,18 +63,18 @@ JenkinsLoader.prototype.loadJobs = function (viewName, callback) {
}
JenkinsLoader.prototype.loadBuilds = function (jobName, callback) {
var self = this;
const self = this;
var jobUrl = `${self._url}/job/${jobName}`;
var buildsDataTag = `${jobUrl}BuildsData`;
var cacheLastUpdateTag = `${jobUrl}BuildsLastUpdate`
const jobUrl = `${self._url}/job/${jobName}`;
const buildsDataTag = `${jobUrl}BuildsData`;
const cacheLastUpdateTag = `${jobUrl}BuildsLastUpdate`
chrome.storage.local.get([cacheLastUpdateTag, buildsDataTag], function (result) {
var buildsDataTimestamp = $.now();
var cachedBuildsData = result[buildsDataTag];
var cachedBuildsLastUpdate = result[cacheLastUpdateTag];
const buildsDataTimestamp = $.now();
const cachedBuildsData = result[buildsDataTag];
const cachedBuildsLastUpdate = result[cacheLastUpdateTag];
var cachedCallback = () => {
const cachedCallback = () => {
if (cachedBuildsData) {
GUI.log(i18n.getMessage('buildServerUsingCached', [jobName]));
}
@ -83,22 +83,22 @@ JenkinsLoader.prototype.loadBuilds = function (jobName, callback) {
};
if (!cachedBuildsData || !cachedBuildsLastUpdate || buildsDataTimestamp - cachedBuildsLastUpdate > self._cacheExpirationPeriod) {
var url = `${jobUrl}${self._buildsRequest}`;
const url = `${jobUrl}${self._buildsRequest}`;
$.get(url, function (buildsInfo) {
GUI.log(i18n.getMessage('buildServerLoaded', [jobName]));
// filter successful builds
var builds = buildsInfo.builds.filter(build => build.result == 'SUCCESS')
const builds = buildsInfo.builds.filter(build => build.result == 'SUCCESS')
.map(build => ({
number: build.number,
artifacts: build.artifacts.map(artifact => artifact.relativePath),
changes: build.changeSet.items.map(item => '* ' + item.msg).join('<br>\n'),
changes: build.changeSet.items.map(item => `* ${item.msg}`).join('<br>\n'),
timestamp: build.timestamp
}));
// cache loaded info
let object = {}
const object = {}
object[buildsDataTag] = builds;
object[cacheLastUpdateTag] = $.now();
chrome.storage.local.set(object);
@ -116,30 +116,35 @@ JenkinsLoader.prototype.loadBuilds = function (jobName, callback) {
JenkinsLoader.prototype._parseBuilds = function (jobUrl, jobName, builds, callback) {
// convert from `build -> targets` to `target -> builds` mapping
var targetBuilds = {};
const targetBuilds = {};
var targetFromFilenameExpression = /betaflight_([\d.]+)?_?(\w+)(\-.*)?\.(.*)/;
const targetFromFilenameExpression = /betaflight_([\d.]+)?_?(\w+)(\-.*)?\.(.*)/;
builds.forEach(build => {
build.artifacts.forEach(relativePath => {
var match = targetFromFilenameExpression.exec(relativePath);
const match = targetFromFilenameExpression.exec(relativePath);
if (!match) {
return;
}
var version = match[1];
var target = match[2];
var date = new Date(build.timestamp);
const version = match[1];
const target = match[2];
const date = new Date(build.timestamp);
var formattedDate = ("0" + date.getDate()).slice(-2) + "-" + ("0" + (date.getMonth()+1)).slice(-2) + "-" +
date.getFullYear() + " " + ("0" + date.getHours()).slice(-2) + ":" + ("0" + date.getMinutes()).slice(-2);
const day = (`0${date.getDate()}`).slice(-2);
const month = (`0${(date.getMonth() + 1)}`).slice(-2);
const year = date.getFullYear();
const hours = (`0${date.getHours()}`).slice(-2);
const minutes = (`0${date.getMinutes()}`).slice(-2);
var descriptor = {
'releaseUrl': jobUrl + '/' + build.number,
'name' : jobName + ' #' + build.number,
'version' : version + ' #' + build.number,
'url' : jobUrl + '/' + build.number + '/artifact/' + relativePath,
const formattedDate = `${day}-${month}-${year} ${hours}:${minutes}`;
const descriptor = {
'releaseUrl': `${jobUrl}/${build.number}`,
'name' : `${jobName} #${build.number}`,
'version' : `${version} #${build.number}`,
'url' : `${jobUrl}/${build.number}/artifact/${relativePath}`,
'file' : relativePath.split('/').slice(-1)[0],
'target' : target,
'date' : formattedDate,