- 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
GitHub issue add-comment #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      1224ba4
              
                Add github-issue add-comment enhancer.
              
              
                WebsByTodd 1582d5f
              
                Only enhance textareas with the correct id.
              
              
                WebsByTodd da7985b
              
                reduce `styles.js` diff
              
              
                nedtwigg 969c5fc
              
                more diff minimization
              
              
                nedtwigg e48c94e
              
                more diff minimization
              
              
                nedtwigg 50daae0
              
                more diff minimization
              
              
                nedtwigg File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            69 changes: 69 additions & 0 deletions
          
          69 
        
  browser-extension/src/lib/enhancers/github/githubIssueAddComment.ts
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import OverType, { type OverTypeInstance } from '../../../overtype/overtype' | ||
| import type { CommentEnhancer, CommentSpot } from '../../enhancer' | ||
| import { logger } from '../../logger' | ||
| import { modifyDOM } from '../modifyDOM' | ||
| import { githubHighlighter } from './githubHighlighter' | ||
|  | ||
| interface GitHubIssueAddCommentSpot extends CommentSpot { | ||
| type: 'GH_ISSUE_ADD_COMMENT' | ||
| domain: string | ||
| slug: string // owner/repo | ||
| number: number // issue number, undefined for new issues | ||
| } | ||
|  | ||
| export class GitHubIssueAddCommentEnhancer implements CommentEnhancer<GitHubIssueAddCommentSpot> { | ||
| forSpotTypes(): string[] { | ||
| return ['GH_ISSUE_ADD_COMMENT'] | ||
| } | ||
|  | ||
| tryToEnhance(_textarea: HTMLTextAreaElement): GitHubIssueAddCommentSpot | null { | ||
| if (window.location.hostname !== 'github.com' || _textarea.id !== ':r2v:') { | ||
| return null | ||
| } | ||
|  | ||
| // Parse GitHub URL structure: /owner/repo/issues/123 or /owner/repo/pull/456 | ||
| logger.debug(`${this.constructor.name} examing url`, window.location.pathname) | ||
|  | ||
| const match = window.location.pathname.match(/^\/([^/]+)\/([^/]+)(?:\/issues\/(\d+))/) | ||
| logger.debug(`${this.constructor.name} found match`, window.location.pathname) | ||
| if (!match) return null | ||
| const [, owner, repo, numberStr] = match | ||
| const slug = `${owner}/${repo}` | ||
| const number = parseInt(numberStr!, 10) | ||
| const unique_key = `github.com:${slug}:${number}` | ||
| return { | ||
| domain: 'github.com', | ||
| number, | ||
| slug, | ||
| type: 'GH_ISSUE_ADD_COMMENT', | ||
| unique_key, | ||
| } | ||
| } | ||
|  | ||
| prepareForFirstEnhancement(): void { | ||
| OverType.setCodeHighlighter(githubHighlighter) | ||
| } | ||
|  | ||
| enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueAddCommentSpot): OverTypeInstance { | ||
| const overtypeContainer = modifyDOM(textArea) | ||
| return new OverType(overtypeContainer, { | ||
| autoResize: true, | ||
| minHeight: '100px', | ||
| padding: 'var(--base-size-16)', | ||
| placeholder: 'Use Markdown to format your comment', | ||
| })[0]! | ||
| } | ||
|  | ||
| tableTitle(spot: GitHubIssueAddCommentSpot): string { | ||
| const { slug, number } = spot | ||
| return `${slug} Issue #${number}` | ||
| } | ||
|  | ||
| tableIcon(_: GitHubIssueAddCommentSpot): string { | ||
| return '🔄' // PR icon TODO: icon urls in /public | ||
| } | ||
|  | ||
| buildUrl(spot: GitHubIssueAddCommentSpot): string { | ||
| return `https://${spot.domain}/${spot.slug}/issue/${spot.number}` | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Modify the DOM to trick overtype into adopting it instead of recreating it | ||
| export function modifyDOM(overtypeInput: HTMLTextAreaElement): HTMLElement { | ||
| overtypeInput.classList.add('overtype-input') | ||
| const overtypePreview = document.createElement('div') | ||
| overtypePreview.classList.add('overtype-preview') | ||
| overtypeInput.insertAdjacentElement('afterend', overtypePreview) | ||
| const overtypeWrapper = overtypeInput.parentElement!.closest('div')! | ||
| overtypeWrapper.classList.add('overtype-wrapper') | ||
| overtypeInput.placeholder = 'Add your comment here...' | ||
| const overtypeContainer = overtypeWrapper.parentElement!.closest('div')! | ||
| overtypeContainer.classList.add('overtype-container') | ||
| return overtypeContainer.parentElement!.closest('div')! | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.