How Lepton Configures and Interacts with GitHub Enterprise Instances
Lepton enables GitHub Enterprise support through a centralized configuration system that rewrites API endpoints, injects personal access tokens, and customizes UI elements based on four key settings in the enterprise configuration block.
Lepton, an open-source snippet manager built by hackjutsu/Lepton, allows developers to sync gists with self-hosted GitHub Enterprise instances rather than just public GitHub. Understanding how Lepton configures and interacts with GitHub Enterprise instances requires examining the configuration schema, runtime resolution, and API layer modifications that redirect traffic from api.github.com to your internal Enterprise server.
Configuration Schema and Default Values
Lepton defines its GitHub Enterprise settings in configs/defaultConfig.js through a dedicated enterprise object. This block provides the default state for all Enterprise-specific features, which users override via a .leptonrc file in their home directory.
The Enterprise Configuration Block
The default configuration declares four properties that control Enterprise behavior:
- enable – Boolean toggle that activates GitHub Enterprise mode
- host – Base hostname of your Enterprise instance (e.g.,
ghe.mycompany.com) - token – Personal access token for authentication, bypassing OAuth
- avatarUrl – Optional URL for a custom avatar image
// configs/defaultConfig.js – lines 28-33
"enterprise": {
"enable": false,
"host": "",
"token": "",
"avatarUrl": ""
},
Runtime Configuration Resolution
At runtime, Lepton uses the nconf library to merge default settings with user overrides into a global conf object. Both the Electron main process and renderer components access Enterprise settings through the conf.get('enterprise:<key>') API.
This approach ensures that any component can check Enterprise status or retrieve credentials without importing configuration logic directly. The conf object acts as the single source of truth for all GitHub Enterprise parameters.
API Host Rewriting for Enterprise Endpoints
When Enterprise mode is enabled, Lepton redirects all REST API calls from the public GitHub endpoint to your internal Enterprise API. This transformation occurs in app/utilities/githubApi/index.js.
// app/utilities/githubApi/index.js – lines 22-25
if (conf.get('enterprise:enable')) {
const gitHubHost = conf.get('enterprise:host')
gitHubHostApi = `${gitHubHost}/api/v3`
}
By default, gitHubHostApi points to api.github.com. When the enterprise:enable flag is true, the code constructs an Enterprise-specific URL using the format <host>/api/v3. All subsequent API operations—including getUserProfile, getSingleGist, and getAllGistsV2—build their request URLs from this gitHubHostApi variable, ensuring seamless targeting of your Enterprise server without modifying individual endpoint logic.
Authentication Flow Changes
Lepton bypasses the standard OAuth flow when connecting to GitHub Enterprise instances. Instead of launching a browser-based authorization sequence, the application uses the personal access token supplied in the configuration.
In app/containers/loginPage/index.js, the authentication logic checks the Enterprise flag and retrieves the token directly:
// app/containers/loginPage/index.js – lines 91-92
if (conf.get('enterprise:enable')) {
const token = conf.get('enterprise:token')
}
This token is then passed to all API request helpers, granting immediate access to gists and user data without requiring interactive login flows.
UI Customizations for Enterprise Instances
Beyond API routing, Lepton adjusts its interface to reflect Enterprise-specific branding and host information. These UI modifications ensure users recognize when they are connected to internal infrastructure rather than public GitHub.
Custom Avatar Support
When Enterprise mode is active, Lepton checks for a custom avatar URL in app/containers/userPanel/index.js. If enterprise:avatarUrl is set, the application uses this image instead of the default GitHub avatar.
// app/containers/userPanel/index.js – lines 41-44
if (conf.get('enterprise:enable')) {
if (conf.get('enterprise:avatarUrl')) {
defaultImage = conf.get('enterprise:avatarUrl')
}
}
Host URL Display
Navigation elements that reference GitHub dynamically update to show your Enterprise domain. In app/containers/navigationPanel/index.js, the code replaces the public GitHub hostname with your configured Enterprise host:
// app/containers/navigationPanel/index.js – lines 146-147
if (conf.get('enterprise:enable')) {
gitHubHost = conf.get('enterprise:host')
}
This ensures that buttons and links correctly reference your internal instance rather than github.com.
Practical Configuration Examples
To enable GitHub Enterprise support, create or edit the .leptonrc file in your home directory. The following JSON structure activates Enterprise mode and configures connection parameters:
{
"enterprise": {
"enable": true,
"host": "ghe.mycompany.com",
"token": "ghp_XXXXXXXXXXXXXXXXXXXX",
"avatarUrl": "https://example.com/my-avatar.png"
}
}
You can programmatically verify Enterprise configuration within any component:
const isGHE = conf.get('enterprise:enable')
const apiBase = isGHE
? `${conf.get('enterprise:host')}/api/v3`
: 'api.github.com'
console.log('Lepton will call', apiBase)
For manual API testing using Lepton's internal utilities:
// Assuming `token` contains a valid PAT for GHE
import { getUserProfile } from '../../utilities/githubApi'
getUserProfile(token).then(profile => {
console.log('Authenticated user:', profile.login)
})
Summary
- Lepton stores GitHub Enterprise settings in the
enterpriseblock ofconfigs/defaultConfig.js, which users override via.leptonrc - The application uses
conf.get('enterprise:enable')to check mode status andconf.get('enterprise:host')to construct API URLs - API calls redirect from
api.github.comto<host>/api/v3through logic inapp/utilities/githubApi/index.js - Authentication uses the static
enterprise:tokenvalue rather than OAuth, as implemented inapp/containers/loginPage/index.js - UI components in
app/containers/userPanel/index.jsandapp/containers/navigationPanel/index.jsadapt avatars and host displays for Enterprise instances
Frequently Asked Questions
What configuration file does Lepton use for GitHub Enterprise settings?
Lepton reads Enterprise configuration from the .leptonrc file in the user's home directory, which overrides the default values defined in configs/defaultConfig.js. This JSON file accepts an enterprise object with enable, host, token, and avatarUrl properties.
Does Lepton support OAuth authentication for GitHub Enterprise?
No. According to the source code in app/containers/loginPage/index.js, Lepton uses a static personal access token (enterprise:token) when Enterprise mode is enabled, bypassing the OAuth flow entirely. You must generate a personal access token from your GitHub Enterprise instance and supply it in the configuration.
Which API version does Lepton use when connecting to GitHub Enterprise?
Lepton targets the GitHub Enterprise REST API v3 endpoint. The code in app/utilities/githubApi/index.js constructs the base URL as ${gitHubHost}/api/v3 when Enterprise mode is active, routing all gist and user profile requests to this endpoint instead of the public api.github.com.
Can I use a custom avatar image when connecting to GitHub Enterprise?
Yes. If you specify an avatarUrl in the Enterprise configuration block, Lepton displays this image in the user panel instead of the default GitHub avatar. The logic in app/containers/userPanel/index.js checks for enterprise:avatarUrl and falls back to that URL when Enterprise mode is enabled.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →