Skip to content

Commit

Permalink
feat: adding github entreprise API
Browse files Browse the repository at this point in the history
see #98
  • Loading branch information
Mara-Li committed Feb 2, 2023
1 parent 42d73b7 commit 0868c7b
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 16 deletions.
10 changes: 10 additions & 0 deletions plugin/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ export default {
exportSettings: "Export settings",
importSettings: "Import settings",
github: {
apiType: {
title: "API Type",
desc: "Choose between the Github API or the Github Enterprise API (for Github Enterprise users).",
hostname: "Github Enterprise Hostname",
hostnameDesc: "The hostname of your Github Enterprise instance.",
dropdown: {
free: "Free/Pro/Team (default)",
enterprise: "Enterprise",
}
},
githubConfiguration: "Github Configuration",
repoName: "Repo Name",
repoNameDesc:
Expand Down
12 changes: 11 additions & 1 deletion plugin/i18n/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ export default {
exportSettings: "Exporter les paramètres",
importSettings: "Importer des paramètres",
github: {
apiType: {
title: "Type d'API",
desc: "Choisir entre l'API GitHub ou l'API pour GitHub Entreprise (uniquement pour les utilisateur de GitHub entreprise).",
hostname: "Instance GitHub Entreprise",
hostnameDesc: "Le nom de votre instance GitHub Entreprise.",
dropdown: {
free: "Free/Pro/Team (défaut)",
enterprise: "Entreprise",
}
},
githubConfiguration: "Configuration GitHub",
repoName: "Nom du dépôt",
repoNameDesc:
Expand All @@ -58,7 +68,7 @@ export default {
testConnection: "Tester la connexion",
},
uploadConfig: {
uploadConfig: "Configuration d'upload", //désolée du franglais ici mais je trouve pas de traduction propre
title: "Configuration du transfert", //désolée du franglais ici mais je trouve pas de traduction propre
pathSetting: "Paramètres du chemin d'accès",
folderBehavior: "Comportement du dossier",
folderBehaviorDesc:
Expand Down
10 changes: 10 additions & 0 deletions plugin/i18n/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ export default {
exportSettings: "Export settings",
importSettings: "Import settings",
github: {
apiType: {
title: "API Type",
desc: "Choose between the Github API or the Github Enterprise API (for Github Enterprise users).",
hostname: "Github Enterprise Hostname",
hostnameDesc: "The hostname of your Github Enterprise instance.",
dropdown: {
free: "Free/Pro/Team (default)",
enterprise: "Enterprise",
}
},
githubConfiguration: "Настройки интеграции с Github",
repoName: "Repo Name",
repoNameDesc:
Expand Down
10 changes: 10 additions & 0 deletions plugin/i18n/locales/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ export default {
exportSettings: "Export settings",
importSettings: "Import settings",
github: {
apiType: {
title: "API Type",
desc: "Choose between the Github API or the Github Enterprise API (for Github Enterprise users).",
hostname: "Github Enterprise Hostname",
hostnameDesc: "The hostname of your Github Enterprise instance.",
dropdown: {
free: "Free/Pro/Team (default)",
enterprise: "Enterprise",
}
},
githubConfiguration: "Github设置",
repoName: "仓库名",
repoNameDesc: "你博客所在的github仓库名",
Expand Down
13 changes: 11 additions & 2 deletions plugin/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {FrontMatterCache, Menu, Plugin, TFile} from "obsidian";
import {GithubPublisherSettings} from "./settings";
import {DEFAULT_SETTINGS, GitHubPublisherSettings, RepoFrontmatter} from "./settings/interface";
import {DEFAULT_SETTINGS, GitHubPublisherSettings, GithubTiersVersion, RepoFrontmatter} from "./settings/interface";
import {convertOldSettings, disablePublish, getRepoFrontmatter,} from "./src/utils";
import {GithubBranch} from "./publishing/branch";
import {Octokit} from "@octokit/core";
Expand Down Expand Up @@ -38,7 +38,16 @@ export default class GithubPublisher extends Plugin {
* Create a new instance of Octokit to load a new instance of GithubBranch
*/
reloadOctokit() {
const octokit = new Octokit({ auth: this.settings.GhToken });
let octokit: Octokit;
if (this.settings.tiersForApi === GithubTiersVersion.entreprise && this.settings.hostname.length > 0) {
octokit = new Octokit(
{
baseUrl: `${this.settings.hostname}/api/v3`,
auth: this.settings.GhToken
});
} else {
octokit = new Octokit({auth: this.settings.GhToken});
}
return new GithubBranch(
this.settings,
octokit,
Expand Down
45 changes: 33 additions & 12 deletions plugin/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import {
folderSettings,
TextCleaner,
PUBLISHER_TABS,
PUBLISHER_TABS, GithubTiersVersion,
} from "./settings/interface";
import {settings, StringFunc, subSettings, t} from "./i18n";
import {
Expand Down Expand Up @@ -129,6 +129,36 @@ export class GithubPublisherSettings extends PluginSettingTab {
}

renderGithubConfiguration() {
new Setting(this.settingsPage)
.setName(subSettings("github.apiType.title") as string)
.setDesc(subSettings("github.apiType.desc") as string)
.addDropdown((dropdown) => {
dropdown
.addOption(GithubTiersVersion.free, subSettings("github.apiType.dropdown.free") as string)
.addOption(GithubTiersVersion.entreprise, subSettings("github.apiType.dropdown.enterprise") as string)
.setValue(this.plugin.settings.tiersForApi)
.onChange(async (value) => {
this.plugin.settings.tiersForApi = value as GithubTiersVersion;
await this.plugin.saveSettings();
this.settingsPage.empty();
this.renderGithubConfiguration();
});
});
if (this.plugin.settings.tiersForApi === GithubTiersVersion.entreprise) {
new Setting(this.settingsPage)
.setName(subSettings("github.apiType.hostname") as string)
.setDesc(subSettings("github.apiType.hostnameDesc") as string)
.addText((text) =>
text
.setPlaceholder("https://github.mycompany.com")
.setValue(this.plugin.settings.hostname)
.onChange(async (value) => {
this.plugin.settings.hostname = value.trim();
await this.plugin.saveSettings();
})
);
}

new Setting(this.settingsPage)
.setName(settings("github", "repoName") as string)
.setDesc(settings("github", "repoNameDesc") as string)
Expand Down Expand Up @@ -208,16 +238,7 @@ export class GithubPublisherSettings extends PluginSettingTab {
.setButtonText(settings("github", "testConnection") as string)
.setClass("github-publisher-connect-button")
.onClick(async () => {
const octokit = new Octokit({auth: this.plugin.settings.GhToken});
console.log(octokit);
const publisher = new GithubBranch(
this.plugin.settings,
octokit,
this.app.vault,
this.app.metadataCache,
this.plugin,
);
await checkRepositoryValidity(this.branchName, publisher, this.plugin.settings, null, this.app.metadataCache);
await checkRepositoryValidity(this.branchName, this.plugin.reloadOctokit(), this.plugin.settings, null, this.app.metadataCache);
})
);
this.settingsPage.createEl("h3", { text: "Github Workflow" });
Expand Down Expand Up @@ -422,7 +443,7 @@ export class GithubPublisherSettings extends PluginSettingTab {

const folderNoteSettings = new Setting(this.settingsPage)
.setName(subSettings("textConversion.links.folderNote") as string)
.setClass("github-publisher")
.setClass("github-publisher-folderNote")
.setDesc(
subSettings("textConversion.links.folderNoteDesc") as string
)
Expand Down
10 changes: 9 additions & 1 deletion plugin/settings/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export interface GitHubPublisherSettings {
convertInternalNonShared: boolean;
frontmatterTitleRegex: string;
frontmatterTitleReplacement: string;
tiersForApi: GithubTiersVersion;
hostname: string;
}

/**
Expand All @@ -99,6 +101,10 @@ export enum folderSettings {
fixed = "fixed",
}

export enum GithubTiersVersion {
free = "Github Free/Pro/Team (default)",
entreprise = "Enterprise",
}
/**
* Default settings of the plugins
* @type {{downloadedFolder: folderSettings.fixed, autoCleanUpExcluded: any[], subFolder: string, embedImage: boolean, dataviewFields: any[], githubName: string, useFrontmatterTitle: boolean, convertDataview: boolean, githubRepo: string, editorMenu: boolean, frontmatterTitleKey: string, metadataFileFields: any[], yamlFolderKey: string, folderDefaultName: string, copyLink: boolean, metadataExtractorPath: string, excludeDataviewValue: any[], GhToken: string, githubBranch: string, fileMenu: boolean, convertWikiLinks: boolean, embedNotes: boolean, folderNote: boolean, rootFolder: string, defaultImageFolder: string, mainLink: string, shareKey: string, workflowName: string, shareExternalModified: boolean, convertForGithub: boolean, autoCleanUp: boolean, inlineTags: boolean, logNotice: boolean, excludedFolder: any[], hardBreak: boolean, automaticallyMergePR: boolean, linkRemover: string, censorText: any[]}}
Expand Down Expand Up @@ -150,6 +156,8 @@ export const DEFAULT_SETTINGS: GitHubPublisherSettings = {
convertInternalNonShared: false,
frontmatterTitleRegex: "",
frontmatterTitleReplacement: "",
tiersForApi: GithubTiersVersion.free,
hostname: "",
};

export interface MetadataExtractor {
Expand Down Expand Up @@ -190,7 +198,7 @@ export const PUBLISHER_TABS = {
icon: "cloud",
},
"upload-configuration": {
name: "Upload Configuration",
name: settings("uploadConfig", "title") as string,
icon: "upload",
},
"text-conversion": {
Expand Down

0 comments on commit 0868c7b

Please sign in to comment.