Skip to content

Commit 069013a

Browse files
[project setup wizard] Create readme file if missing and fix some bugs
Fixes #3012
1 parent 6b10ec9 commit 069013a

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

components/theia/packages/gitpod-extension/src/browser/setup/setup-manager.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export interface SetupManager {
3737
testSetup(): Promise<void>;
3838
}
3939

40+
export const gitpodSetupBranchName = "gitpod-setup"
41+
4042
@injectable()
4143
export class SetupManagerImpl implements SetupManager, FS, CommandContribution {
4244

@@ -159,7 +161,7 @@ export class SetupManagerImpl implements SetupManager, FS, CommandContribution {
159161
return;
160162
}
161163
const myLogin = await this.gitHubModel.getMyLogin();
162-
const testbranch = myLogin + '/gitpod-setup';
164+
const testbranch = myLogin + '/' + gitpodSetupBranchName;
163165
const total = 6;
164166
let done = 1;
165167
const repo = this.repoProvider.selectedRepository;
@@ -185,8 +187,8 @@ export class SetupManagerImpl implements SetupManager, FS, CommandContribution {
185187
if (await this.exists(this.dockerFileName)) {
186188
filesToAdd.push(dockerUri.toString());
187189
}
188-
const readme = await this.getReadMe();
189-
if (await this.exists(readme)) {
190+
const readme = await this.getReadMe().catch(() => "");
191+
if (readme != "" && await this.exists(readme)) {
190192
filesToAdd.push((await this.toURI(readme)).toString());
191193
}
192194
try {
@@ -482,7 +484,7 @@ issue or pull request almost instantly with a single click.
482484
total: 50
483485
}
484486
});
485-
this.write(this.dockerFileName,
487+
await this.write(this.dockerFileName,
486488
`FROM ${baseImage}
487489
488490
# Install custom tools, runtimes, etc.
@@ -525,7 +527,10 @@ issue or pull request almost instantly with a single click.
525527
}
526528

527529
async hasReadmeConfig(): Promise<boolean> {
528-
const file = await this.getReadMe();
530+
const file = await this.getReadMe().catch(() => "");
531+
if (file == "") {
532+
return false;
533+
}
529534
const contents = await this.read(file);
530535
const info = await this.infoService.getInfo();
531536
if (!contents) {
@@ -536,17 +541,17 @@ issue or pull request almost instantly with a single click.
536541
}
537542

538543
async updateReadme(): Promise<EditorWidget> {
539-
const fileName = await this.getReadMe();
544+
const fileName = await this.getReadMe().catch(() => "README.md");
540545
const repo = this.repoProvider.selectedRepository;
541546
if (!repo) {
542547
throw new Error('no repository selected');
543548
}
544549
const remotes = await this.git.remote(repo);
545550
const remote = remotes.indexOf('upstream') === -1 ? 'origin' : 'upstream';
546-
const content = await this.read(fileName);
551+
const content = await this.read(fileName) || "";
547552
const contextUrl = await this.getContextUrl(remote);
548553

549-
this.write(fileName,
554+
await this.write(fileName,
550555
`[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](${contextUrl})
551556
552557
${content}`);

components/theia/packages/gitpod-extension/src/browser/setup/setup-view.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { ReactWidget, Message, ApplicationShell } from "@theia/core/lib/browser";
88
import * as React from 'react';
99
import { injectable, inject, postConstruct } from "inversify";
10-
import { SetupManager } from "./setup-manager";
10+
import { SetupManager, gitpodSetupBranchName } from "./setup-manager";
1111
import { CommandRegistry } from "@theia/core";
1212
import { GitHubCommand } from "../github";
1313
import { GitHubExtension } from "../github/github-extension";
@@ -156,7 +156,7 @@ export class SetupView extends ReactWidget {
156156
title: 'Test Drive Configuration',
157157
description: <React.Fragment>
158158
<p>
159-
Push your changes on a remote branch and start a fresh workspace.
159+
Push your changes to the remote branch{gitpodSetupBranchName} and start a fresh workspace.
160160
</p>
161161
</React.Fragment>
162162
,

0 commit comments

Comments
 (0)