### Install and Run ohmyzsh-bot (Shell) Source: https://github.com/ohmyzsh/ohmyzsh-bot/blob/main/README.md This snippet outlines the steps to install dependencies, build the TypeScript code, and start the ohmyzsh-bot using npm commands. It assumes a Node.js environment with npm installed. ```shell # Install dependencies npm install # Run typescript npm run build # Run the bot npm start ``` -------------------------------- ### Install Dependencies and Run Tests (npm) Source: https://github.com/ohmyzsh/ohmyzsh-bot/blob/main/CONTRIBUTING.md This snippet shows how to install project dependencies and run tests using npm. The tests also include linting, so separate linting is not required. Ensure all tests pass before submitting changes. ```shell npm install npm test ``` -------------------------------- ### Install and Run Bot - Bash Source: https://context7.com/ohmyzsh/ohmyzsh-bot/llms.txt Provides essential bash commands for managing the Oh My Zsh bot project. This includes installing dependencies, building the TypeScript code, starting the bot, running tests, and enabling development mode with auto-reloading. ```bash # Install dependencies npm install # Build TypeScript npm run build # Start the bot npm start # Run tests npm test # Development mode with auto-reload npm run dev ``` -------------------------------- ### Test Pull Request Reviewer Assignment - TypeScript Source: https://context7.com/ohmyzsh/ohmyzsh-bot/llms.txt Demonstrates how to test the reviewer assignment functionality using Probot's testing utilities and nock for HTTP mocking. This example simulates a pull request opening event, mocks API responses for listing files and fetching CODEOWNERS, and verifies that the correct reviewer is mentioned in a comment. ```typescript import assignPullRequestReviewers from '../src/actions/assign' import { Probot, ProbotOctokit } from 'probot' import nock from 'nock' nock.disableNetConnect() describe('assign PR reviewers', () => { test('correctly mentions reviewers when a pull request is opened', async () => { const probot = new Probot({ appId: 1, githubToken: 'test', Octokit: ProbotOctokit.defaults({ retry: { enabled: false }, throttle: { enabled: false } }) }) probot.load((app) => { app.on('pull_request.opened', assignPullRequestReviewers) }) const githubScope = nock('https://api.github.com') // Mock PR listFiles endpoint githubScope .get('/repos/owner/repo/pulls/13/files') .reply(200, [{ filename: 'plugins/gitfast/update' }]) // Mock CODEOWNERS file githubScope .get('/repos/owner/repo/contents/.github%2FCODEOWNERS') .reply(200, { content: Buffer.from('plugins/gitfast/ @felipec').toString('base64') }) // Mock createComment - verify @felipec is mentioned githubScope .post('/repos/owner/repo/issues/13/comments', (body: any) => { expect(body.body).toMatch(/@felipec/) return true }) .reply(200) // Simulate webhook event await probot.receive({ id: 'event-id', name: 'pull_request', payload: pullRequestOpenedEvent }) expect(githubScope.isDone()).toBe(true) }) }) ``` -------------------------------- ### Create and Checkout Git Branch Source: https://github.com/ohmyzsh/ohmyzsh-bot/blob/main/CONTRIBUTING.md This snippet demonstrates how to create a new branch for your changes and then check it out. This is a standard Git workflow for isolating development efforts. ```shell git checkout -b my-branch-name ``` -------------------------------- ### GitHub App Configuration - YAML Source: https://context7.com/ohmyzsh/ohmyzsh-bot/llms.txt Defines the configuration for the Oh My Zsh bot as a GitHub App. This YAML file specifies the events the bot subscribes to, its default permissions for issues and pull requests, and the bot's name and public visibility. ```yaml # app.yml - GitHub App configuration default_events: - issues - pull_request default_permissions: issues: write metadata: read pull_requests: write name: Oh My Zsh bot public: false ``` -------------------------------- ### Probot Application Entry Point (TypeScript) Source: https://context7.com/ohmyzsh/ohmyzsh-bot/llms.txt The main Probot application function that registers event handlers for pull request events. It binds the triage and reviewer assignment actions to specific GitHub webhook events. ```typescript import { Probot } from 'probot' import triagePullRequest from './actions/triage' import assignPullRequestReviewers from './actions/assign' const probotApp = (app: Probot) => { // Triage PRs when opened or updated (synchronized) app.on(['pull_request.opened', 'pull_request.synchronize'], triagePullRequest) // Assign reviewers only when PR is initially opened app.on('pull_request.opened', assignPullRequestReviewers) } export default probotApp ``` -------------------------------- ### Automatic Pull Request Label Assignment (TypeScript) Source: https://context7.com/ohmyzsh/ohmyzsh-bot/llms.txt Analyzes modified files in a pull request to automatically apply relevant labels based on file paths and content. It preserves existing labels not managed by the bot and handles specific cases like documentation labels. ```typescript import { Context } from 'probot' import LABELS from './labels.json' export default async function triagePullRequest(context: Context<'pull_request'>): Promise { const PRNumber = context.payload.number const oldLabels: string[] = context.payload.pull_request.labels.map( (label: { name: string }) => label.name ) // Get new labels based on file analysis let newLabels = await labelsOfPR(context) // Preserve labels not managed by the bot newLabels = newLabels.concat( oldLabels.filter(label => !Object.values(LABELS).includes(label)) ) // Keep documentation label if manually applied if (oldLabels.includes(LABELS.DOCUMENTATION) && !newLabels.includes(LABELS.DOCUMENTATION)) { newLabels.push(LABELS.DOCUMENTATION) } // Only update if labels changed if (different(oldLabels, newLabels)) { const params = context.repo({ issue_number: PRNumber, labels: newLabels }) await context.octokit.issues.setLabels(params) } } // Available labels applied by the bot: // { // "CORE": "Area: core", // "INIT": "Area: init", // "INSTALL": "Area: installer", // "UPDATE": "Area: updater", // "PLUGIN": "Area: plugin", // "THEME": "Area: theme", // "UNINSTALL": "Area: uninstaller", // "NEW_PLUGIN": "New: plugin", // "NEW_THEME": "New: theme", // "ALIAS": "Topic: alias", // "BINDKEY": "Topic: bindkey", // "COMPLETION": "Topic: completion", // "CONFLICTS": "Status: conflicts", // "DOCUMENTATION": "Type: documentation" // } ``` -------------------------------- ### Parse CODEOWNERS File - TypeScript Source: https://context7.com/ohmyzsh/ohmyzsh-bot/llms.txt Parses a CODEOWNERS file to extract path-to-username mappings. It ignores comments and only considers owners in the '@username' format. The function takes the CODEOWNERS file content as a string and returns an array of CodeOwner objects. ```typescript interface CodeOwner { path: string username: string } function parseCodeOwners(codeOwnersFile: string): CodeOwner[] { const codeOwners: CodeOwner[] = [] for (const line of codeOwnersFile.split('\n')) { // Ignore empty lines and comments if (line.length === 0 || line.startsWith('#')) { continue } const [path, owner] = line.split(/\s+/) // Only accept @username format if (!owner?.startsWith('@')) { continue } codeOwners.push({ path: path, username: owner.slice(1) // Remove '@' prefix }) } return codeOwners } // Usage example: const codeOwnersContent = ` # Plugin owners plugins/gitfast/ @felipec plugins/sdk/ @rgoldberg ` const owners = parseCodeOwners(codeOwnersContent) // Result: [ // { path: 'plugins/gitfast/', username: 'felipec' }, // { path: 'plugins/sdk/', username: 'rgoldberg' } // ] ``` -------------------------------- ### Code Owner Notification for Pull Requests (TypeScript) Source: https://context7.com/ohmyzsh/ohmyzsh-bot/llms.txt Identifies code owners for modified files by parsing the CODEOWNERS file and creates a comment mentioning them. The PR author is automatically excluded from the reviewers list. ```typescript import { Context } from 'probot' export default async function assignPullRequestReviewers(context: Context<'pull_request'>) { const PRnumber = context.payload.number const owner = context.payload.repository.owner.login const repo = context.payload.repository.name // Get list of reviewers based on modified files and CODEOWNERS let reviewers = await reviewersOfPR(context, PRnumber, owner, repo) // Remove the PR author from reviewers const author = context.payload.pull_request.user.login reviewers = reviewers.filter(reviewer => reviewer !== author) // If no reviewers, do nothing if (reviewers.length === 0) return // Create comment mentioning the reviewers const reviewersText = reviewers.map(reviewer => '@' + reviewer).join(', ') const body = `Bleep bloop. I determined that these users own the modified files: ${reviewersText}.` await context.octokit.issues.createComment({ owner, repo, issue_number: PRnumber, body }) } // Example CODEOWNERS file format: // # Plugin owners // plugins/gitfast/ @felipec // plugins/sdk/ @rgoldberg ``` -------------------------------- ### Array Comparison Utility - TypeScript Source: https://context7.com/ohmyzsh/ohmyzsh-bot/llms.txt Compares two string arrays to determine if they contain different elements, irrespective of their order. This utility is useful for preventing redundant API calls by checking if labels have changed. It returns true if the arrays differ in content or length, and false otherwise. ```typescript export function different(A: string[], B: string[]): boolean { if (A.length !== B.length) return true A.sort() B.sort() for (let i = 0; i < A.length; i++) { if (A[i] !== B[i]) return true } return false } // Usage examples: different(['a', 'b'], ['b', 'a']) // false - same elements different(['a', 'b'], ['a', 'c']) // true - different elements different(['a'], ['a', 'b']) // true - different lengths ``` -------------------------------- ### Extract Filenames from GitHub API Response - TypeScript Source: https://context7.com/ohmyzsh/ohmyzsh-bot/llms.txt Parses the response from the GitHub API's pulls.listFiles endpoint to extract an array of modified file paths. It iterates through the provided file response data and collects the 'filename' property for each file. ```typescript import { GetResponseDataTypeFromEndpointMethod } from '@octokit/types' type PullsListFilesResponseData = GetResponseDataTypeFromEndpointMethod< Context['octokit']['pulls']['listFiles'] > function parseModifiedFiles(filesResponse: PullsListFilesResponseData): string[] { const modifiedFiles: string[] = [] for (const file of filesResponse) { modifiedFiles.push(file.filename) } return modifiedFiles } // Usage with GitHub API response: const apiResponse = [ { sha: '992f26d5c2a5574cdf4753c6a8859eb97ebbd335', filename: 'plugins/laravel/laravel.plugin.zsh', status: 'modified', additions: 1, deletions: 0, changes: 1, patch: '@@ -1,6 +1,7 @@\n alias artisan="php artisan"\n+alias tinker="php artisan tinker"' } ] const files = parseModifiedFiles(apiResponse) // Result: ['plugins/laravel/laravel.plugin.zsh'] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.