2025-06-07 19:21:15 +03:00
|
|
|
import {GET} from '../modules/fetch.js';
|
|
|
|
import {parseIssueHref, parseRepoOwnerPathInfo} from '../utils.js';
|
2025-06-07 18:21:41 +03:00
|
|
|
|
2025-06-06 01:25:07 +03:00
|
|
|
export function getIssueIcon(issue) {
|
2025-06-07 21:27:15 +03:00
|
|
|
if (issue.is_pr) {
|
2025-06-07 19:21:15 +03:00
|
|
|
if (issue.state === 'open') {
|
2025-06-07 21:27:15 +03:00
|
|
|
if (issue.draft === true) {
|
2025-06-07 19:21:15 +03:00
|
|
|
return 'octicon-git-pull-request-draft'; // WIP PR
|
2025-06-06 01:25:07 +03:00
|
|
|
}
|
2025-06-07 19:21:15 +03:00
|
|
|
return 'octicon-git-pull-request'; // Open PR
|
2025-06-07 21:27:15 +03:00
|
|
|
} else if (issue.merged === true) {
|
2025-06-07 19:21:15 +03:00
|
|
|
return 'octicon-git-merge'; // Merged PR
|
2025-06-06 01:25:07 +03:00
|
|
|
}
|
2025-06-07 19:21:15 +03:00
|
|
|
return 'octicon-git-pull-request'; // Closed PR
|
|
|
|
} else if (issue.state === 'open') {
|
|
|
|
return 'octicon-issue-opened'; // Open Issue
|
2025-06-06 01:25:07 +03:00
|
|
|
}
|
2025-06-07 19:21:15 +03:00
|
|
|
return 'octicon-issue-closed'; // Closed Issue
|
|
|
|
}
|
|
|
|
|
2025-06-07 18:21:41 +03:00
|
|
|
export function getIssueColor(issue) {
|
2025-06-07 21:27:15 +03:00
|
|
|
if (issue.is_pr) {
|
|
|
|
if (issue.draft === true) {
|
2025-06-07 18:21:41 +03:00
|
|
|
return 'grey'; // WIP PR
|
2025-06-07 21:27:15 +03:00
|
|
|
} else if (issue.merged === true) {
|
2025-06-07 18:21:41 +03:00
|
|
|
return 'purple'; // Merged PR
|
2025-06-06 01:25:07 +03:00
|
|
|
}
|
2025-06-07 18:21:41 +03:00
|
|
|
}
|
|
|
|
if (issue.state === 'open') {
|
|
|
|
return 'green'; // Open Issue
|
|
|
|
}
|
|
|
|
return 'red'; // Closed Issue
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isIssueSuggestionsLoaded() {
|
2025-06-07 19:21:15 +03:00
|
|
|
return Boolean(window.config.issueValues);
|
2025-06-07 18:21:41 +03:00
|
|
|
}
|
|
|
|
|
2025-06-07 19:17:00 +03:00
|
|
|
export async function fetchIssueSuggestions() {
|
2025-06-07 18:21:41 +03:00
|
|
|
const issuePathInfo = parseIssueHref(window.location.href);
|
|
|
|
if (!issuePathInfo.ownerName) {
|
|
|
|
const repoOwnerPathInfo = parseRepoOwnerPathInfo(window.location.pathname);
|
|
|
|
issuePathInfo.ownerName = repoOwnerPathInfo.ownerName;
|
|
|
|
issuePathInfo.repoName = repoOwnerPathInfo.repoName;
|
|
|
|
// then no issuePathInfo.indexString here, it is only used to exclude the current issue when "matchIssue"
|
|
|
|
}
|
|
|
|
|
|
|
|
const res = await GET(`${window.config.appSubUrl}/${issuePathInfo.ownerName}/${issuePathInfo.repoName}/issues/suggestions`);
|
|
|
|
const issues = await res.json();
|
|
|
|
window.config.issueValues = issues;
|
2025-06-07 19:21:15 +03:00
|
|
|
}
|