Skip to content

Commit

Permalink
feat: 从issues导入更改
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanzhi33 committed Mar 25, 2024
1 parent 2cad42d commit 209ad71
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions src/components/EditItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ const { t } = useI18n({
wait: "等待处理 (WAIT)",
selectTag: "点击添加TAG",
updateSuccess: "更新成功",
importFromIssue: "从 Issue 导入"
importFromIssue: "从 Issue 导入",
importSuccess: "从 Issue (#{issue}) 成功导入站点 {id} 的新信息~",
importFailed: "未找到和站点 {id} 相关的“信息变更”Issue"
},
en: {
websiteName: "Website Name",
Expand All @@ -70,11 +72,45 @@ const { t } = useI18n({
wait: "Waiting for processing (WAIT)",
selectTag: "Click to add TAG",
updateSuccess: "Update successfully",
importFromIssue: "Import from Issue"
importFromIssue: "Import from Issue",
importSuccess: "Successfully imported new data for site {id} from Issue #{issue}~",
importFailed: "No 'Information Change' Issue related to site {id} found"
}
}
});
const issuesApi = async () => {
const timestamp = new Date().getTime();
const res = await fetch("https://api.github.com/repos/travellings-link/travellings/issues?labels=申请变更信息&_t=" + timestamp);
return await res.json();
}
const loadingIssues = ref(false);
const importFromIssue = async () => {
loadingIssues.value = true;
const issues = await issuesApi();
loadingIssues.value = false;
let found = false;
for (const issue of issues) {
const issueData = issue.body.split("\n");
const issueId = parseInt(issueData[6]);
if (issueId === id.value) {
name.value = issueData[14];
url.value = issueData[18];
found = true;
toast.success(t('importSuccess', {
issue: issue.number,
id: id.value
}));
break;
}
}
if (!found) {
toast.error(t('importFailed', { id: id.value }));
}
}
const loading = ref(false);
const tagList = computed(() => {
Expand Down Expand Up @@ -172,6 +208,10 @@ const submit = async () => {
<button type="button" class="btn btn-secondary" @click="isOpen = false">
{{ t('cancel') }}
</button>
<button type="button" class="btn btn-info" @click="importFromIssue" :disabled="loadingIssues">
<span class="spinner-border spinner-border-sm" v-if="loadingIssues"></span>
{{ t('importFromIssue') }}
</button>
</Modal>
</template>

Expand Down

0 comments on commit 209ad71

Please sign in to comment.