mirror of
https://github.com/nathonius/obsidian-github-link.git
synced 2026-07-22 09:20:25 +00:00
Merge pull request #74 from nathonius/feat/70/icons
✨ feat: #70 Use specific icons for each state of issue and PR
This commit is contained in:
commit
fba45fae9b
8 changed files with 38 additions and 35 deletions
|
|
@ -12,7 +12,6 @@ import type {
|
|||
} from "./response";
|
||||
import type { RequestUrlParam, RequestUrlResponse } from "obsidian";
|
||||
|
||||
import { Logger } from "src/plugin";
|
||||
import { RequestError } from "src/util";
|
||||
import { requestUrl } from "obsidian";
|
||||
|
||||
|
|
@ -35,10 +34,8 @@ export async function githubRequest(config: RequestUrlParam, token?: string): Pr
|
|||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
Logger.debug(config);
|
||||
try {
|
||||
const response = await requestUrl(config);
|
||||
Logger.debug(response);
|
||||
return response;
|
||||
} catch (err) {
|
||||
throw new RequestError(err as Error);
|
||||
|
|
|
|||
|
|
@ -17,16 +17,14 @@ import { api, githubRequest } from "./api";
|
|||
|
||||
import { Cache } from "./cache";
|
||||
import type { GithubAccount } from "src/settings";
|
||||
import { Logger, PluginSettings } from "src/plugin";
|
||||
import { PluginSettings } from "src/plugin";
|
||||
|
||||
const cache = new Cache();
|
||||
|
||||
function getAccount(org?: string): GithubAccount | undefined {
|
||||
Logger.debug(`Getting account and token for org ${org}`);
|
||||
const account =
|
||||
PluginSettings.accounts.find((acc) => acc.orgs.some((savedOrg) => savedOrg === org)) ??
|
||||
PluginSettings.accounts.find((acc) => acc.id === PluginSettings.defaultAccount);
|
||||
Logger.debug(account);
|
||||
return account;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,16 @@ export function getSearchResultIssueStatus(issue: IssueSearchResponse["items"][n
|
|||
}
|
||||
}
|
||||
|
||||
export function getIssueStatus(issue: IssueResponse): IssueStatus {
|
||||
if (issue.state === "open") {
|
||||
return IssueStatus.Open;
|
||||
} else if (issue.state_reason === "completed") {
|
||||
return IssueStatus.Done;
|
||||
} else {
|
||||
return IssueStatus.Closed;
|
||||
}
|
||||
}
|
||||
|
||||
export function getPRStatus(pr: PullResponse): IssueStatus {
|
||||
if (pr.merged) {
|
||||
return IssueStatus.Done;
|
||||
|
|
|
|||
26
src/icon.ts
26
src/icon.ts
|
|
@ -1,20 +1,24 @@
|
|||
import { setIcon } from "obsidian";
|
||||
import { IssueStatus } from "./github/response";
|
||||
|
||||
const PRIcon: Readonly<Record<IssueStatus, string>> = {
|
||||
[IssueStatus.Open]: "lucide-git-pull-request-arrow",
|
||||
[IssueStatus.Closed]: "lucide-git-pull-request-closed",
|
||||
[IssueStatus.Done]: "lucide-git-merge",
|
||||
};
|
||||
|
||||
const IssueIcon: Readonly<Record<IssueStatus, string>> = {
|
||||
[IssueStatus.Open]: "lucide-circle-dot",
|
||||
[IssueStatus.Closed]: "lucide-circle-slash",
|
||||
[IssueStatus.Done]: "lucide-check-circle",
|
||||
};
|
||||
|
||||
export function setPRIcon(icon: HTMLElement, status: IssueStatus) {
|
||||
if (status !== IssueStatus.Closed) {
|
||||
setIcon(icon, "git-pull-request-arrow");
|
||||
} else {
|
||||
setIcon(icon, "git-pull-request-closed");
|
||||
}
|
||||
setIcon(icon, PRIcon[status]);
|
||||
icon.dataset.status = status;
|
||||
}
|
||||
|
||||
export function setIssueIcon(icon: HTMLElement, status: IssueStatus, reason: string | null | undefined) {
|
||||
if (reason === "not_planned") {
|
||||
setIcon(icon, "square-slash");
|
||||
} else {
|
||||
setIcon(icon, "square-dot");
|
||||
}
|
||||
export function setIssueIcon(icon: HTMLElement, status: IssueStatus) {
|
||||
setIcon(icon, IssueIcon[status]);
|
||||
icon.dataset.status = status;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import { getPRStatus } from "src/github/response";
|
||||
import { getIssueStatus, getPRStatus } from "src/github/response";
|
||||
import { getIssue, getPullRequest } from "../github/github";
|
||||
|
||||
import { parseUrl } from "../github/url-parse";
|
||||
import { setIcon } from "obsidian";
|
||||
import { setPRIcon } from "src/icon";
|
||||
import { setIssueIcon, setPRIcon } from "src/icon";
|
||||
import { Logger } from "src/plugin";
|
||||
|
||||
export async function createTag(href: string) {
|
||||
const parsedUrl = parseUrl(href);
|
||||
|
|
@ -35,13 +36,11 @@ export async function createTag(href: string) {
|
|||
// Get issue info
|
||||
if (parsedUrl.issue !== undefined) {
|
||||
const issue = await getIssue(parsedUrl.org, parsedUrl.repo, parsedUrl.issue);
|
||||
Logger.debug("Rendering tag for issue:");
|
||||
Logger.debug(issue);
|
||||
if (issue.title) {
|
||||
setIcon(icon, "square-dot");
|
||||
if (issue.pull_request?.merged_at) {
|
||||
icon.dataset.status = "done";
|
||||
} else {
|
||||
icon.dataset.status = issue.state;
|
||||
}
|
||||
const status = getIssueStatus(issue);
|
||||
setIssueIcon(icon, status);
|
||||
createTagSection(container).createSpan({
|
||||
cls: "github-link-inline-issue-title",
|
||||
text: issue.title,
|
||||
|
|
@ -52,6 +51,8 @@ export async function createTag(href: string) {
|
|||
// Get PR info
|
||||
if (parsedUrl.pr !== undefined) {
|
||||
const pull = await getPullRequest(parsedUrl.org, parsedUrl.repo, parsedUrl.pr);
|
||||
Logger.debug("Rendering tag for pull request:");
|
||||
Logger.debug(pull);
|
||||
if (pull.title) {
|
||||
const status = getPRStatus(pull);
|
||||
setPRIcon(icon, status);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ export class GithubLinkPlugin extends Plugin {
|
|||
async onload() {
|
||||
PluginSettings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
||||
Logger = verboseFactory(PluginSettings.logLevel);
|
||||
// Logger.debug(getIconIds());
|
||||
|
||||
this.addSettingTab(new GithubLinkPluginSettingsTab(this.app, this));
|
||||
this.registerMarkdownPostProcessor(InlineRenderer);
|
||||
this.registerEditorExtension(createInlineViewPlugin(this));
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ export const IssueColumns: ColumnsMap<IssueSearchResponse["items"][number]> = {
|
|||
const wrapper = el.createDiv({ cls: "github-link-table-status" });
|
||||
const status = getSearchResultIssueStatus(row);
|
||||
const icon = wrapper.createSpan({ cls: "github-link-status-icon" });
|
||||
setIssueIcon(icon, status, row.state_reason);
|
||||
setIssueIcon(icon, status);
|
||||
wrapper.createSpan({ text: row.state_reason === "not_planned" ? "Not Planned" : titleCase(status) });
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import { QueryType, isTableParams, isTableQueryParams, processParams } from "./p
|
|||
import { renderTable } from "./output";
|
||||
import { searchIssues, getIssuesForRepo, getMyIssues, getPullRequestsForRepo } from "src/github/github";
|
||||
import type { IssueListParams, IssueSearchParams, PullListParams } from "src/github/response";
|
||||
import { Logger } from "src/plugin";
|
||||
|
||||
export async function QueryProcessor(
|
||||
source: string,
|
||||
|
|
@ -13,8 +12,6 @@ export async function QueryProcessor(
|
|||
): Promise<void> {
|
||||
const params = processParams(source);
|
||||
|
||||
Logger.debug(params);
|
||||
|
||||
if (!params) {
|
||||
// TODO: show an error instead
|
||||
el.setText(source);
|
||||
|
|
@ -22,9 +19,6 @@ export async function QueryProcessor(
|
|||
}
|
||||
|
||||
const renderFn = async (element: HTMLElement, skipCache = false) => {
|
||||
if (skipCache) {
|
||||
Logger.debug("Skipping cache for this render.");
|
||||
}
|
||||
let response: { items: unknown[] } | unknown[] | undefined = undefined;
|
||||
if (isTableQueryParams(params)) {
|
||||
if (params.queryType === QueryType.Issue || params.queryType === QueryType.PullRequest) {
|
||||
|
|
@ -40,12 +34,9 @@ export async function QueryProcessor(
|
|||
response = await getMyIssues(issueParams, issueParams.org, skipCache);
|
||||
}
|
||||
} else if (params.queryType === QueryType.PullRequest) {
|
||||
Logger.debug("Rendering pull table...");
|
||||
const pullParams = params as TableParams<PullListParams>;
|
||||
if (pullParams.org && pullParams.repo) {
|
||||
response = await getPullRequestsForRepo(pullParams, pullParams.org, pullParams.repo, skipCache);
|
||||
Logger.debug("Got PRs");
|
||||
Logger.debug(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue