This commit is contained in:
Oscar Plaisant
2024-12-17 18:49:14 +01:00
parent c891129430
commit 3a5cad8e48
520 changed files with 20726 additions and 344954 deletions

View File

@@ -4013,11 +4013,11 @@ var RequestError = class extends Error {
* Response object if a response was received
*/
__publicField(this, "response");
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
this.name = "HttpError";
this.status = statusCode;
this.status = Number.parseInt(statusCode);
if (Number.isNaN(this.status)) {
this.status = 0;
}
if ("response" in options2) {
this.response = options2.response;
}
@@ -4037,129 +4037,115 @@ var RequestError = class extends Error {
// node_modules/@octokit/rest/node_modules/@octokit/request/dist-bundle/index.js
var VERSION2 = "0.0.0-development";
var defaults_default = {
headers: {
"user-agent": `octokit-request.js/${VERSION2} ${getUserAgent()}`
}
};
function isPlainObject2(value) {
if (typeof value !== "object" || value === null)
return false;
if (Object.prototype.toString.call(value) !== "[object Object]")
return false;
if (typeof value !== "object" || value === null) return false;
if (Object.prototype.toString.call(value) !== "[object Object]") return false;
const proto = Object.getPrototypeOf(value);
if (proto === null)
return true;
if (proto === null) return true;
const Ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
return typeof Ctor === "function" && Ctor instanceof Ctor && Function.prototype.call(Ctor) === Function.prototype.call(value);
}
function getBufferResponse(response) {
return response.arrayBuffer();
}
function fetchWrapper(requestOptions) {
var _a, _b, _c, _d;
const log = requestOptions.request && requestOptions.request.log ? requestOptions.request.log : console;
const parseSuccessResponseBody = ((_a = requestOptions.request) == null ? void 0 : _a.parseSuccessResponseBody) !== false;
if (isPlainObject2(requestOptions.body) || Array.isArray(requestOptions.body)) {
requestOptions.body = JSON.stringify(requestOptions.body);
}
let headers = {};
let status;
let url;
let { fetch } = globalThis;
if ((_b = requestOptions.request) == null ? void 0 : _b.fetch) {
fetch = requestOptions.request.fetch;
}
if (!fetch) {
throw new Error(
"fetch is not set. Please pass a fetch implementation as new Octokit({ request: { fetch }}). Learn more at https://github.com/octokit/octokit.js/#fetch-missing"
);
}
return fetch(requestOptions.url, __spreadValues({
method: requestOptions.method,
body: requestOptions.body,
redirect: (_c = requestOptions.request) == null ? void 0 : _c.redirect,
// Header values must be `string`
headers: Object.fromEntries(
return __async(this, null, function* () {
var _a, _b, _c, _d, _e;
const fetch = ((_a = requestOptions.request) == null ? void 0 : _a.fetch) || globalThis.fetch;
if (!fetch) {
throw new Error(
"fetch is not set. Please pass a fetch implementation as new Octokit({ request: { fetch }}). Learn more at https://github.com/octokit/octokit.js/#fetch-missing"
);
}
const log = ((_b = requestOptions.request) == null ? void 0 : _b.log) || console;
const parseSuccessResponseBody = ((_c = requestOptions.request) == null ? void 0 : _c.parseSuccessResponseBody) !== false;
const body = isPlainObject2(requestOptions.body) || Array.isArray(requestOptions.body) ? JSON.stringify(requestOptions.body) : requestOptions.body;
const requestHeaders = Object.fromEntries(
Object.entries(requestOptions.headers).map(([name, value]) => [
name,
String(value)
])
),
signal: (_d = requestOptions.request) == null ? void 0 : _d.signal
}, requestOptions.body && { duplex: "half" })).then((response) => __async(this, null, function* () {
url = response.url;
status = response.status;
for (const keyAndValue of response.headers) {
headers[keyAndValue[0]] = keyAndValue[1];
);
let fetchResponse;
try {
fetchResponse = yield fetch(requestOptions.url, __spreadValues({
method: requestOptions.method,
body,
redirect: (_d = requestOptions.request) == null ? void 0 : _d.redirect,
headers: requestHeaders,
signal: (_e = requestOptions.request) == null ? void 0 : _e.signal
}, requestOptions.body && { duplex: "half" }));
} catch (error) {
let message = "Unknown Error";
if (error instanceof Error) {
if (error.name === "AbortError") {
error.status = 500;
throw error;
}
message = error.message;
if (error.name === "TypeError" && "cause" in error) {
if (error.cause instanceof Error) {
message = error.cause.message;
} else if (typeof error.cause === "string") {
message = error.cause;
}
}
}
const requestError = new RequestError(message, 500, {
request: requestOptions
});
requestError.cause = error;
throw requestError;
}
if ("deprecation" in headers) {
const matches = headers.link && headers.link.match(/<([^>]+)>; rel="deprecation"/);
const status = fetchResponse.status;
const url = fetchResponse.url;
const responseHeaders = {};
for (const [key, value] of fetchResponse.headers) {
responseHeaders[key] = value;
}
const octokitResponse = {
url,
status,
headers: responseHeaders,
data: ""
};
if ("deprecation" in responseHeaders) {
const matches = responseHeaders.link && responseHeaders.link.match(/<([^>]+)>; rel="deprecation"/);
const deprecationLink = matches && matches.pop();
log.warn(
`[@octokit/request] "${requestOptions.method} ${requestOptions.url}" is deprecated. It is scheduled to be removed on ${headers.sunset}${deprecationLink ? `. See ${deprecationLink}` : ""}`
`[@octokit/request] "${requestOptions.method} ${requestOptions.url}" is deprecated. It is scheduled to be removed on ${responseHeaders.sunset}${deprecationLink ? `. See ${deprecationLink}` : ""}`
);
}
if (status === 204 || status === 205) {
return;
return octokitResponse;
}
if (requestOptions.method === "HEAD") {
if (status < 400) {
return;
return octokitResponse;
}
throw new RequestError(response.statusText, status, {
response: {
url,
status,
headers,
data: void 0
},
throw new RequestError(fetchResponse.statusText, status, {
response: octokitResponse,
request: requestOptions
});
}
if (status === 304) {
octokitResponse.data = yield getResponseData(fetchResponse);
throw new RequestError("Not modified", status, {
response: {
url,
status,
headers,
data: yield getResponseData(response)
},
response: octokitResponse,
request: requestOptions
});
}
if (status >= 400) {
const data = yield getResponseData(response);
const error = new RequestError(toErrorMessage(data), status, {
response: {
url,
status,
headers,
data
},
octokitResponse.data = yield getResponseData(fetchResponse);
throw new RequestError(toErrorMessage(octokitResponse.data), status, {
response: octokitResponse,
request: requestOptions
});
throw error;
}
return parseSuccessResponseBody ? yield getResponseData(response) : response.body;
})).then((data) => {
return {
status,
url,
headers,
data
};
}).catch((error) => {
if (error instanceof RequestError)
throw error;
else if (error.name === "AbortError")
throw error;
let message = error.message;
if (error.name === "TypeError" && "cause" in error) {
if (error.cause instanceof Error) {
message = error.cause.message;
} else if (typeof error.cause === "string") {
message = error.cause;
}
}
throw new RequestError(message, 500, {
request: requestOptions
});
octokitResponse.data = parseSuccessResponseBody ? yield getResponseData(fetchResponse) : fetchResponse.body;
return octokitResponse;
});
}
function getResponseData(response) {
@@ -4171,23 +4157,19 @@ function getResponseData(response) {
if (!contentType || /^text\/|charset=utf-8$/.test(contentType)) {
return response.text();
}
return getBufferResponse(response);
return response.arrayBuffer();
});
}
function toErrorMessage(data) {
if (typeof data === "string")
if (typeof data === "string") {
return data;
let suffix;
if ("documentation_url" in data) {
suffix = ` - ${data.documentation_url}`;
} else {
suffix = "";
}
if (data instanceof ArrayBuffer) {
return "Unknown error";
}
if ("message" in data) {
if (Array.isArray(data.errors)) {
return `${data.message}: ${data.errors.map(JSON.stringify).join(", ")}${suffix}`;
}
return `${data.message}${suffix}`;
const suffix = "documentation_url" in data ? ` - ${data.documentation_url}` : "";
return Array.isArray(data.errors) ? `${data.message}: ${data.errors.map((v) => JSON.stringify(v)).join(", ")}${suffix}` : `${data.message}${suffix}`;
}
return `Unknown error: ${JSON.stringify(data)}`;
}
@@ -4214,11 +4196,7 @@ function withDefaults2(oldEndpoint, newDefaults) {
defaults: withDefaults2.bind(null, endpoint2)
});
}
var request = withDefaults2(endpoint, {
headers: {
"user-agent": `octokit-request.js/${VERSION2} ${getUserAgent()}`
}
});
var request = withDefaults2(endpoint, defaults_default);
// node_modules/@octokit/rest/node_modules/@octokit/graphql/dist-bundle/index.js
var VERSION3 = "0.0.0-development";
@@ -4508,7 +4486,7 @@ __publicField(Octokit, "VERSION", VERSION4);
__publicField(Octokit, "plugins", []);
// node_modules/@octokit/rest/node_modules/@octokit/plugin-request-log/dist-src/version.js
var VERSION5 = "5.3.0";
var VERSION5 = "5.3.1";
// node_modules/@octokit/rest/node_modules/@octokit/plugin-request-log/dist-src/index.js
function requestLog(octokit) {
@@ -4524,7 +4502,8 @@ function requestLog(octokit) {
);
return response;
}).catch((error) => {
const requestId = error.response.headers["x-github-request-id"] || "UNKNOWN";
var _a;
const requestId = ((_a = error.response) == null ? void 0 : _a.headers["x-github-request-id"]) || "UNKNOWN";
octokit.log.error(
`${requestOptions.method} ${path} - ${error.status} with id ${requestId} in ${Date.now() - start}ms`
);
@@ -6719,7 +6698,7 @@ function legacyRestEndpointMethods(octokit) {
legacyRestEndpointMethods.VERSION = VERSION7;
// node_modules/@octokit/rest/dist-src/version.js
var VERSION8 = "21.0.0";
var VERSION8 = "21.0.1";
// node_modules/@octokit/rest/dist-src/index.js
var Octokit2 = Octokit.plugin(requestLog, legacyRestEndpointMethods, paginateRest).defaults(
@@ -6728,12 +6707,85 @@ var Octokit2 = Octokit.plugin(requestLog, legacyRestEndpointMethods, paginateRes
}
);
// src/shared-gists.ts
var import_gray_matter = __toESM(require_gray_matter());
var getBaseUrlForSharedGist = (sharedGist) => sharedGist.baseUrl || DOTCOM_BASE_URL;
var getTargetForSharedGist = (sharedGist) => getBaseUrlForSharedGist(sharedGist) === DOTCOM_BASE_URL ? "dotcom" /* Dotcom */ : "github_enterprise_server" /* GitHubEnterpriseServer */;
var getSharedGistsForFile = (fileContents, target) => {
const { data } = (0, import_gray_matter.default)(fileContents);
const gists = data.gists || [];
return gists.filter((gist) => {
if (typeof target === "undefined") {
return true;
}
return getTargetForSharedGist(gist) === target;
});
};
var upsertSharedGistForFile = (sharedGist, fileContents) => {
const { data, content } = (0, import_gray_matter.default)(fileContents);
const existingSharedGists = data.gists || [];
const matchingGist = existingSharedGists.find(
(existingSharedGist) => existingSharedGist.id === sharedGist.id
);
if (matchingGist) {
const otherGists = existingSharedGists.filter(
(existingSharedGist) => existingSharedGist !== matchingGist
);
const gists = [...otherGists, sharedGist];
const updatedData = __spreadProps(__spreadValues({}, data), { gists });
return import_gray_matter.default.stringify(content, updatedData);
} else {
const gists = [...existingSharedGists, sharedGist];
const updatedData = __spreadProps(__spreadValues({}, data), { gists });
return import_gray_matter.default.stringify(content, updatedData);
}
};
// src/storage.ts
var DOTCOM_ACCESS_TOKEN_LOCAL_STORAGE_KEY = "share_as_gist_dotcom_access_token";
var GHES_BASE_URL_LOCAL_STORAGE_KEY = "share_as_gist_ghes_base_url";
var GHES_ACCESS_TOKEN_LOCAL_STORAGE_KEY = "share_as_gist_ghes_access_token";
var getDotcomAccessToken = () => localStorage.getItem(DOTCOM_ACCESS_TOKEN_LOCAL_STORAGE_KEY);
var setDotcomAccessToken = (accessToken) => localStorage.setItem(DOTCOM_ACCESS_TOKEN_LOCAL_STORAGE_KEY, accessToken);
var isDotcomEnabled = () => !!getDotcomAccessToken();
var getGhesBaseUrl = () => localStorage.getItem(GHES_BASE_URL_LOCAL_STORAGE_KEY);
var setGhesBaseUrl = (baseUrl) => localStorage.setItem(GHES_BASE_URL_LOCAL_STORAGE_KEY, baseUrl);
var getGhesAccessToken = () => localStorage.getItem(GHES_ACCESS_TOKEN_LOCAL_STORAGE_KEY);
var setGhesAccessToken = (accessToken) => localStorage.setItem(GHES_ACCESS_TOKEN_LOCAL_STORAGE_KEY, accessToken);
var isGhesEnabled = () => !!getGhesBaseUrl() && !!getGhesAccessToken();
var getTargetBaseUrl = (target) => {
switch (target) {
case "dotcom" /* Dotcom */:
return DOTCOM_BASE_URL;
case "github_enterprise_server" /* GitHubEnterpriseServer */:
return getGhesBaseUrl();
}
};
var getAccessTokenForBaseUrl = (baseUrl) => {
if (baseUrl === DOTCOM_BASE_URL) {
return getDotcomAccessToken();
} else {
return getGhesAccessToken();
}
};
// src/gists.ts
var DOTCOM_BASE_URL = "https://api.github.com";
var updateGist = (opts) => __async(void 0, null, function* () {
const { accessToken, sharedGist, content } = opts;
const { sharedGist, content } = opts;
const baseUrl = getBaseUrlForSharedGist(sharedGist);
const accessToken = getAccessTokenForBaseUrl(baseUrl);
if (!accessToken) {
return {
status: "failed" /* Failed */,
sharedGist,
errorMessage: `No access token found for the ${baseUrl} target.`
};
}
try {
const octokit = new Octokit2({
auth: accessToken
auth: accessToken,
baseUrl
});
const response = yield octokit.rest.gists.update({
gist_id: sharedGist.id,
@@ -6756,9 +6808,12 @@ var updateGist = (opts) => __async(void 0, null, function* () {
});
var createGist = (opts) => __async(void 0, null, function* () {
try {
const { accessToken, content, description, filename, isPublic } = opts;
const { content, description, filename, isPublic, target } = opts;
const baseUrl = getTargetBaseUrl(target);
const accessToken = getAccessTokenForBaseUrl(baseUrl);
const octokit = new Octokit2({
auth: accessToken
auth: accessToken,
baseUrl
});
const response = yield octokit.rest.gists.create({
description: description || filename,
@@ -6775,7 +6830,8 @@ var createGist = (opts) => __async(void 0, null, function* () {
createdAt: response.data.created_at,
updatedAt: response.data.updated_at,
filename,
isPublic
isPublic,
baseUrl
},
errorMessage: null
};
@@ -6788,38 +6844,6 @@ var createGist = (opts) => __async(void 0, null, function* () {
}
});
// src/storage.ts
var ACCESS_TOKEN_LOCAL_STORAGE_KEY = "share_as_gist_dotcom_access_token";
var getAccessToken = () => localStorage.getItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY);
var setAccessToken = (accessToken) => localStorage.setItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY, accessToken);
// src/shared-gists.ts
var import_gray_matter = __toESM(require_gray_matter());
var getSharedGistsForFile = (fileContents) => {
const { data } = (0, import_gray_matter.default)(fileContents);
const gists = data.gists || [];
return gists;
};
var upsertSharedGistForFile = (sharedGist, fileContents) => {
const { data, content } = (0, import_gray_matter.default)(fileContents);
const existingSharedGists = data.gists || [];
const matchingGist = existingSharedGists.find(
(existingSharedGist) => existingSharedGist.id === sharedGist.id
);
if (matchingGist) {
const otherGists = existingSharedGists.filter(
(existingSharedGist) => existingSharedGist !== matchingGist
);
const gists = [...otherGists, sharedGist];
const updatedData = __spreadProps(__spreadValues({}, data), { gists });
return import_gray_matter.default.stringify(content, updatedData);
} else {
const gists = [...existingSharedGists, sharedGist];
const updatedData = __spreadProps(__spreadValues({}, data), { gists });
return import_gray_matter.default.stringify(content, updatedData);
}
};
// main.ts
var DEFAULT_SETTINGS = {
includeFrontMatter: false,
@@ -6834,12 +6858,6 @@ var getLatestSettings = (plugin) => __async(void 0, null, function* () {
var stripFrontMatter = (content) => (0, import_gray_matter2.default)(content).content;
var copyGistUrlEditorCallback = (opts) => () => __async(void 0, null, function* () {
const { app, plugin } = opts;
const { enableUpdatingGistsAfterCreation } = yield getLatestSettings(plugin);
if (!enableUpdatingGistsAfterCreation) {
return new import_obsidian.Notice(
"You need to enable 'Update gists after creation' in Settings to use this command."
);
}
const view = app.workspace.getActiveViewOfType(import_obsidian.MarkdownView);
if (!view) {
return new import_obsidian.Notice("No active file");
@@ -6848,9 +6866,16 @@ var copyGistUrlEditorCallback = (opts) => () => __async(void 0, null, function*
const originalContent = editor.getValue();
const existingSharedGists = getSharedGistsForFile(originalContent);
if (existingSharedGists.length === 0) {
return new import_obsidian.Notice(
"You must share this note as a gist before you can copy its URL to the clipboard."
);
const { enableUpdatingGistsAfterCreation } = yield getLatestSettings(plugin);
if (!enableUpdatingGistsAfterCreation) {
return new import_obsidian.Notice(
"You need to enable 'Update gists after creation' in Settings to use this command."
);
} else {
return new import_obsidian.Notice(
"You must share this note as a gist before you can copy its URL to the clipboard."
);
}
}
if (existingSharedGists.length > 1) {
new SelectExistingGistModal(
@@ -6870,12 +6895,6 @@ var copyGistUrlEditorCallback = (opts) => () => __async(void 0, null, function*
});
var openGistEditorCallback = (opts) => () => __async(void 0, null, function* () {
const { app, plugin } = opts;
const { enableUpdatingGistsAfterCreation } = yield getLatestSettings(plugin);
if (!enableUpdatingGistsAfterCreation) {
return new import_obsidian.Notice(
"You need to enable 'Update gists after creation' in Settings to use this command."
);
}
const view = app.workspace.getActiveViewOfType(import_obsidian.MarkdownView);
if (!view) {
return new import_obsidian.Notice("No active file");
@@ -6884,9 +6903,16 @@ var openGistEditorCallback = (opts) => () => __async(void 0, null, function* ()
const originalContent = editor.getValue();
const existingSharedGists = getSharedGistsForFile(originalContent);
if (existingSharedGists.length === 0) {
return new import_obsidian.Notice(
"You must share this note as a gist before you can open its gist."
);
const { enableUpdatingGistsAfterCreation } = yield getLatestSettings(plugin);
if (!enableUpdatingGistsAfterCreation) {
return new import_obsidian.Notice(
"You need to enable 'Update gists after creation' in Settings to use this command."
);
} else {
return new import_obsidian.Notice(
"You must share this note as a gist before you can open its gist."
);
}
}
if (existingSharedGists.length > 1) {
new SelectExistingGistModal(
@@ -6903,14 +6929,8 @@ var openGistEditorCallback = (opts) => () => __async(void 0, null, function* ()
}
});
var shareGistEditorCallback = (opts) => () => __async(void 0, null, function* () {
const { isPublic, app, plugin } = opts;
const accessToken = getAccessToken();
const { isPublic, app, plugin, target } = opts;
const { enableUpdatingGistsAfterCreation, includeFrontMatter } = yield getLatestSettings(plugin);
if (!accessToken) {
return new import_obsidian.Notice(
"You need to add your GitHub personal access token in Settings."
);
}
const view = app.workspace.getActiveViewOfType(import_obsidian.MarkdownView);
if (!view) {
return new import_obsidian.Notice("No active file");
@@ -6918,9 +6938,10 @@ var shareGistEditorCallback = (opts) => () => __async(void 0, null, function* ()
const editor = view.editor;
const originalContent = editor.getValue();
const filename = view.file.name;
const existingSharedGists = getSharedGistsForFile(originalContent).filter(
(sharedGist) => sharedGist.isPublic === isPublic
);
const existingSharedGists = getSharedGistsForFile(
originalContent,
target
).filter((sharedGist) => sharedGist.isPublic === isPublic);
const gistContent = includeFrontMatter ? originalContent : stripFrontMatter(originalContent);
if (enableUpdatingGistsAfterCreation && existingSharedGists.length) {
new SelectExistingGistModal(
@@ -6931,7 +6952,6 @@ var shareGistEditorCallback = (opts) => () => __async(void 0, null, function* ()
if (sharedGist) {
const result = yield updateGist({
sharedGist,
accessToken,
content: gistContent
});
if (result.status === "succeeded" /* Succeeded */) {
@@ -6945,12 +6965,12 @@ var shareGistEditorCallback = (opts) => () => __async(void 0, null, function* ()
);
editor.setValue(updatedContent);
} else {
new import_obsidian.Notice(`GitHub API error: ${result.errorMessage}`);
new import_obsidian.Notice(`Error: ${result.errorMessage}`);
}
} else {
new SetGistDescriptionModal(app, filename, (description) => __async(void 0, null, function* () {
const result = yield createGist({
accessToken,
target,
content: gistContent,
description,
filename,
@@ -6967,7 +6987,7 @@ var shareGistEditorCallback = (opts) => () => __async(void 0, null, function* ()
);
editor.setValue(updatedContent);
} else {
new import_obsidian.Notice(`GitHub API error: ${result.errorMessage}`);
new import_obsidian.Notice(`Error: ${result.errorMessage}`);
}
})).open();
}
@@ -6976,7 +6996,7 @@ var shareGistEditorCallback = (opts) => () => __async(void 0, null, function* ()
} else {
new SetGistDescriptionModal(app, filename, (description) => __async(void 0, null, function* () {
const result = yield createGist({
accessToken,
target,
content: gistContent,
description,
filename,
@@ -7003,18 +7023,12 @@ var shareGistEditorCallback = (opts) => () => __async(void 0, null, function* ()
});
var documentChangedAutoSaveCallback = (opts) => __async(void 0, null, function* () {
const { plugin, file, content: rawContent } = opts;
const accessToken = getAccessToken();
const { includeFrontMatter, showAutoSaveNotice } = yield getLatestSettings(plugin);
if (!accessToken) {
return new import_obsidian.Notice(
"You need to add your GitHub personal access token in Settings."
);
}
const existingSharedGists = getSharedGistsForFile(rawContent);
const content = includeFrontMatter ? rawContent : stripFrontMatter(rawContent);
if (existingSharedGists.length) {
for (const sharedGist of existingSharedGists) {
const result = yield updateGist({ sharedGist, accessToken, content });
const result = yield updateGist({ sharedGist, content });
if (result.status === "succeeded" /* Succeeded */) {
const updatedContent = upsertSharedGistForFile(
result.sharedGist,
@@ -7022,56 +7036,107 @@ var documentChangedAutoSaveCallback = (opts) => __async(void 0, null, function*
);
yield file.vault.adapter.write(file.path, updatedContent);
if (showAutoSaveNotice) {
new import_obsidian.Notice("Gist updated");
return new import_obsidian.Notice("Gist updated");
}
} else {
new import_obsidian.Notice(`GitHub API error: ${result.errorMessage}`);
return new import_obsidian.Notice(`Error: ${result.errorMessage}`);
}
}
}
});
var hasAtLeastOneSharedGist = (editor) => {
const originalContent = editor.getValue();
const existingSharedGists = getSharedGistsForFile(originalContent);
return existingSharedGists.length > 0;
};
var ShareAsGistPlugin = class extends import_obsidian.Plugin {
onload() {
return __async(this, null, function* () {
yield this.loadSettings();
this.addCommand({
id: "share-as-public-dotcom-gist",
name: "Share as public gist on GitHub.com",
editorCallback: shareGistEditorCallback({
plugin: this,
app: this.app,
isPublic: true
})
});
this.addCommand({
id: "share-as-private-dotcom-gist",
name: "Share as private gist on GitHub.com",
callback: shareGistEditorCallback({
plugin: this,
app: this.app,
isPublic: false
})
});
this.addCommand({
id: "copy-gist-url",
name: "Copy GitHub.com gist URL",
callback: copyGistUrlEditorCallback({
plugin: this,
app: this.app
})
});
this.addCommand({
id: "open-gist-url",
name: "Open gist on GitHub.com",
callback: openGistEditorCallback({
plugin: this,
app: this.app
})
});
this.registerCommands();
this.addModifyCallback();
this.addSettingTab(new ShareAsGistSettingTab(this.app, this));
});
}
addEditorCommandWithCheck(opts) {
const { id, name, performCheck, callback } = opts;
this.addCommand({
id,
name,
editorCheckCallback: (checking, editor, ctx) => {
if (performCheck(editor, ctx)) {
if (checking) {
return true;
}
callback(editor, ctx);
}
}
});
}
registerCommands() {
this.addEditorCommandWithCheck({
id: "share-as-private-dotcom-gist",
name: "Share as private gist on GitHub.com",
callback: shareGistEditorCallback({
plugin: this,
app: this.app,
isPublic: false,
target: "dotcom" /* Dotcom */
}),
performCheck: isDotcomEnabled
});
this.addEditorCommandWithCheck({
id: "share-as-public-dotcom-gist",
name: "Share as public gist on GitHub.com",
callback: shareGistEditorCallback({
plugin: this,
app: this.app,
isPublic: true,
target: "dotcom" /* Dotcom */
}),
performCheck: isDotcomEnabled
});
this.addEditorCommandWithCheck({
id: "share-as-private-ghes-gist",
name: "Share as private gist on GitHub Enterprise Server",
callback: shareGistEditorCallback({
plugin: this,
app: this.app,
isPublic: false,
target: "github_enterprise_server" /* GitHubEnterpriseServer */
}),
performCheck: isGhesEnabled
});
this.addEditorCommandWithCheck({
id: "share-as-public-ghes-gist",
name: "Share as public gist on GitHub Enterprise Server",
callback: shareGistEditorCallback({
plugin: this,
app: this.app,
isPublic: true,
target: "github_enterprise_server" /* GitHubEnterpriseServer */
}),
performCheck: isGhesEnabled
});
this.addEditorCommandWithCheck({
id: "copy-gist-url",
name: "Copy gist URL",
callback: copyGistUrlEditorCallback({
plugin: this,
app: this.app
}),
performCheck: hasAtLeastOneSharedGist
});
this.addEditorCommandWithCheck({
id: "open-gist-url",
name: "Open gist",
callback: openGistEditorCallback({
plugin: this,
app: this.app
}),
performCheck: hasAtLeastOneSharedGist
});
}
addModifyCallback() {
const previousContents = {};
const debouncedCallbacks = {};
@@ -7130,8 +7195,9 @@ var SelectExistingGistModal = class extends import_obsidian.SuggestModal {
if (sharedGist === null) {
el.createEl("div", { text: "Create new gist" });
} else {
const targetLabel = getTargetForSharedGist(sharedGist) === "dotcom" /* Dotcom */ ? "GitHub.com" : new URL(sharedGist.baseUrl).host;
el.createEl("div", {
text: sharedGist.isPublic ? "Public gist" : "Private gist"
text: (sharedGist.isPublic ? "Public gist" : "Private gist") + ` on ${targetLabel}`
});
el.createEl("small", { text: `Created at ${sharedGist.createdAt}` });
}
@@ -7187,14 +7253,38 @@ var ShareAsGistSettingTab = class extends import_obsidian.PluginSettingTab {
}
display() {
const { containerEl } = this;
const accessToken = getAccessToken();
const dotcomAccessToken = getDotcomAccessToken();
const ghesBaseUrl = getGhesBaseUrl();
const ghesAccessToken = getGhesAccessToken();
containerEl.empty();
containerEl.createEl("h2", { text: "Share as Gist" });
new import_obsidian.Setting(containerEl).setName("GitHub.com personal access token").setDesc(
containerEl.createEl("h3", { text: "GitHub.com" });
new import_obsidian.Setting(containerEl).setName("Personal access token").setDesc(
'An access token for GitHub.com with permission to write gists. You can create one from "Settings" in your GitHub account.'
).addText(
(text) => text.setPlaceholder("Your personal access token").setValue(accessToken).onChange(setAccessToken)
(text) => text.setPlaceholder("Your personal access token").setValue(dotcomAccessToken).onChange((value) => __async(this, null, function* () {
setDotcomAccessToken(value);
yield this.plugin.saveSettings();
}))
);
containerEl.createEl("h3", { text: "GitHub Enterprise Server" });
new import_obsidian.Setting(containerEl).setName("Base URL").setDesc(
"The base URL for the GitHub REST API on your GitHub Enterprise Server instance. This usually ends with `/api/v3`."
).addText(
(text) => text.setPlaceholder("https://github.example.com/api/v3").setValue(ghesBaseUrl).onChange((value) => __async(this, null, function* () {
setGhesBaseUrl(value);
yield this.plugin.saveSettings();
}))
);
new import_obsidian.Setting(containerEl).setName("Personal access token").setDesc(
'An access token for your GitHub Enterprise Server instance with permission to write gists. You can create one from "Settings" in your GitHub account.'
).addText(
(text) => text.setPlaceholder("Your personal access token").setValue(ghesAccessToken).onChange((value) => __async(this, null, function* () {
setGhesAccessToken(value);
yield this.plugin.saveSettings();
}))
);
containerEl.createEl("h3", { text: "Advanced options" });
new import_obsidian.Setting(containerEl).setName("Enable updating gists after creation").setDesc(
"Whether gists should be updateable through this plugin after creation. If this is turned on, when you create a gist, you will be able to choose to update an existing gist (if one exists) or create a brand new one. To make this possible, front matter will be added to your notes to track gists that you have created. If this is turned off, a brand new gist will always be created."
).addToggle(
@@ -7243,3 +7333,5 @@ strip-bom-string/index.js:
* Released under the MIT License.
*)
*/
/* nosourcemap */

View File

@@ -1,7 +1,7 @@
{
"id": "obsidian-share-as-gist",
"name": "Share as Gist",
"version": "1.6.1",
"version": "1.7.0",
"minAppVersion": "0.9.7",
"description": "Shares an Obsidian note as a GitHub.com gist",
"author": "Tim Rogers",