Skip to content

Added PreBuild Button configurable from Preference #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { EventEmitter } from "events";
export interface Config {
gitpodURL: string;
openAsPopup: boolean;
isEnabledPrebuildButton: boolean;
}

export const DEFAULT_CONFIG: Config = {
gitpodURL: "https://gitpod.io",
openAsPopup: false
openAsPopup: false,
isEnabledPrebuildButton: false,
};

export interface ConfigListener {
Expand Down
20 changes: 16 additions & 4 deletions src/injectors/gitlab-injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class RepositoryInjector implements ButtonInjector {
return result;
}

inject(currentUrl: string, openAsPopup: boolean) {
inject(currentUrl: string, openAsPopup: boolean, isEnabledPrebuildButton: boolean) {
const parent = select(RepositoryInjector.PARENT_SELECTOR);
if (!parent || !parent.firstElementChild) {
return;
Expand All @@ -68,7 +68,7 @@ class RepositoryInjector implements ButtonInjector {
return;
}

const btn = this.renderButton(currentUrl, openAsPopup);
const btn = this.renderButton(currentUrl, openAsPopup, isEnabledPrebuildButton);
parent.firstElementChild.appendChild(btn);

const primaryButtons = parent.firstElementChild.getElementsByClassName("btn-primary");
Expand All @@ -82,7 +82,7 @@ class RepositoryInjector implements ButtonInjector {
}
}

protected renderButton(url: string, openAsPopup: boolean): HTMLElement {
protected renderButton(url: string, openAsPopup: boolean, isEnabledPrebuildButton: boolean): HTMLElement {
const container = document.createElement('div');
container.className = "project-clone-holder d-none d-md-inline-block";

Expand All @@ -96,12 +96,24 @@ class RepositoryInjector implements ButtonInjector {
a.href = url;
a.target = "_blank";
a.className = "gl-button btn btn-info";

if (openAsPopup) {
makeOpenInPopup(a);
}

container2ndLevel.appendChild(a);

if(isEnabledPrebuildButton){
const pb = document.createElement('a');
pb.id = Gitpodify.BTN_ID;
pb.title = "PreBuild";
pb.text = "PreBuild"
pb.href = url.replace("#","#prebuild/");
pb.target = "_blank";
pb.className = "gl-button btn btn-info";
container2ndLevel.appendChild(pb)
}

container.appendChild(container2ndLevel);
return container;
}
Expand Down
4 changes: 2 additions & 2 deletions src/injectors/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface ButtonInjector {
* Injects the actual button
* @param currentUrl The currently configured Gitpod URL
*/
inject(currentUrl: string, openAsPopup: boolean): void;
inject(currentUrl: string, openAsPopup: boolean, isEnabledPrebuildButton:boolean): void;
}

export abstract class InjectorBase implements Injector {
Expand All @@ -54,7 +54,7 @@ export abstract class InjectorBase implements Injector {
const currentUrl = renderGitpodUrl(this.config.gitpodURL);
for (const injector of this.buttonInjectors) {
if (injector.isApplicableToCurrentPage()) {
injector.inject(currentUrl, this.config.openAsPopup);
injector.inject(currentUrl, this.config.openAsPopup, this.config.isEnabledPrebuildButton);
if (singleInjector) {
break;
}
Expand Down
4 changes: 4 additions & 0 deletions src/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<label>Gitpod installation URL:</label>
<input id="gitpod-url-input" type="url" value=""/>
</div>
<div class="row">
<label>Show PreBuild Option:</label>
<input id="gitpod-is-enabled-prebuild-button" type="checkbox" value=""/>
</div>
<div class="row">
<label>Open as popup:</label>
<input id="gitpod-open-as-popup" type="checkbox"/>
Expand Down
6 changes: 5 additions & 1 deletion src/options/options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ConfigProvider } from "../config";

const gitpodUrlInput = document.getElementById("gitpod-url-input")! as HTMLInputElement;
const gitpodPrebuildButtonEnabled = document.getElementById("gitpod-is-enabled-prebuild-button") as HTMLInputElement;
const gitpodPopupInput = document.getElementById("gitpod-open-as-popup")! as HTMLInputElement;
const messageElement = document.getElementById("message")! as HTMLDivElement;

Expand All @@ -12,6 +13,7 @@ const init = async () => {
const initialConfig = configProvider.getConfig();
gitpodUrlInput.value = initialConfig.gitpodURL;
gitpodPopupInput.checked = initialConfig.openAsPopup;
gitpodPrebuildButtonEnabled.checked = initialConfig.isEnabledPrebuildButton;

let timeout: number | undefined = undefined;

Expand All @@ -20,7 +22,8 @@ const init = async () => {
// Update config (propagated internally)
configProvider.setConfig({
gitpodURL: gitpodUrlInput.value || undefined,
openAsPopup: gitpodPopupInput.checked
openAsPopup: gitpodPopupInput.checked,
isEnabledPrebuildButton: gitpodPrebuildButtonEnabled.checked
});
if (timeout) {
window.clearTimeout(timeout);
Expand All @@ -36,6 +39,7 @@ const init = async () => {
save()
});
gitpodPopupInput.addEventListener('change', save);
gitpodPrebuildButtonEnabled.addEventListener('change', save);
};

init().catch(err => console.error(err));