2021-07-13 18:09:19 +00:00
|
|
|
<script>
|
|
|
|
import {SvgIcon} from '../svg.js';
|
2024-04-07 16:19:25 +00:00
|
|
|
import {contrastColor} from '../utils/color.js';
|
2024-02-24 12:03:53 +00:00
|
|
|
import {GET} from '../modules/fetch.js';
|
2024-03-29 19:41:13 +00:00
|
|
|
import {emojiHTML} from '../features/emoji.js';
|
|
|
|
import {htmlEscape} from 'escape-goat';
|
2021-07-13 18:09:19 +00:00
|
|
|
|
2021-12-28 13:28:27 +00:00
|
|
|
const {appSubUrl, i18n} = window.config;
|
2021-07-13 18:09:19 +00:00
|
|
|
|
|
|
|
export default {
|
2022-12-23 16:03:11 +00:00
|
|
|
components: {SvgIcon},
|
2021-07-13 18:09:19 +00:00
|
|
|
data: () => ({
|
|
|
|
loading: false,
|
2021-12-28 13:28:27 +00:00
|
|
|
issue: null,
|
|
|
|
i18nErrorOccurred: i18n.error_occurred,
|
|
|
|
i18nErrorMessage: null,
|
2021-07-13 18:09:19 +00:00
|
|
|
}),
|
|
|
|
computed: {
|
|
|
|
createdAt() {
|
|
|
|
return new Date(this.issue.created_at).toLocaleDateString(undefined, {year: 'numeric', month: 'short', day: 'numeric'});
|
|
|
|
},
|
|
|
|
|
|
|
|
body() {
|
|
|
|
const body = this.issue.body.replace(/\n+/g, ' ');
|
|
|
|
if (body.length > 85) {
|
|
|
|
return `${body.substring(0, 85)}…`;
|
|
|
|
}
|
|
|
|
return body;
|
|
|
|
},
|
|
|
|
|
|
|
|
icon() {
|
|
|
|
if (this.issue.pull_request !== null) {
|
2024-07-16 14:38:46 +00:00
|
|
|
if (this.issue.pull_request.merged === true) {
|
2021-07-13 18:09:19 +00:00
|
|
|
return 'octicon-git-merge'; // Merged PR
|
|
|
|
}
|
2024-07-16 14:38:46 +00:00
|
|
|
|
|
|
|
if (this.issue.state === 'closed') {
|
|
|
|
return 'octicon-git-pull-request-closed'; // Closed PR
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.issue.pull_request.draft === true) {
|
|
|
|
return 'octicon-git-pull-request-draft'; // WIP PR
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'octicon-git-pull-request'; // Open PR
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.issue.state === 'closed') {
|
|
|
|
return 'octicon-issue-closed'; // Closed issue
|
2021-07-13 18:09:19 +00:00
|
|
|
}
|
2024-07-16 14:38:46 +00:00
|
|
|
|
|
|
|
return 'octicon-issue-opened'; // Open issue
|
2021-07-13 18:09:19 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
color() {
|
2024-02-04 22:37:45 +00:00
|
|
|
if (this.issue.pull_request !== null) {
|
2024-07-16 14:38:46 +00:00
|
|
|
if (this.issue.pull_request.merged === true) {
|
2024-02-04 22:37:45 +00:00
|
|
|
return 'purple'; // Merged PR
|
|
|
|
}
|
2024-07-16 14:38:46 +00:00
|
|
|
|
|
|
|
if (this.issue.pull_request.draft === true && this.issue.state === 'open') {
|
|
|
|
return 'grey'; // WIP PR
|
|
|
|
}
|
2024-02-04 22:37:45 +00:00
|
|
|
}
|
2024-07-16 14:38:46 +00:00
|
|
|
|
|
|
|
if (this.issue.state === 'closed') {
|
|
|
|
return 'red'; // Closed issue
|
2021-07-13 18:09:19 +00:00
|
|
|
}
|
2024-07-16 14:38:46 +00:00
|
|
|
|
|
|
|
return 'green'; // Open issue
|
2021-07-13 18:09:19 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
labels() {
|
2024-04-07 16:19:25 +00:00
|
|
|
return this.issue.labels.map((label) => ({
|
|
|
|
name: htmlEscape(label.name).replaceAll(/:[-+\w]+:/g, (emoji) => {
|
2024-03-29 19:41:13 +00:00
|
|
|
return emojiHTML(emoji.substring(1, emoji.length - 1));
|
2024-04-07 16:19:25 +00:00
|
|
|
}),
|
|
|
|
color: `#${label.color}`,
|
|
|
|
textColor: contrastColor(`#${label.color}`),
|
|
|
|
}));
|
2024-03-22 14:06:53 +00:00
|
|
|
},
|
2021-07-13 18:09:19 +00:00
|
|
|
},
|
|
|
|
mounted() {
|
2023-03-05 14:23:42 +00:00
|
|
|
this.$refs.root.addEventListener('ce-load-context-popup', (e) => {
|
2022-10-01 14:26:38 +00:00
|
|
|
const data = e.detail;
|
2021-07-13 18:09:19 +00:00
|
|
|
if (!this.loading && this.issue === null) {
|
2022-10-01 14:26:38 +00:00
|
|
|
this.load(data);
|
2021-07-13 18:09:19 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
methods: {
|
2024-02-24 12:03:53 +00:00
|
|
|
async load(data) {
|
2021-07-13 18:09:19 +00:00
|
|
|
this.loading = true;
|
2021-12-28 13:28:27 +00:00
|
|
|
this.i18nErrorMessage = null;
|
2024-02-24 12:03:53 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
const response = await GET(`${appSubUrl}/${data.owner}/${data.repo}/issues/${data.index}/info`);
|
|
|
|
const respJson = await response.json();
|
|
|
|
if (!response.ok) {
|
|
|
|
this.i18nErrorMessage = respJson.message ?? i18n.network_error;
|
|
|
|
return;
|
2021-12-28 13:28:27 +00:00
|
|
|
}
|
2024-02-24 12:03:53 +00:00
|
|
|
this.issue = respJson;
|
|
|
|
} catch {
|
|
|
|
this.i18nErrorMessage = i18n.network_error;
|
|
|
|
} finally {
|
2021-07-13 18:09:19 +00:00
|
|
|
this.loading = false;
|
2024-02-24 12:03:53 +00:00
|
|
|
}
|
2024-03-22 14:06:53 +00:00
|
|
|
},
|
|
|
|
},
|
2021-07-13 18:09:19 +00:00
|
|
|
};
|
|
|
|
</script>
|
2023-09-02 14:59:07 +00:00
|
|
|
<template>
|
|
|
|
<div ref="root">
|
2024-03-27 20:18:04 +00:00
|
|
|
<div v-if="loading" class="tw-h-12 tw-w-12 is-loading"/>
|
2024-03-29 19:41:13 +00:00
|
|
|
<div v-if="!loading && issue !== null" id="issue-info-popup">
|
2023-09-02 14:59:07 +00:00
|
|
|
<p><small>{{ issue.repository.full_name }} on {{ createdAt }}</small></p>
|
|
|
|
<p><svg-icon :name="icon" :class="['text', color]"/> <strong>{{ issue.title }}</strong> #{{ issue.number }}</p>
|
|
|
|
<p>{{ body }}</p>
|
2024-04-07 16:19:25 +00:00
|
|
|
<div class="labels-list">
|
2024-03-29 19:41:13 +00:00
|
|
|
<!-- eslint-disable-next-line vue/no-v-html -->
|
|
|
|
<div v-for="label in labels" :key="label.name" class="ui label" :style="{ color: label.textColor, backgroundColor: label.color }" v-html="label.name"/>
|
2023-09-02 14:59:07 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-if="!loading && issue === null">
|
|
|
|
<p><small>{{ i18nErrorOccurred }}</small></p>
|
|
|
|
<p>{{ i18nErrorMessage }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|