Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spicy-webs-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"commitcrawler": patch
---

우클릭 기반의 동작 기능 추가
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "CommitExtractor",
"version": "1.0.3",
"description": "A tool for extracting commit messages and generating PR templates with custom regex patterns.",
"permissions": ["debugger", "tabs", "storage"],
"permissions": ["debugger", "tabs", "storage", "contextMenus"],
"host_permissions": [
"https://*.gitlab.com/*",
"https://*.gabia.io/*",
Expand Down
13 changes: 8 additions & 5 deletions src/commitInterceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ import {
import { GitlabCommitParser } from "./services/git/parser/GitlabCommitParser";
import { CommitMessageFormatter } from "./services/git/parser/CommitMessageFormatter";
import { GIT_SERVICE_INFO } from "./services/git/types";
import { initializeContextMenu } from "./contextMenuHandler";

const debuggerService = new DebuggerService();
const commitInterceptorService = new CommitInterceptorService(
new TaskExecutionController(),
debuggerService
);

initializeContextMenu();

chrome.runtime.onMessage.addListener(
(message: MessagePayload<{ targetTabId: number }>, sender, sendResponse) => {
if (message.action === "START_INTERCEPTOR_COMMIT") {
const targetTabId = message.data?.targetTabId;
if (!targetTabId) {
console.error("Target tab ID missing for START_INTERCEPTOR_COMMIT");
sendResponse({ status: "error", message: "탭 ID가 없습니다." });
return true;
}
Expand All @@ -32,7 +36,6 @@ chrome.runtime.onMessage.addListener(
}
);

// 네트워크 응답 처리
chrome.debugger.onEvent.addListener((source, method, params) => {
if (method === "Network.responseReceived") {
handleNetworkResponse(source, params);
Expand All @@ -42,10 +45,6 @@ chrome.debugger.onEvent.addListener((source, method, params) => {
async function handleNetworkResponse(source, params) {
if (!commitInterceptorService.isTaskExecutionActive()) return;

// FIXME 의존성 분리 필요(이유는 모르겠으나 에러도 안찍힘)
// const siteInfo = getGitInfo();
// const { parser } = siteInfo;

if (params.response.url.includes(GIT_SERVICE_INFO.gitlab.apiEndpoint)) {
try {
const response = await debuggerService.getResponseBody(
Expand All @@ -69,14 +68,18 @@ async function handleNetworkResponse(source, params) {
"INTERCEPTOR_COMMIT_FAILED",
"커밋 데이터 파싱 실패"
);
commitInterceptorService.detachDebugger(source.tabId);
}
} else {
console.warn("Response body was empty for request:", params.requestId);
}
} catch (error) {
console.error("Response body error:", error);
MessageDispatcher.sendError(
"INTERCEPTOR_COMMIT_FAILED",
"응답 데이터 가져오기 실패"
);
commitInterceptorService.detachDebugger(source.tabId);
}
}
}
51 changes: 51 additions & 0 deletions src/contextMenuHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const CONTEXT_MENU_ID = "openCommitExtractorPopup";

function createContextMenu() {
chrome.contextMenus.create({
id: CONTEXT_MENU_ID,
title: "CommitExtractor 열기",
contexts: ["page"],
});
}

function handleContextMenuClick(
info: chrome.contextMenus.OnClickData,
tab?: chrome.tabs.Tab
) {
if (info.menuItemId === CONTEXT_MENU_ID) {
const originalTabId = tab?.id;
const originalUrl = tab?.url;

if (!originalTabId || !originalUrl) {
console.error(
"Could not get the original tab ID or URL for context menu action."
);
return;
}

const encodedUrl = encodeURIComponent(originalUrl);
const popupUrl = chrome.runtime.getURL(
`base.html?originalTabId=${originalTabId}&originalUrl=${encodedUrl}`
);

const windowWidth = 800;
const windowHeight = 600;

chrome.windows.create({
url: popupUrl,
type: "popup",
width: windowWidth,
height: windowHeight,
});
}
}

export function initializeContextMenu(): void {
chrome.contextMenus.removeAll(() => {
createContextMenu();
});

chrome.runtime.onInstalled.addListener(createContextMenu);

chrome.contextMenus.onClicked.addListener(handleContextMenuClick);
}
Loading
Loading