### Initialize Gin Web Server in Go Source: https://github.com/jfrog/frogbot/blob/main/testdata/indirect-projects/go/main.go.txt This snippet shows the basic setup for a Go web server using the Gin framework. Ensure Gin is installed in your Go environment. ```go package main import ( "github.com/gin-gonic/gin" ) func main() { print("test") _ = gin.Default() } ``` -------------------------------- ### Use Token for Git Operations Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/auth-token/README.md Demonstrates how to use both OAuth and installation access tokens for git operations, including prefixing installation tokens with 'x-access-token'. This example uses the 'execa' package. ```javascript const TOKEN = "ghp_PersonalAccessToken01245678900000000"; const auth = createTokenAuth(TOKEN); const { token, tokenType } = await auth(); const tokenWithPrefix = tokenType === "installation" ? `x-access-token:${token}` : token; const repositoryUrl = `https://${tokenWithPrefix}@github.com/octocat/hello-world.git`; const { stdout } = await execa("git", ["push", repositoryUrl]); console.log(stdout); ``` -------------------------------- ### Install @actions/http-client Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@actions/http-client/README.md Install the package using npm. ```bash npm install @actions/http-client --save ``` -------------------------------- ### Check Go Installation Source: https://github.com/jfrog/frogbot/blob/main/CONTRIBUTING.md Verify that Go is installed on your system before proceeding with the build process. ```bash go version ``` -------------------------------- ### REST API Example with @octokit/request Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/request/README.md Demonstrates how to make a GET request to the GitHub REST API to fetch user information. Requires importing the request function. ```javascript import { request } from "@octokit/request"; const { data } = await request("GET /users/{username}", { username: "octokit" }); ``` -------------------------------- ### Install before-after-hook with npm Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/before-after-hook/README.md Install the before-after-hook package using npm. ```bash npm install before-after-hook ``` -------------------------------- ### Install and Import in Node.js Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/auth-token/README.md Install the @octokit/auth-token package using npm and import the createTokenAuth function. ```js const { createTokenAuth } = require("@octokit/auth-token"); // or: import { createTokenAuth } from "@octokit/auth-token"; ``` -------------------------------- ### Generate documentation Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/is-plain-object/README.md Install global dependencies and run the documentation generation command. ```sh $ npm install -g verbose/verb#dev verb-generate-readme && verb ``` -------------------------------- ### GraphQL Example Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/request/README.md Example of how to make a request to the GitHub GraphQL API using the @octokit/request library. ```APIDOC ## GraphQL Example ### Description Send a POST request to the GraphQL endpoint to query for the authenticated user's login. ### Method POST ### Endpoint /graphql ### Parameters #### Request Body - **query** (string) - Required - The GraphQL query string. - **variables** (Object) - Optional - Variables to use with the GraphQL query. ### Request Example ```javascript import { request } from "@octokit/request"; async function getLogin() { const response = await request("POST /graphql", { headers: { authorization: `token YOUR-GITHUB-TOKEN` }, body: { query: "query { viewer { login } }" } }); console.log(response.data.viewer.login); } getLogin(); ``` ### Response #### Success Response (200) - **data** (Object) - The result of the GraphQL query. #### Response Example ```json { "data": { "viewer": { "login": "octocat" } } } ``` ``` -------------------------------- ### MockAgent: Basic Mocked Request with Global Dispatcher Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/undici/docs/api/MockAgent.md This example shows how to set up a basic mocked request using MockAgent. It involves getting a mock pool for a specific origin, intercepting a path, and replying with a status code and body. The MockAgent is then set as the global dispatcher. ```javascript import { MockAgent, setGlobalDispatcher, request } from 'undici' const mockAgent = new MockAgent() setGlobalDispatcher(mockAgent) const mockPool = mockAgent.get('http://localhost:3000') mockPool.intercept({ path: '/foo' }).reply(200, 'foo') const { statusCode, body } = await request('http://localhost:3000/foo') console.log('response received', statusCode) // response received 200 for await (const data of body) { console.log('data', data.toString('utf8')) // data foo } ``` -------------------------------- ### Basic Pagination Example Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/plugin-paginate-rest/README.md Instantiate Octokit with the plugin and use the `paginate` method to fetch all issues for a repository. ```javascript const MyOctokit = Octokit.plugin(paginateRest); const octokit = new MyOctokit({ auth: "secret123" }); // See https://developer.github.com/v3/issues/#list-issues-for-a-repository const issues = await octokit.paginate("GET /repos/{owner}/{repo}/issues", { owner: "octocat", repo: "hello-world", since: "2010-10-01", per_page: 100, }); ``` -------------------------------- ### Install Dependencies Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@actions/http-client/README.md Install project dependencies using npm. ```bash npm install ``` -------------------------------- ### Create Token Auth with User-to-Server Installation Token Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/auth-token/README.md Use createTokenAuth with a user authentication for installation token (user-to-server). ```js // Installation access token or GitHub Action token createTokenAuth("ghu_InstallationUserToServer000000000000"); // { // type: 'token', // token: 'ghu_InstallationUserToServer000000000000', // tokenType: 'user-to-server' // } ``` -------------------------------- ### TypeScript Usage Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/graphql/README.md Example of using @octokit/graphql with TypeScript. Ensure you have the necessary types installed. ```typescript import { graphql } from "@octokit/graphql"; async function run() { const query = ` { viewer { login } } `; const token = "YOUR_PERSONAL_ACCESS_TOKEN"; const { viewer } = await graphql<{ viewer: { login: string } }>(query, { headers: { authorization: `token ${token}` } }); console.log(`Hello, ${viewer.login}!`); } run(); ``` -------------------------------- ### Go Main Function Example Source: https://github.com/jfrog/frogbot/blob/main/testdata/projects/go/main.go.txt This is the entry point of a Go program. It includes imports for standard libraries and external packages. ```go package main import ( "fmt" "github.com/google/uuid" "github.com/sassoftware/go-rpmutils" ) func main() { fmt.Println("test") uuid.New() _, _ = rpmutils.ReadRpm(nil) } ``` -------------------------------- ### Run tests Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/is-plain-object/README.md Install dependencies and run the unit tests to verify the package's functionality. ```sh $ npm install && npm test ``` -------------------------------- ### Install and Import Octokit Core in Node.js Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/core/README.md Install @octokit/core using npm and import the Octokit class for use in Node.js environments. ```javascript const { Octokit } = require("@octokit/core"); // or: import { Octokit } from "@octokit/core"; ``` -------------------------------- ### Usage Example Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/plugin-rest-endpoint-methods/README.md Demonstrates how to load the plugin and use one of the generated REST API methods. ```APIDOC ## GET /user ### Description Retrieves the authenticated user's information. ### Method GET ### Endpoint /user ### Parameters This endpoint does not require any parameters. ### Request Example ```javascript // Assuming octokit is an instance of Octokit with the restEndpointMethods plugin loaded octokit.rest.users.getAuthenticated(); ``` ### Response #### Success Response (200) - **id** (integer) - The user's unique ID. - **login** (string) - The user's login name. - **name** (string) - The user's display name. #### Response Example ```json { "id": 1, "login": "octocat", "name": "The Octocat" } ``` ``` -------------------------------- ### Dispatch GET Request with Undici Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/undici/docs/api/Dispatcher.md This example demonstrates how to dispatch a GET request using the Undici Client. It includes setting custom headers and handling various events like connection, headers received, data chunks, and request completion. The server and client are closed upon successful completion. ```javascript import { createServer } from 'http' import { Client } from 'undici' import { once } from 'events' const server = createServer((request, response) => { response.end('Hello, World!') }).listen() await once(server, 'listening') const client = new Client(`http://localhost:${server.address().port}`) const data = [] client.dispatch({ path: '/', method: 'GET', headers: { 'x-foo': 'bar' } }, { onConnect: () => { console.log('Connected!') }, onError: (error) => { console.error(error) }, onHeaders: (statusCode, headers) => { console.log(`onHeaders | statusCode: ${statusCode} | headers: ${headers}`) }, onData: (chunk) => { console.log('onData: chunk received') data.push(chunk) }, onComplete: (trailers) => { console.log(`onComplete | trailers: ${trailers}`) const res = Buffer.concat(data).toString('utf8') console.log(`Data: ${res}`) client.close() server.close() } }) ``` -------------------------------- ### Install debug.js Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/debug/README.md Install the debug.js package using npm. ```bash $ npm install debug ``` -------------------------------- ### Install node-fetch Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/node-fetch/README.md Install the current stable release (2.x) of node-fetch using npm. ```sh npm install node-fetch ``` -------------------------------- ### Create Token Auth with Installation or GitHub Action Token Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/auth-token/README.md Use createTokenAuth with an installation access token or a GITHUB_TOKEN provided to GitHub Actions. ```js // Installation access token or GitHub Action token createTokenAuth("ghs_InstallallationOrActionToken00000000"); // { // type: 'token', // token: 'ghs_InstallallationOrActionToken00000000', // tokenType: 'installation' // } ``` -------------------------------- ### Example Review Content Source: https://github.com/jfrog/frogbot/blob/main/testdata/messages/reviewcomment/review_comment_fallback_standard.md This snippet shows sample review content that might be included in a comment. ```text some review content ``` -------------------------------- ### Install is-plain-object with npm Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/is-plain-object/README.md Install the package using npm for use in your project. ```sh $ npm install --save is-plain-object ``` -------------------------------- ### MockClient Request Example Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/undici/docs/api/MockClient.md Shows how to use MockClient to intercept a request and receive a mocked response. The example registers a mock response for '/foo' and then makes a request to that path, logging the status code and response body. ```javascript import { MockAgent } from 'undici' const mockAgent = new MockAgent({ connections: 1 }) const mockClient = mockAgent.get('http://localhost:3000') mockClient.intercept({ path: '/foo' }).reply(200, 'foo') const { statusCode, body } = await mockClient.request({ origin: 'http://localhost:3000', path: '/foo', method: 'GET' }) console.log('response received', statusCode) // response received 200 for await (const data of body) { console.log('data', data.toString('utf8')) // data foo } ``` -------------------------------- ### Install semver with npm Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/semver/README.md Install the semver package using npm. This is the first step to using it in your Node.js project. ```bash npm install semver ``` -------------------------------- ### Starting the Node.js HTTP Server Source: https://github.com/jfrog/frogbot/blob/main/testdata/scanpullrequest/expected_response_multi_dir.md Command to start the Node.js HTTP server defined in poc1-server.mjs. This is the first terminal command required to set up the demonstration. ```bash node poc1-server.mjs ``` -------------------------------- ### Node.js Usage with npm Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/plugin-paginate-rest/README.md Install and import the plugin and Octokit core using npm for Node.js environments. ```javascript const { Octokit } = require("@octokit/core"); const { paginateRest, composePaginateRest, } = require("@octokit/plugin-paginate-rest"); ``` -------------------------------- ### Installing and Importing @octokit/request in Node.js Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/request/README.md Instructions for installing the @octokit/request package via npm and importing the request function in Node.js environments. ```javascript const { request } = require("@octokit/request"); // or: import { request } from "@octokit/request"; ``` -------------------------------- ### Install and Import @octokit/graphql in Node.js Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/graphql/README.md Install the package using npm and import the graphql function. Supports both CommonJS and ES Module syntax. ```javascript const {graphql} = require("@octokit/graphql"); // or: import { graphql } from "@octokit/graphql"; ``` -------------------------------- ### MockAgent Request Example Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/undici/docs/api/MockAgent.md Shows how to use the MockAgent's `request` method directly to simulate an HTTP request and capture its response details. ```javascript import { MockAgent } from 'undici' const mockAgent = new MockAgent() const mockPool = mockAgent.get('http://localhost:3000') mockPool.intercept({ path: '/foo' }).reply(200, 'foo') const { statusCode, body } = await mockAgent.request({ origin: 'http://localhost:3000', path: '/foo', method: 'GET' }) console.log('response received', statusCode) // response received 200 for await (const data of body) { console.log('data', data.toString('utf8')) // data foo } ``` -------------------------------- ### GraphQL API Example Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/core/README.md Example of how to make a GraphQL API request using the octokit.graphql method. This method allows you to execute GraphQL queries. ```APIDOC ## octokit.graphql ### Description Make a request to the GitHub GraphQL API. ### Method `octokit.graphql(query, variables)` ### Parameters - **query** (string) - The GraphQL query string. - **variables** (object) - An object containing variables for the GraphQL query. - **login** (string) - Required - The organization login. ### Request Example ```javascript const octokit = new Octokit({ auth: `secret123` }); const response = await octokit.graphql( `query ($login: String!) { organization(login: $login) { repositories(privacy: PRIVATE) { totalCount } } }`, { login: "octokit" } ); ``` ### Response #### Success Response (200) - **data** (Object) - The result of the GraphQL query. #### Response Example ```json { "data": { "organization": { "repositories": { "totalCount": 100 } } } } ``` ``` -------------------------------- ### Type-Safe Webhook Payload Handling Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@actions/github/README.md Provides an example of how to use TypeScript type definitions from '@octokit/webhooks-definitions' to safely access webhook payload data. Install the package first using 'npm install @octokit/webhooks-definitions'. ```ts import * as core from '@actions/core' import * as github from '@actions/github' import {PushEvent} from '@octokit/webhooks-definitions/schema' if (github.context.eventName === 'push') { const pushPayload = github.context.payload as PushEvent core.info(`The head commit is: ${pushPayload.head_commit}`) } ``` -------------------------------- ### Get OAuth Token Scopes Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/auth-token/README.md Retrieve and display the scopes enabled for a given OAuth token. This method does not work for installation tokens. ```javascript const TOKEN = "ghp_PersonalAccessToken01245678900000000"; const auth = createTokenAuth(TOKEN); const authentication = await auth(); const response = await request("HEAD /", { headers: authentication.headers, }); const scopes = response.headers["x-oauth-scopes"].split(/,\s+/); if (scopes.length) { console.log( `"${TOKEN}" has ${scopes.length} scopes enabled: ${scopes.join(", ")}` ); } else { console.log(`"${TOKEN}" has no scopes enabled`); } ``` -------------------------------- ### Get Repository Permissions Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/auth-token/README.md Retrieve the permissions enabled for a specific repository. Note that the 'permissions' key is not available when using installation access tokens. ```javascript const TOKEN = "ghp_PersonalAccessToken01245678900000000"; const auth = createTokenAuth(TOKEN); const authentication = await auth(); const response = await request("GET /repos/{owner}/{repo}", { owner: 'octocat', repo: 'hello-world', headers: authentication.headers }); console.log(response.data.permissions) // { // admin: true, // push: true, // pull: true // } ``` -------------------------------- ### Load in Node.js Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/plugin-rest-endpoint-methods/README.md Install the necessary packages using npm and require them for Node.js applications. You can optionally use a compatible module instead of @octokit/core. ```js const { Octokit } = require("@octokit/core"); const { restEndpointMethods, } = require("@octokit/plugin-rest-endpoint-methods"); ``` -------------------------------- ### Make a REST API Request with Octokit Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/core/README.md Example of creating an Octokit instance with authentication and making a GET request to retrieve private repositories for an organization. ```javascript // Create a personal access token at https://github.com/settings/tokens/new?scopes=repo const octokit = new Octokit({ auth: `personal-access-token123` }); const response = await octokit.request("GET /orgs/{org}/repos", { org: "octokit", type: "private", }); ``` -------------------------------- ### Basic Gradle Build Script Setup Source: https://github.com/jfrog/frogbot/blob/main/testdata/projects/gradle/fixedBuildGradleForCompare.txt Standard configuration for a Java application project in Gradle. Includes plugins, main class, group, version, and source compatibility. ```gradle plugins { id 'java' id 'application' } mainClassName = 'com.example.Main' group 'com.example' version '1.0-SNAPSHOT' sourceCompatibility = 1.8 ``` -------------------------------- ### Client Certificate Authentication Example Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/undici/docs/best-practices/client-certificate.md Demonstrates setting up an HTTPS server that requests client certificates and an Undici client that provides its own certificate for authentication. It shows how to configure both server and client TLS options, including CA certificates, keys, and certs. The server checks the `authorized` and `authorizationError` properties of the client's certificate. ```javascript const { readFileSync } = require('fs') const { join } = require('path') const { createServer } = require('https') const { Client } = require('undici') const serverOptions = { ca: [ readFileSync(join(__dirname, 'client-ca-crt.pem'), 'utf8') ], key: readFileSync(join(__dirname, 'server-key.pem'), 'utf8'), cert: readFileSync(join(__dirname, 'server-crt.pem'), 'utf8'), requestCert: true, rejectUnauthorized: false } const server = createServer(serverOptions, (req, res) => { // true if client cert is valid if(req.client.authorized === true) { console.log('valid') } else { console.error(req.client.authorizationError) } res.end() }) server.listen(0, function () { const tls = { ca: [ readFileSync(join(__dirname, 'server-ca-crt.pem'), 'utf8') ], key: readFileSync(join(__dirname, 'client-key.pem'), 'utf8'), cert: readFileSync(join(__dirname, 'client-crt.pem'), 'utf8'), rejectUnauthorized: false, servername: 'agent1' } const client = new Client(`https://localhost:${server.address().port}`, { connect: tls }) client.request({ path: '/', method: 'GET' }, (err, { body }) => { body.on('data', (buf) => {}) body.on('end', () => { client.close() server.close() }) }) }) ``` -------------------------------- ### MockPool request Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/undici/docs/api/MockPool.md This example demonstrates how to use `mockPool.request` to make a request to a mocked origin. It intercepts a GET request to '/foo' and replies with a 200 status and 'foo' as the body. The response is then processed to log the status code and the body content. ```javascript import { MockAgent } from 'undici' const mockAgent = new MockAgent() const mockPool = mockAgent.get('http://localhost:3000') mockPool.intercept({ path: '/foo', method: 'GET', }).reply(200, 'foo') const { statusCode, body } = await mockPool.request({ origin: 'http://localhost:3000', path: '/foo', method: 'GET' }) console.log('response received', statusCode) // response received 200 for await (const data of body) { console.log('data', data.toString('utf8')) // data foo } ``` -------------------------------- ### Mocked Request with Reply Data Callback Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/undici/docs/api/MockPool.md This example shows how to use a callback function within `reply` to dynamically generate the response body based on the incoming request's headers. It intercepts a GET request to '/echo' and echoes a 'message' header from the request in the response. ```javascript import { MockAgent, setGlobalDispatcher, request } from 'undici' const mockAgent = new MockAgent() setGlobalDispatcher(mockAgent) const mockPool = mockAgent.get('http://localhost:3000') mockPool.intercept({ path: '/echo', method: 'GET', headers: { 'User-Agent': 'undici', Host: 'example.com' } }).reply(200, ({ headers }) => ({ message: headers.get('message') })) const { statusCode, body, headers } = await request('http://localhost:3000', { headers: { message: 'hello world!' } }) console.log('response received', statusCode) // response received 200 console.log('headers', headers) // { 'content-type': 'application/json' } for await (const data of body) { console.log('data', data.toString('utf8')) // { "message":"hello world!" } } ``` -------------------------------- ### Mocked request with path callback Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/undici/docs/api/MockPool.md This example demonstrates how to mock a GET request to 'http://localhost:3000/foo?foo=bar' using a callback function to match the request path and query parameters. The mock pool is configured to intercept requests that match the specified criteria and reply with a 200 status code and 'foo' as the response body. ```javascript import { MockAgent, setGlobalDispatcher, request } from 'undici' import querystring from 'querystring' const mockAgent = new MockAgent() setGlobalDispatcher(mockAgent) const mockPool = mockAgent.get('http://localhost:3000') const matchPath = requestPath => { const [pathname, search] = requestPath.split('?') const requestQuery = querystring.parse(search) if (!pathname.startsWith('/foo')) { return false } if (!Object.keys(requestQuery).includes('foo') || requestQuery.foo !== 'bar') { return false } return true } mockPool.intercept({ path: matchPath, method: 'GET' }).reply(200, 'foo') const result = await request('http://localhost:3000/foo?foo=bar') // Will match and return mocked data ``` -------------------------------- ### Basic HTTP Server with Busboy Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@fastify/busboy/README.md This example demonstrates a basic HTTP server that uses busboy to parse incoming form data, including files and fields. It handles both POST requests for form submission and GET requests to serve the HTML form. Ensure you handle the file stream, even if discarding its contents, to prevent the 'finish' event from being missed. ```javascript const http = require('node:http'); const { inspect } = require('node:util'); const Busboy = require('busboy'); http.createServer(function(req, res) { if (req.method === 'POST') { const busboy = new Busboy({ headers: req.headers }); busboy.on('file', function(fieldname, file, filename, encoding, mimetype) { console.log('File [' + fieldname + ']: filename: ' + filename); file.on('data', function(data) { console.log('File [' + fieldname + '] got ' + data.length + ' bytes'); }); file.on('end', function() { console.log('File [' + fieldname + '] Finished'); }); }); busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated) { console.log('Field [' + fieldname + ']: value: ' + inspect(val)); }); busboy.on('finish', function() { console.log('Done parsing form!'); res.writeHead(303, { Connection: 'close', Location: '/' }); res.end(); }); req.pipe(busboy); } else if (req.method === 'GET') { res.writeHead(200, { Connection: 'close' }); res.end('
\ \ '); } }).listen(8000, function() { console.log('Listening for requests'); }); // Example output: // // Listening for requests // Field [textfield]: value: 'testing! :-)' // Field [selectfield]: value: '9001' // Field [checkfield]: value: 'on' // Done parsing form! ``` -------------------------------- ### Initialize New Git Repository Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/simple-git/readme.md Initializes a new Git repository, adds all files, commits them, adds a remote origin, and pushes to the master branch. ```javascript simpleGit() .init() .add('./*') .commit('first commit!') .addRemote('origin', 'https://github.com/user/repo.git') .push('origin', 'master'); ``` -------------------------------- ### Install uuid Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@actions/core/node_modules/uuid/README.md Install the uuid package using npm. ```shell npm install uuid ``` -------------------------------- ### Mocked Request with Query, Body, Headers, and Trailers Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/undici/docs/api/MockPool.md This comprehensive example demonstrates mocking a POST request with specific query parameters, request body, headers, and configuring a response with status code, JSON body, custom headers, and trailers. It verifies that all aspects of the request and response are correctly handled. ```javascript import { MockAgent, setGlobalDispatcher, request } from 'undici' const mockAgent = new MockAgent() setGlobalDispatcher(mockAgent) const mockPool = mockAgent.get('http://localhost:3000') mockPool.intercept({ path: '/foo?hello=there&see=ya', method: 'POST', body: 'form1=data1&form2=data2', headers: { 'User-Agent': 'undici', Host: 'example.com' } }).reply(200, { foo: 'bar' }, { headers: { 'content-type': 'application/json' }, trailers: { 'Content-MD5': 'test' } }) const { statusCode, headers, trailers, body } = await request('http://localhost:3000/foo?hello=there&see=ya', { method: 'POST', body: 'form1=data1&form2=data2', headers: { foo: 'bar', 'User-Agent': 'undici', Host: 'example.com' } }) console.log('response received', statusCode) // response received 200 console.log('headers', headers) // { 'content-type': 'application/json' } for await (const data of body) { console.log('data', data.toString('utf8')) // '{"foo":"bar"}' } console.log('trailers', trailers) // { 'content-md5': 'test' } ``` -------------------------------- ### Building a Custom Octokit with Plugins and Defaults Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/@octokit/core/README.md Shows how to create a custom Octokit class with multiple plugins, default options, and authentication strategies. This is useful for specific environments like GitHub Actions. ```javascript const { Octokit } = require("@octokit/core"); const MyActionOctokit = Octokit.plugin( require("@octokit/plugin-paginate-rest").paginateRest, require("@octokit/plugin-throttling").throttling, require("@octokit/plugin-retry").retry ).defaults({ throttle: { onAbuseLimit: (retryAfter, options) => { /* ... */ }, onRateLimit: (retryAfter, options) => { /* ... */ }, }, authStrategy: require("@octokit/auth-action").createActionAuth, userAgent: `my-octokit-action/v1.2.3`, }); const octokit = new MyActionOctokit(); const installations = await octokit.paginate("GET /app/installations"); ``` -------------------------------- ### Configure Simple Git Instance with Options Source: https://github.com/jfrog/frogbot/blob/main/action/node_modules/simple-git/readme.md Instantiate simple-git with a configuration object to set options like base directory, binary path, and concurrency. Supports backward compatibility by allowing base directory as the first argument. ```typescript import { simpleGit, SimpleGit, SimpleGitOptions } from 'simple-git'; const options: Partial