2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2021-09-04 01:27:46 +05:30
|
|
|
import 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
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
const displayError = () =>
|
|
|
|
createFlash({
|
|
|
|
message: __('An error occurred while loading commit signatures'),
|
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|