2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2018-02-12 05:58:45 -05:00
|
|
|
import { parseQueryStringIntoObject } from '~/lib/utils/common_utils';
|
2018-02-08 03:47:31 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2018-07-23 10:58:21 -04:00
|
|
|
import createFlash from '~/flash';
|
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
|
|
|
|
2017-08-15 04:20:35 -04:00
|
|
|
badges.html('<i class="fa fa-spinner fa-spin"></i>');
|
|
|
|
|
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 }) => {
|
|
|
|
data.signatures.forEach(signature => {
|
|
|
|
badges.filter(`[data-commit-sha="${signature.commit_sha}"]`).replaceWith(signature.html);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(displayError);
|
2017-07-25 03:40:23 -04:00
|
|
|
}
|
|
|
|
}
|