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