发布支持自定义提交信息

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 BadgeManagementModal from './modals/BadgeManagementModal';
import SponsorModal from './modals/SponsorModal';
import CommitMessageModal from './modals/CommitMessageModal';
// Providers
import GooglePhotoModal from './modals/providers/GooglePhotoModal';
@ -105,6 +106,7 @@ export default {
AccountManagementModal,
BadgeManagementModal,
SponsorModal,
CommitMessageModal,
// Providers
GooglePhotoModal,
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">
<icon-provider provider-id="gitee"></icon-provider>
</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">
<input slot="field" class="textfield" type="text" v-model.trim="repoUrl" @keydown.enter="resolve()">
<div class="form-entry__info">

View File

@ -4,7 +4,7 @@
<div class="modal__image">
<icon-provider provider-id="github"></icon-provider>
</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">
<input slot="field" class="textfield" type="text" v-model.trim="repoUrl" @keydown.enter="resolve()">
<div class="form-entry__info">

View File

@ -4,7 +4,7 @@
<div class="modal__image">
<icon-provider provider-id="gitlab"></icon-provider>
</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">
<input slot="field" class="textfield" type="text" v-model.trim="projectUrl" @keydown.enter="resolve()">
<div class="form-entry__info">

View File

@ -4,7 +4,7 @@
<div class="modal__image">
<icon-provider provider-id="googleDrive"></icon-provider>
</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="可选的">
<input slot="field" class="textfield" type="text" v-model.trim="folderId" @keydown.enter="resolve()">
<div class="form-entry__info">

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -40,7 +40,10 @@ const ensureDate = (value, defaultValue) => {
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 template = store.getters['data/allTemplatesById'][publishLocation.templateId];
const html = await exportSvc.applyTemplate(fileId, template);
@ -59,7 +62,7 @@ const publish = async (publishLocation) => {
status: ensureString(properties.status),
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) => {
@ -69,11 +72,22 @@ const publishFile = async (fileId) => {
...store.getters['publishLocation/filteredGroupedByFileId'][fileId] || [],
];
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 store.dispatch('queue/doWithLocation', {
location: publishLocation,
action: async () => {
const publishLocationToStore = await publish(publishLocation);
const publishLocationToStore = await publish(publishLocation, commitMsg);
try {
// Replace publish location if modified
if (utils.serializeObject(publishLocation) !==
@ -131,7 +145,16 @@ const createPublishLocation = (publishLocation, featureId) => {
store.dispatch(
'queue/enqueue',
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);
store.dispatch('notification/info', `添加了一个新的发布位置 "${currentFile.name}".`);
if (featureId) {