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

38 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2020-10-24 23:57:45 +05:30
import { deprecatedCreateFlash as createFlash } from '~/flash';
2021-03-11 19:13:27 +05:30
import axios from '~/lib/utils/axios_utils';
import { parseQueryStringIntoObject } from '~/lib/utils/common_utils';
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
2020-11-24 15:15:51 +05:30
badges.html('<span class="gl-spinner gl-spinner-orange gl-spinner-sm"></span>');
badges.children().attr('aria-label', __('Loading'));
2017-09-10 17:25:29 +05:30
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();
2019-09-04 21:01:54 +05:30
return Promise.reject(new Error(__('Missing commit signatures endpoint!')));
2018-11-18 11:00:15 +05:30
}
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 }) => {
2021-03-08 18:12:59 +05:30
data.signatures.forEach((signature) => {
2018-11-18 11:00:15 +05:30
badges.filter(`[data-commit-sha="${signature.commit_sha}"]`).replaceWith(signature.html);
});
})
.catch(displayError);
2017-09-10 17:25:29 +05:30
}
}