Skip to content

Commit

Permalink
feat: add support for GitHub Enterprise Server (GHES) (#68)
Browse files Browse the repository at this point in the history
Make it possible to define a custom GitHub server URL, thus supporting
GHES installations as a source for bookmarks.
  • Loading branch information
frederikb authored Apr 8, 2024
1 parent 912cc24 commit e475d6d
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 7 deletions.
Binary file modified docs/screenshot-options.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Store bookmarks in a simple JSON structure in your organization's GitHub reposit
- 📁 **Multi-File Support**: Organize your organizations bookmarks into separate JSON files, for example by project.
- 📢 **Notifications**: Stay informed about successful syncs or if any issues arise.
- 🔒 **Secure**: Uses GitHub's Personal Access Token (PAT) for authentication, ensuring secure access.
- 🌐 **GitHub Enterprise Support**: Synchronize bookmarks from GitHub or GitHub Enterprise Server (GHES).

## 🛠 Installation

Expand All @@ -46,9 +47,13 @@ Access the extension's options and provide:
3. **Repository**: The name of the repository without the `.git` extension. The name is not case sensitive.
4. **Source Path**: The path within the repository to either a single JSON file or a directory containing multiple JSON bookmark files. For a single file, provide the path e.g., `path/to/bookmarks.json`. For a directory, just specify the folder path e.g., `bookmarks`.

You can also synchronize bookmarks from a GitHub Enterprise Server (GHES) by specifying the **GitHub API URL** (which ends with `/api/v3`).


Then make your bookmarks available at the source path in your repository to watch the magic happen.

Use the `Check Connection` to test the configuration.

## 📄 Bookmark Collection JSON Format

Structure your JSON file for bookmarks as per the schema defined at [https://frederikb.github.io/bookmarksync/schemas/bookmarks.1-0-0.schema.json](https://frederikb.github.io/bookmarksync/schemas/bookmarks.1-0-0.schema.json).
Expand Down
14 changes: 13 additions & 1 deletion src/entrypoints/options/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@

<body>
<form id="options-form" class="detail-view-container">
<p>
<p>
<label>
<input type="checkbox" name="useCustomHost">
Use GitHub Enterprise Server
</label>
</p>
<p id="customHostContainer">
<label class="text-input">
<span>GitHub API URL</span>
<input type="url" name="githubApiUrl" required placeholder="https://github.yourdomain.com/api/v3">
</label>
</p>
<p>
<label class="text-input">
<span>GitHub Personal Access Token</span>
<input type="password" name="pat" required>
Expand Down
19 changes: 16 additions & 3 deletions src/entrypoints/options/options.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
html {
min-width: 550px;
min-height: 14rem;
min-height: 16rem;
overflow-x: hidden;
/* Required to hide horizontal scroll on Firefox */
}

#options-form input[type="text"],
#options-form input[type="password"] {
#options-form input[type="password"],
#options-form input[type="url"] {
margin: 0;
padding: 5px;
border: 1px solid #ccc;
Expand Down Expand Up @@ -52,6 +53,18 @@ hr {
margin-bottom: 15px;
}

#customHostContainer {
visibility: visible;
transition: max-height 0.5s ease-in-out;
max-height: 10rem;
overflow: hidden;
}

#customHostContainer.hidden {
visibility: hidden;
max-height: 0;
transition: max-height 0.5s ease-in-out, visibility 0s 0.5s;
}
#check-connection-btn {
width: 11rem;
cursor: pointer;
Expand Down Expand Up @@ -88,4 +101,4 @@ hr {
color: #330000;
background-color: #ffcccc;
border: 1px solid #440000;
}
}
22 changes: 21 additions & 1 deletion src/entrypoints/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ async function init() {
}
};

const showCustomHostInput = checked => {
document.querySelector('#customHostContainer').className = checked ? '' : 'hidden';
document.querySelector('#customHostContainer input').required = checked;
};

const clearCustomHostInput = () => {
document.querySelector('[name="githubApiUrl"]').value = '';
};

const setupCustomHostInput = async () => {
const {useCustomHost} = await optionsStorage.getAll();
showCustomHostInput(useCustomHost);
if (!useCustomHost) {
await optionsStorage.set({githubApiUrl: ''});
clearCustomHostInput();
}
};

checkConnectionButton.addEventListener('click', async () => {
if (!form.checkValidity() || isChecking) {
return;
Expand Down Expand Up @@ -90,11 +108,13 @@ async function init() {
}
});

form.addEventListener('options-sync:form-synced', () => {
form.addEventListener('options-sync:form-synced', async () => {
cancelCurrentCheck = true;
await setupCustomHostInput();
resetCheckConnection();
});

await setupCustomHostInput();
resetCheckConnection();
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/github-bookmarks-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {

class GitHubBookmarksLoader {
async load({force = false, cacheEtag = true} = {}) {
const {repo, owner, pat, sourcePath, etag} = await optionsStorage.getAll();
const {repo, owner, pat, sourcePath, etag, githubApiUrl} = await optionsStorage.getAll();

if (!repo || !owner || !sourcePath || !pat) {
throw new BookmarkSourceNotConfiguredError();
}

const MyOctokit = Octokit.plugin(retry);
const octokit = new MyOctokit({auth: pat});
const octokit = new MyOctokit({auth: pat, baseUrl: githubApiUrl || null});

console.info(`Starting sync with GitHub using ${owner}/${repo}/${sourcePath}`);

Expand Down
2 changes: 2 additions & 0 deletions src/utils/options-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import OptionsSync from 'webext-options-sync';

const optionsStorage = new OptionsSync({
defaults: {
useCustomHost: false,
githubApiUrl: '',
pat: '',
owner: '',
repo: '',
Expand Down

0 comments on commit e475d6d

Please sign in to comment.