Skip to content

Commit

Permalink
bugfix: retry will alaways push empty commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ylc395 committed Oct 18, 2021
2 parents b76715c + 66c04b6 commit cc1cc91
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/domain/service/PublishService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class PublishService {
this.git.terminate();
}

async publish(isRetry = false, needToCreateRepo = false) {
async publish(needToCreateRepo = false) {
if (this.isPublishing.value) {
return;
}
Expand All @@ -199,7 +199,9 @@ export class PublishService {
}

const needToInit =
isRetry || needToCreateRepo || this.localRepoStatus.value === LocalRepoStatus.Fail;
this.publishingProgress.result === PublishResults.Fail ||
needToCreateRepo ||
this.localRepoStatus.value === LocalRepoStatus.Fail;

if (needToInit) {
this.refreshPublishingProgress();
Expand Down
2 changes: 1 addition & 1 deletion src/driver/git/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface GitEventHandler {
}

export interface WorkerGit {
initRepo: (payload: { gitInfo: GitInfo; githubInfo: Github }) => Promise<void>;
initRepo: (payload: { gitInfo: GitInfo; githubInfo: Github; keepDir: boolean }) => Promise<void>;

publish: (payload: { gitInfo: GitInfo; githubInfo: Github; files: string[] }) => Promise<void>;
}
11 changes: 10 additions & 1 deletion src/driver/git/webWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ import type { WorkerGit, GitEventHandler } from './type';
const { onMessage, onProgress } = wrap<GitEventHandler>(self);

const workerGit: WorkerGit = {
async initRepo({ gitInfo, githubInfo }) {
async initRepo({ gitInfo, githubInfo, keepDir }) {
const { userName, token, branch: branchName, email } = githubInfo;
const { dir, gitdir, url, remote } = gitInfo;
const _branchName = branchName || DEFAULT_GITHUB_BRANCH;

if (keepDir) {
await fs.promises.move(dir, `${dir}_backup`);
}

await fs.promises.emptyDir(gitdir);
await fs.promises.emptyDir(dir);

Expand All @@ -45,6 +49,10 @@ const workerGit: WorkerGit = {
onProgress,
});

if (keepDir) {
await fs.promises.move(`${dir}_backup`, dir);
}

const branches = await listBranches({ fs, dir, gitdir });

if (!branches.includes(_branchName)) {
Expand All @@ -54,6 +62,7 @@ const workerGit: WorkerGit = {
await setConfig({ fs, gitdir, path: 'user.name', value: userName });
await setConfig({ fs, gitdir, path: 'user.email', value: email });
},

async publish({ gitInfo: { dir, gitdir, remote, url }, githubInfo, files }) {
await add({ fs, gitdir, dir, filepath: '.' });

Expand Down
5 changes: 3 additions & 2 deletions src/driver/git/webviewApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Git extends EventEmitter<GitEvents> {
return this.initRepo();
}

private initRepo() {
private initRepo(byPublishing = false) {
// always init worker when init repo
this.initWorker();

Expand Down Expand Up @@ -96,6 +96,7 @@ class Git extends EventEmitter<GitEvents> {
url: github.getRepositoryUrl(),
remote: Git.remote,
},
keepDir: byPublishing,
})
.then(resolve_, reject_);
});
Expand Down Expand Up @@ -144,7 +145,7 @@ class Git extends EventEmitter<GitEvents> {
this.isPushing = true;

if (needToInit) {
this.initRepo();
this.initRepo(true);
}

try {
Expand Down
11 changes: 10 additions & 1 deletion src/driver/github/webviewApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,22 @@ export class Github extends EventEmitter<GithubClientEvents> implements GithubCl
}

async createRepository() {
if (!this.githubInfo?.userName) {
throw new Error('no userName');
}

try {
await this.request('POST', '/user/repos', {
name: this.getRepositoryName(),
description: 'Blog Website By Joplin Pages Publisher',
});
} catch (error) {
throw new PublishError(PublishResults.Fail, error);
try {
// maybe user create it manually
await this.request('GET', `/repos/${this.githubInfo.userName}/${this.getRepositoryName()}`);
} catch {
throw new PublishError(PublishResults.Fail, error);
}
}
}

Expand Down
7 changes: 2 additions & 5 deletions src/driver/webview/app/Publisher/PublishingModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ export default defineComponent({
</template>
<template #extra>
<Button @click="reset">Confirm</Button>
<Button
v-if="progress.result === PublishResults.Fail"
type="primary"
@click="publish(true)"
<Button v-if="progress.result === PublishResults.Fail" type="primary" @click="publish()"
>Retry</Button
>
</template>
Expand All @@ -104,7 +101,7 @@ export default defineComponent({
on Github?
<div class="text-right mt-4">
<Button class="mr-2" @click="reset">Cancel</Button>
<Button type="primary" @click="publish(true, true)">Confirm</Button>
<Button type="primary" @click="publish(true)">Confirm</Button>
</div>
</Modal>
</template>

0 comments on commit cc1cc91

Please sign in to comment.