2018-03-09 20:18:59 +00:00
|
|
|
import $ from 'jquery';
|
2018-02-12 10:58:45 +00:00
|
|
|
import { parseQueryStringIntoObject } from '~/lib/utils/common_utils';
|
2018-02-08 08:47:31 +00:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2020-08-20 09:09:55 +00:00
|
|
|
import { deprecatedCreateFlash as createFlash } from '~/flash';
|
2018-02-08 08:47:31 +00:00
|
|
|
import { __ } from '~/locale';
|
|
|
|
|
2017-07-25 07:40:23 +00:00
|
|
|
export default class GpgBadges {
|
|
|
|
static fetch() {
|
2018-05-07 08:41:36 +00:00
|
|
|
const tag = $('.js-signature-container');
|
2018-07-23 14:58:21 +00:00
|
|
|
if (tag.length === 0) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
const badges = $('.js-loading-gpg-badge');
|
2017-07-25 07:40:23 +00:00
|
|
|
|
2020-09-14 06:09:28 +00:00
|
|
|
badges.html('<span class="gl-spinner gl-spinner-orange gl-spinner-sm"></span>');
|
|
|
|
badges.children().attr('aria-label', __('Loading'));
|
2017-08-15 08:20:35 +00:00
|
|
|
|
2018-07-23 14:58:21 +00:00
|
|
|
const displayError = () => createFlash(__('An error occurred while loading commit signatures'));
|
|
|
|
|
|
|
|
const endpoint = tag.data('signaturesPath');
|
|
|
|
if (!endpoint) {
|
|
|
|
displayError();
|
2019-05-02 14:36:20 +00:00
|
|
|
return Promise.reject(new Error(__('Missing commit signatures endpoint!')));
|
2018-07-23 14:58:21 +00:00
|
|
|
}
|
|
|
|
|
2018-05-07 08:41:36 +00:00
|
|
|
const params = parseQueryStringIntoObject(tag.serialize());
|
2018-07-23 14:58:21 +00:00
|
|
|
return axios
|
|
|
|
.get(endpoint, { params })
|
|
|
|
.then(({ data }) => {
|
2020-12-24 00:10:25 +00:00
|
|
|
data.signatures.forEach((signature) => {
|
2018-07-23 14:58:21 +00:00
|
|
|
badges.filter(`[data-commit-sha="${signature.commit_sha}"]`).replaceWith(signature.html);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(displayError);
|
2017-07-25 07:40:23 +00:00
|
|
|
}
|
|
|
|
}
|