- 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
Feature/more enhancers #34
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 5 commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      f38d51c
              
                Biome format config files too.
              
              
                WebsByTodd f6dfe03
              
                Add Issue New
              
              
                WebsByTodd 597f6e5
              
                PR new
              
              
                WebsByTodd 97948e7
              
                tests
              
              
                WebsByTodd cd0031a
              
                Fix test output.
              
              
                WebsByTodd e68c744
              
                Update browser-extension/src/lib/logger.ts
              
              
                nedtwigg 8fcf594
              
                Merge branch 'main' into feature/more-enhancers
              
              
                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
  
    
      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
    
  
  
    
              
        
          
          
            67 changes: 67 additions & 0 deletions
          
          67 
        
  browser-extension/src/lib/enhancers/github/githubIssueNewComment.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,67 @@ | ||
| import OverType, { type OverTypeInstance } from 'overtype' | ||
| import type { CommentEnhancer, CommentSpot } from '../../enhancer' | ||
| import { logger } from '../../logger' | ||
| import { modifyDOM } from '../modifyDOM' | ||
| import { githubHighlighter } from './githubHighlighter' | ||
|  | ||
| interface GitHubIssueNewCommentSpot extends CommentSpot { | ||
| type: 'GH_ISSUE_NEW_COMMENT' | ||
| domain: string | ||
| slug: string // owner/repo | ||
| } | ||
|  | ||
| export class GitHubIssueNewCommentEnhancer implements CommentEnhancer<GitHubIssueNewCommentSpot> { | ||
| forSpotTypes(): string[] { | ||
| return ['GH_ISSUE_NEW_COMMENT'] | ||
| } | ||
|  | ||
| tryToEnhance(_textarea: HTMLTextAreaElement): GitHubIssueNewCommentSpot | null { | ||
| if (document.querySelector('meta[name="hostname"]')?.getAttribute('content') !== 'github.com') { | ||
| 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\/new)/) | ||
| logger.debug(`${this.constructor.name} found match`, window.location.pathname) | ||
|  | ||
| if (!match) return null | ||
| const [, owner, repo] = match | ||
| const slug = `${owner}/${repo}` | ||
| const unique_key = `github.com:${slug}:new` | ||
| return { | ||
| domain: 'github.com', | ||
| slug, | ||
| type: 'GH_ISSUE_NEW_COMMENT', | ||
| unique_key, | ||
| } | ||
| } | ||
|  | ||
| prepareForFirstEnhancement(): void { | ||
| OverType.setCodeHighlighter(githubHighlighter) | ||
| } | ||
|  | ||
| enhance(textArea: HTMLTextAreaElement, _spot: GitHubIssueNewCommentSpot): OverTypeInstance { | ||
| const overtypeContainer = modifyDOM(textArea) | ||
| return new OverType(overtypeContainer, { | ||
| autoResize: true, | ||
| minHeight: '400px', | ||
| padding: 'var(--base-size-16)', | ||
| placeholder: 'Type your description here...', | ||
| })[0]! | ||
| } | ||
|  | ||
| tableTitle(spot: GitHubIssueNewCommentSpot): string { | ||
| const { slug } = spot | ||
| return `${slug} New Issue` | ||
| } | ||
|  | ||
| tableIcon(_: GitHubIssueNewCommentSpot): string { | ||
| return '🔄' // PR icon TODO: icon urls in /public | ||
| } | ||
|  | ||
| buildUrl(spot: GitHubIssueNewCommentSpot): string { | ||
| return `https://${spot.domain}/${spot.slug}/issue/new` | ||
| } | ||
| } | 
        
          
          
            72 changes: 72 additions & 0 deletions
          
          72 
        
  browser-extension/src/lib/enhancers/github/githubPRNewComment.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,72 @@ | ||
| import OverType, { type OverTypeInstance } from 'overtype' | ||
| import type { CommentEnhancer, CommentSpot } from '../../enhancer' | ||
| import { logger } from '../../logger' | ||
| import { modifyDOM } from '../modifyDOM' | ||
| import { githubHighlighter } from './githubHighlighter' | ||
|  | ||
| interface GitHubPRNewCommentSpot extends CommentSpot { | ||
| type: 'GH_PR_NEW_COMMENT' | ||
| domain: string | ||
| slug: string // owner/repo/base-branch/compare-branch | ||
| } | ||
|  | ||
| export class GitHubPRNewCommentEnhancer implements CommentEnhancer<GitHubPRNewCommentSpot> { | ||
| forSpotTypes(): string[] { | ||
| return ['GH_PR_NEW_COMMENT'] | ||
| } | ||
|  | ||
| tryToEnhance(_textarea: HTMLTextAreaElement): GitHubPRNewCommentSpot | null { | ||
| if (document.querySelector('meta[name="hostname"]')?.getAttribute('content') !== 'github.com') { | ||
| return null | ||
| } | ||
|  | ||
| // /owner/repo/compare/feature/more-enhancers?expand=1 | ||
| // or /owner/repo/compare/feat/issue-static-and-dynamic...feature/more-enhancers?expand=1 | ||
| logger.info(`${this.constructor.name} examing url`, window.location.pathname) | ||
|  | ||
| const match = window.location.pathname.match( | ||
| /^\/([^/]+)\/([^/]+)\/compare\/(?:([^.?]+)\.\.\.)?([^?]+)/, | ||
| ) | ||
| logger.info(`${this.constructor.name} found match`, window.location.pathname, match) | ||
|  | ||
| if (!match) return null | ||
| const [, owner, repo, baseBranch, compareBranch] = match | ||
| const slug = baseBranch | ||
| ? `${owner}/${repo}/${baseBranch}...${compareBranch}` | ||
| : `${owner}/${repo}/${compareBranch}` | ||
| const unique_key = `github.com:${slug}` | ||
| return { | ||
| domain: 'github.com', | ||
| slug, | ||
| type: 'GH_PR_NEW_COMMENT', | ||
| unique_key, | ||
| } | ||
| } | ||
|  | ||
| prepareForFirstEnhancement(): void { | ||
| OverType.setCodeHighlighter(githubHighlighter) | ||
| } | ||
|  | ||
| enhance(textArea: HTMLTextAreaElement, _spot: GitHubPRNewCommentSpot): OverTypeInstance { | ||
| const overtypeContainer = modifyDOM(textArea) | ||
| return new OverType(overtypeContainer, { | ||
| autoResize: true, | ||
| minHeight: '250px', | ||
| padding: 'var(--base-size-16)', | ||
| placeholder: 'Type your description here...', | ||
| })[0]! | ||
| } | ||
|  | ||
| tableTitle(spot: GitHubPRNewCommentSpot): string { | ||
| const { slug } = spot | ||
| return `${slug} New Issue` | ||
| } | ||
|  | ||
| tableIcon(_: GitHubPRNewCommentSpot): string { | ||
| return '🔄' // PR icon TODO: icon urls in /public | ||
| } | ||
|  | ||
| buildUrl(spot: GitHubPRNewCommentSpot): string { | ||
| return `https://${spot.domain}/${spot.slug}/issue/new` | ||
| } | ||
| } | 
  
    
      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
    
  
  
    
              
  
    
      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.