@@ -36,85 +36,73 @@ export class GitHubHandler implements TextareaHandler<GitHubContext> {
3636 return null ;
3737 }
3838
39- const type = this . determineType ( textarea ) ;
40- const context = this . extractContext ( textarea ) ;
41-
42- if ( type && context ) {
43- return { element : textarea , context : { ...context , type } } ;
44- }
45-
46- return null ;
47- }
48-
49-
50- private extractContext ( textarea : HTMLTextAreaElement ) : GitHubContext | null {
5139 const pathname = window . location . pathname ;
5240
5341 // Parse GitHub URL structure: /owner/repo/issues/123 or /owner/repo/pull/456
5442 const match = pathname . match ( / ^ \/ ( [ ^ \/ ] + ) \/ ( [ ^ \/ ] + ) (?: \/ ( i s s u e s | p u l l ) \/ ( \d + ) ) ? / ) ;
5543 if ( ! match ) return null ;
5644
57- const [ , owner , repo , type , numberStr ] = match ;
45+ const [ , owner , repo , urlType , numberStr ] = match ;
5846 const slug = `${ owner } /${ repo } ` ;
5947 const number = numberStr ? parseInt ( numberStr , 10 ) : undefined ;
6048
49+ // Check if editing existing comment
50+ const commentId = this . getCommentId ( textarea ) ;
51+
52+ // Determine comment type
53+ let type : GitHubCommentType ;
54+
55+ // New issue
56+ if ( pathname . includes ( '/issues/new' ) ) {
57+ type = 'GH_ISSUE_NEW' ;
58+ }
59+ // New PR
60+ else if ( pathname . includes ( '/compare/' ) || pathname . endsWith ( '/compare' ) ) {
61+ type = 'GH_PR_NEW' ;
62+ }
63+ // Existing issue or PR page
64+ else if ( urlType && number ) {
65+ const isEditingComment = commentId !== null ;
66+
67+ if ( urlType === 'issues' ) {
68+ type = isEditingComment ? 'GH_ISSUE_EDIT_COMMENT' : 'GH_ISSUE_ADD_COMMENT' ;
69+ } else {
70+ // Check if it's a code comment (in Files Changed tab)
71+ const isCodeComment = textarea . closest ( '.js-inline-comment-form' ) !== null ||
72+ textarea . closest ( '[data-path]' ) !== null ;
73+
74+ if ( isCodeComment ) {
75+ type = 'GH_PR_CODE_COMMENT' ;
76+ } else {
77+ type = isEditingComment ? 'GH_PR_EDIT_COMMENT' : 'GH_PR_ADD_COMMENT' ;
78+ }
79+ }
80+ } else {
81+ return null ;
82+ }
83+
6184 // Generate unique key based on context
6285 let unique_key = `github:${ slug } ` ;
6386 if ( number ) {
64- unique_key += `:${ type } :${ number } ` ;
87+ unique_key += `:${ urlType } :${ number } ` ;
6588 } else {
6689 unique_key += ':new' ;
6790 }
68-
69- // Check if editing existing comment
70- const commentId = this . getCommentId ( textarea ) ;
91+
7192 if ( commentId ) {
7293 unique_key += `:edit:${ commentId } ` ;
7394 }
7495
75- return {
96+ const context : GitHubContext = {
7697 unique_key,
77- type : '' , // Will be set by caller
98+ type,
7899 domain : window . location . hostname ,
79100 slug,
80101 number,
81102 commentId : commentId || undefined
82103 } ;
83- }
84104
85- private determineType ( textarea : HTMLTextAreaElement ) : GitHubCommentType | null {
86- const pathname = window . location . pathname ;
87-
88- // New issue
89- if ( pathname . includes ( '/issues/new' ) ) {
90- return 'GH_ISSUE_NEW' ;
91- }
92-
93- // New PR
94- if ( pathname . includes ( '/compare/' ) || pathname . endsWith ( '/compare' ) ) {
95- return 'GH_PR_NEW' ;
96- }
97-
98- // Check if we're on an issue or PR page
99- const match = pathname . match ( / \/ ( i s s u e s | p u l l ) \/ ( \d + ) / ) ;
100- if ( ! match ) return null ;
101-
102- const [ , type ] = match ;
103- const isEditingComment = this . getCommentId ( textarea ) !== null ;
104-
105- if ( type === 'issues' ) {
106- return isEditingComment ? 'GH_ISSUE_EDIT_COMMENT' : 'GH_ISSUE_ADD_COMMENT' ;
107- } else {
108- // Check if it's a code comment (in Files Changed tab)
109- const isCodeComment = textarea . closest ( '.js-inline-comment-form' ) !== null ||
110- textarea . closest ( '[data-path]' ) !== null ;
111-
112- if ( isCodeComment ) {
113- return 'GH_PR_CODE_COMMENT' ;
114- }
115-
116- return isEditingComment ? 'GH_PR_EDIT_COMMENT' : 'GH_PR_ADD_COMMENT' ;
117- }
105+ return { element : textarea , context } ;
118106 }
119107
120108 generateDisplayTitle ( context : GitHubContext ) : string {
0 commit comments