发布支持自定义提交信息

This commit is contained in:
xiaoqi.cxq 2022-09-10 19:48:28 +08:00
parent a6493a41da
commit 6fa7992685
15 changed files with 89 additions and 16 deletions

View File

@ -39,6 +39,7 @@ import WorkspaceManagementModal from './modals/WorkspaceManagementModal';
import AccountManagementModal from './modals/AccountManagementModal'; import AccountManagementModal from './modals/AccountManagementModal';
import BadgeManagementModal from './modals/BadgeManagementModal'; import BadgeManagementModal from './modals/BadgeManagementModal';
import SponsorModal from './modals/SponsorModal'; import SponsorModal from './modals/SponsorModal';
import CommitMessageModal from './modals/CommitMessageModal';
// Providers // Providers
import GooglePhotoModal from './modals/providers/GooglePhotoModal'; import GooglePhotoModal from './modals/providers/GooglePhotoModal';
@ -105,6 +106,7 @@ export default {
AccountManagementModal, AccountManagementModal,
BadgeManagementModal, BadgeManagementModal,
SponsorModal, SponsorModal,
CommitMessageModal,
// Providers // Providers
GooglePhotoModal, GooglePhotoModal,
GoogleDriveAccountModal, GoogleDriveAccountModal,

View File

@ -0,0 +1,40 @@
<template>
<modal-inner aria-label="提交信息">
<p>自定义<b> 提交信息</b></p>
<div class="modal__content">
<form-entry label="提交信息">
<input slot="field" class="textfield" placeholder="提交信息非必填" type="text" v-model.trim="commitMessage" @keydown.enter="resolve()">
</form-entry>
</div>
<div class="modal__button-bar">
<button class="button" @click="config.reject()">取消</button>
<button class="button button--resolve" @click="resolve()">确认</button>
</div>
</modal-inner>
</template>
<script>
import { mapGetters } from 'vuex';
import ModalInner from './common/ModalInner';
export default {
components: {
ModalInner,
},
data: () => ({
commitMessage: '',
}),
computed: {
...mapGetters('modal', [
'config',
]),
},
methods: {
resolve() {
this.config.resolve({
commitMessage: this.commitMessage,
});
},
},
};
</script>

View File

@ -4,7 +4,7 @@
<div class="modal__image"> <div class="modal__image">
<icon-provider provider-id="gitee"></icon-provider> <icon-provider provider-id="gitee"></icon-provider>
</div> </div>
<p>Publish <b>{{currentFileName}}</b> to your <b>Gitee</b> repository.</p> <p>发布 <b>{{currentFileName}}</b> 到您的 <b>Gitee</b> 仓库.</p>
<form-entry label="仓库URL" error="repoUrl"> <form-entry label="仓库URL" error="repoUrl">
<input slot="field" class="textfield" type="text" v-model.trim="repoUrl" @keydown.enter="resolve()"> <input slot="field" class="textfield" type="text" v-model.trim="repoUrl" @keydown.enter="resolve()">
<div class="form-entry__info"> <div class="form-entry__info">

View File

@ -4,7 +4,7 @@
<div class="modal__image"> <div class="modal__image">
<icon-provider provider-id="github"></icon-provider> <icon-provider provider-id="github"></icon-provider>
</div> </div>
<p>Publish <b>{{currentFileName}}</b> to your <b>GitHub</b> repository.</p> <p>发布 <b>{{currentFileName}}</b> 到您的 <b>GitHub</b> 仓库.</p>
<form-entry label="仓库URL" error="repoUrl"> <form-entry label="仓库URL" error="repoUrl">
<input slot="field" class="textfield" type="text" v-model.trim="repoUrl" @keydown.enter="resolve()"> <input slot="field" class="textfield" type="text" v-model.trim="repoUrl" @keydown.enter="resolve()">
<div class="form-entry__info"> <div class="form-entry__info">

View File

@ -4,7 +4,7 @@
<div class="modal__image"> <div class="modal__image">
<icon-provider provider-id="gitlab"></icon-provider> <icon-provider provider-id="gitlab"></icon-provider>
</div> </div>
<p>Publish <b>{{currentFileName}}</b> to your <b>GitLab</b> project.</p> <p>发布 <b>{{currentFileName}}</b> 到您的 <b>GitLab</b> 仓库.</p>
<form-entry label="Project URL" error="projectUrl"> <form-entry label="Project URL" error="projectUrl">
<input slot="field" class="textfield" type="text" v-model.trim="projectUrl" @keydown.enter="resolve()"> <input slot="field" class="textfield" type="text" v-model.trim="projectUrl" @keydown.enter="resolve()">
<div class="form-entry__info"> <div class="form-entry__info">

View File

@ -4,7 +4,7 @@
<div class="modal__image"> <div class="modal__image">
<icon-provider provider-id="googleDrive"></icon-provider> <icon-provider provider-id="googleDrive"></icon-provider>
</div> </div>
<p>Publish <b>{{currentFileName}}</b> to your <b>Google Drive</b> account.</p> <p>发布 <b>{{currentFileName}}</b> 到您的 <b>Google Drive</b> 账号.</p>
<form-entry label="Folder ID" info="可选的"> <form-entry label="Folder ID" info="可选的">
<input slot="field" class="textfield" type="text" v-model.trim="folderId" @keydown.enter="resolve()"> <input slot="field" class="textfield" type="text" v-model.trim="folderId" @keydown.enter="resolve()">
<div class="form-entry__info"> <div class="form-entry__info">

View File

@ -56,7 +56,7 @@ export default new Provider({
}); });
return updatedSyncLocation; return updatedSyncLocation;
}, },
async publish(token, html, metadata, publishLocation) { async publish(token, html, metadata, publishLocation, commitMessage) {
const updatedPublishLocation = { const updatedPublishLocation = {
...publishLocation, ...publishLocation,
projectId: await giteaHelper.getProjectId(publishLocation), projectId: await giteaHelper.getProjectId(publishLocation),
@ -74,6 +74,7 @@ export default new Provider({
token, token,
content: html, content: html,
sha, sha,
commitMessage,
}); });
return updatedPublishLocation; return updatedPublishLocation;
}, },

View File

@ -51,7 +51,7 @@ export default new Provider({
}); });
return syncLocation; return syncLocation;
}, },
async publish(token, html, metadata, publishLocation) { async publish(token, html, metadata, publishLocation, commitMessage) {
try { try {
// Get the last sha // Get the last sha
await this.downloadContent(token, publishLocation); await this.downloadContent(token, publishLocation);
@ -65,6 +65,7 @@ export default new Provider({
token, token,
content: html, content: html,
sha, sha,
commitMessage,
}); });
return publishLocation; return publishLocation;
}, },

View File

@ -51,7 +51,7 @@ export default new Provider({
}); });
return syncLocation; return syncLocation;
}, },
async publish(token, html, metadata, publishLocation) { async publish(token, html, metadata, publishLocation, commitMessage) {
try { try {
// Get the last sha // Get the last sha
await this.downloadContent(token, publishLocation); await this.downloadContent(token, publishLocation);
@ -65,6 +65,7 @@ export default new Provider({
token, token,
content: html, content: html,
sha, sha,
commitMessage,
}); });
return publishLocation; return publishLocation;
}, },

View File

@ -56,7 +56,7 @@ export default new Provider({
}); });
return updatedSyncLocation; return updatedSyncLocation;
}, },
async publish(token, html, metadata, publishLocation) { async publish(token, html, metadata, publishLocation, commitMessage) {
const updatedPublishLocation = { const updatedPublishLocation = {
...publishLocation, ...publishLocation,
projectId: await gitlabHelper.getProjectId(token, publishLocation), projectId: await gitlabHelper.getProjectId(token, publishLocation),
@ -74,6 +74,7 @@ export default new Provider({
token, token,
content: html, content: html,
sha, sha,
commitMessage,
}); });
return updatedPublishLocation; return updatedPublishLocation;
}, },

View File

@ -280,13 +280,14 @@ export default {
content, content,
sha, sha,
isFile, isFile,
commitMessage,
}) { }) {
const refreshedToken = await this.refreshToken(token); const refreshedToken = await this.refreshToken(token);
return request(refreshedToken, { return request(refreshedToken, {
method: sha ? 'PUT' : 'POST', method: sha ? 'PUT' : 'POST',
url: `repos/${projectId}/contents/${encodeURIComponent(path)}`, url: `repos/${projectId}/contents/${encodeURIComponent(path)}`,
body: { body: {
message: getCommitMessage(sha ? 'updateFileMessage' : 'createFileMessage', path), message: commitMessage || getCommitMessage(sha ? 'updateFileMessage' : 'createFileMessage', path),
content: isFile ? await utils.encodeFiletoBase64(content) : utils.encodeBase64(content), content: isFile ? await utils.encodeFiletoBase64(content) : utils.encodeBase64(content),
sha, sha,
branch, branch,

View File

@ -276,13 +276,14 @@ export default {
path, path,
content, content,
sha, sha,
commitMessage,
}) { }) {
const refreshedToken = await this.refreshToken(token); const refreshedToken = await this.refreshToken(token);
return repoRequest(refreshedToken, owner, repo, { return repoRequest(refreshedToken, owner, repo, {
method: sha ? 'PUT' : 'POST', method: sha ? 'PUT' : 'POST',
url: `contents/${encodeURIComponent(path)}`, url: `contents/${encodeURIComponent(path)}`,
body: { body: {
message: getCommitMessage(sha ? 'updateFileMessage' : 'createFileMessage', path), message: commitMessage || getCommitMessage(sha ? 'updateFileMessage' : 'createFileMessage', path),
content: utils.encodeBase64(content || ' '), content: utils.encodeBase64(content || ' '),
sha, sha,
branch, branch,

View File

@ -176,12 +176,13 @@ export default {
content, content,
sha, sha,
isFile, isFile,
commitMessage,
}) { }) {
return repoRequest(token, owner, repo, { return repoRequest(token, owner, repo, {
method: 'PUT', method: 'PUT',
url: `contents/${encodeURIComponent(path)}`, url: `contents/${encodeURIComponent(path)}`,
body: { body: {
message: getCommitMessage(sha ? 'updateFileMessage' : 'createFileMessage', path), message: commitMessage || getCommitMessage(sha ? 'updateFileMessage' : 'createFileMessage', path),
content: isFile ? await utils.encodeFiletoBase64(content) : utils.encodeBase64(content), content: isFile ? await utils.encodeFiletoBase64(content) : utils.encodeBase64(content),
sha, sha,
branch, branch,

View File

@ -157,12 +157,13 @@ export default {
path, path,
content, content,
sha, sha,
commitMessage,
}) { }) {
return request(token, { return request(token, {
method: sha ? 'PUT' : 'POST', method: sha ? 'PUT' : 'POST',
url: `projects/${encodeURIComponent(projectId)}/repository/files/${encodeURIComponent(path)}`, url: `projects/${encodeURIComponent(projectId)}/repository/files/${encodeURIComponent(path)}`,
body: { body: {
commit_message: getCommitMessage(sha ? 'updateFileMessage' : 'createFileMessage', path), commit_message: commitMessage || getCommitMessage(sha ? 'updateFileMessage' : 'createFileMessage', path),
content, content,
last_commit_id: sha, last_commit_id: sha,
branch, branch,

View File

@ -40,7 +40,10 @@ const ensureDate = (value, defaultValue) => {
return new Date(`${value}`); return new Date(`${value}`);
}; };
const publish = async (publishLocation) => { // git 相关的 providerId
const gitProviderIds = ['gitea', 'gitee', 'github', 'gitlab'];
const publish = async (publishLocation, commitMessage) => {
const { fileId } = publishLocation; const { fileId } = publishLocation;
const template = store.getters['data/allTemplatesById'][publishLocation.templateId]; const template = store.getters['data/allTemplatesById'][publishLocation.templateId];
const html = await exportSvc.applyTemplate(fileId, template); const html = await exportSvc.applyTemplate(fileId, template);
@ -59,7 +62,7 @@ const publish = async (publishLocation) => {
status: ensureString(properties.status), status: ensureString(properties.status),
date: ensureDate(properties.date, new Date()), date: ensureDate(properties.date, new Date()),
}; };
return provider.publish(token, html, metadata, publishLocation); return provider.publish(token, html, metadata, publishLocation, commitMessage);
}; };
const publishFile = async (fileId) => { const publishFile = async (fileId) => {
@ -69,11 +72,22 @@ const publishFile = async (fileId) => {
...store.getters['publishLocation/filteredGroupedByFileId'][fileId] || [], ...store.getters['publishLocation/filteredGroupedByFileId'][fileId] || [],
]; ];
try { try {
// 查询是否包含git provider 包含则需要填入提交信息
const gitLocations = publishLocations.filter(it => gitProviderIds.indexOf(it.providerId) > -1);
let commitMsg = '';
if (gitLocations.length) {
try {
const { commitMessage } = await store.dispatch('modal/open', { type: 'commitMessage' });
commitMsg = commitMessage;
} catch (e) {
return;
}
}
await utils.awaitSequence(publishLocations, async (publishLocation) => { await utils.awaitSequence(publishLocations, async (publishLocation) => {
await store.dispatch('queue/doWithLocation', { await store.dispatch('queue/doWithLocation', {
location: publishLocation, location: publishLocation,
action: async () => { action: async () => {
const publishLocationToStore = await publish(publishLocation); const publishLocationToStore = await publish(publishLocation, commitMsg);
try { try {
// Replace publish location if modified // Replace publish location if modified
if (utils.serializeObject(publishLocation) !== if (utils.serializeObject(publishLocation) !==
@ -131,7 +145,16 @@ const createPublishLocation = (publishLocation, featureId) => {
store.dispatch( store.dispatch(
'queue/enqueue', 'queue/enqueue',
async () => { async () => {
const publishLocationToStore = await publish(publishLocation); let commitMsg = '';
if (gitProviderIds.indexOf(publishLocation.providerId) > -1) {
try {
const { commitMessage } = await store.dispatch('modal/open', { type: 'commitMessage' });
commitMsg = commitMessage;
} catch (e) {
return;
}
}
const publishLocationToStore = await publish(publishLocation, commitMsg);
workspaceSvc.addPublishLocation(publishLocationToStore); workspaceSvc.addPublishLocation(publishLocationToStore);
store.dispatch('notification/info', `添加了一个新的发布位置 "${currentFile.name}".`); store.dispatch('notification/info', `添加了一个新的发布位置 "${currentFile.name}".`);
if (featureId) { if (featureId) {