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

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2022-11-25 23:54:43 +05:30
import { createAlert } from '~/flash';
2021-03-11 19:13:27 +05:30
import axios from '~/lib/utils/axios_utils';
2021-09-30 23:02:18 +05:30
import { queryToObject } from '~/lib/utils/url_utility';
2022-05-07 20:08:51 +05:30
import { loadingIconForLegacyJS } from '~/loading_icon_for_legacy_js';
2021-09-30 23:02:18 +05:30
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
2022-05-07 20:08:51 +05:30
badges.html(loadingIconForLegacyJS());
2020-11-24 15:15:51 +05:30
badges.children().attr('aria-label', __('Loading'));
2017-09-10 17:25:29 +05:30
2021-09-04 01:27:46 +05:30
const displayError = () =>
2022-11-25 23:54:43 +05:30
createAlert({
2021-09-04 01:27:46 +05:30
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
}
2021-09-30 23:02:18 +05:30
const params = queryToObject(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
}
}