debian-mirror-gitlab/app/assets/javascripts/gpg_badges.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-03-27 19:54:05 +05:30
import { parseQueryStringIntoObject } from '~/lib/utils/common_utils';
import axios from '~/lib/utils/axios_utils';
2018-11-18 11:00:15 +05:30
import createFlash from '~/flash';
2018-03-27 19:54:05 +05:30
import { __ } from '~/locale';
2017-09-10 17:25:29 +05:30
export default class GpgBadges {
static fetch() {
2018-10-15 14:42:47 +05:30
const tag = $('.js-signature-container');
2018-11-18 11:00:15 +05:30
if (tag.length === 0) {
return Promise.resolve();
}
const badges = $('.js-loading-gpg-badge');
2017-09-10 17:25:29 +05:30
badges.html('<i class="fa fa-spinner fa-spin"></i>');
2018-11-18 11:00:15 +05:30
const displayError = () => createFlash(__('An error occurred while loading commit signatures'));
const endpoint = tag.data('signaturesPath');
if (!endpoint) {
displayError();
return Promise.reject(new Error('Missing commit signatures endpoint!'));
}
2018-10-15 14:42:47 +05:30
const params = parseQueryStringIntoObject(tag.serialize());
2018-11-18 11:00:15 +05:30
return axios
.get(endpoint, { params })
.then(({ data }) => {
data.signatures.forEach(signature => {
badges.filter(`[data-commit-sha="${signature.commit_sha}"]`).replaceWith(signature.html);
});
})
.catch(displayError);
2017-09-10 17:25:29 +05:30
}
}