GitHub API Notification Plugin for reg-suit
This plugin for `reg-suit`, a visual regression testing CLI, sends notification results to GitHub repositories. It is specifically designed for GitHub Enterprise users, utilizing the GitHub API with a personal access token for authentication, differentiating it from `reg-notify-github-plugin` which relies on a GitHub App for `github.com`. The current stable version is 0.14.6, with minor releases occurring actively as indicated by recent changelog entries. Key features include configurable GitHub URL, repository owner and name, private access token, and options for customizing the PR comment style, such as a short summary table. It's an essential component for integrating `reg-suit` results into GitHub-centric CI/CD workflows, especially in enterprise environments where GitHub Apps might be restricted.
Common errors
-
GitHub API responded with status 404 (Not Found) for repository 'owner/repository'
cause The configured `owner` or `repository` in `reg.config.json` does not match an existing GitHub repository accessible by the provided token.fixVerify that the `owner` and `repository` configuration values are correct and that the `privateToken` has access to that specific repository. -
GitHub API responded with status 401 (Unauthorized) - Bad credentials
cause The `privateToken` provided in the `reg.config.json` is invalid, expired, or lacks the necessary permissions (e.g., 'repo' scope for private repositories).fixGenerate a new GitHub Personal Access Token with the required `repo` scope and update your `reg.config.json` or environment variable. Ensure there are no typos. -
Error: Plugin 'notify-github-with-api' not found.
cause The plugin has not been correctly installed or `reg-suit` has not been prepared to recognize it.fixEnsure you have run `npm install reg-notify-github-with-api-plugin -D` and then `reg-suit prepare -p notify-github-with-api` to register the plugin with your `reg-suit` configuration.
Warnings
- gotcha This plugin (`reg-notify-github-with-api-plugin`) is specifically for GitHub Enterprise or scenarios requiring personal access token authentication. If you are using `github.com` and prefer GitHub App integration, the `reg-notify-github-plugin` is generally recommended. Do not confuse the two as their authentication methods differ significantly.
- breaking The `privateToken` configuration option requires a GitHub Personal Access Token with the `repo` scope if the target repository is private. Insufficient scopes will lead to authentication failures when attempting to comment or update PR status.
- gotcha Multiple `reg-suit` runs on the same pull request might overwrite each other's comments if they use the default `markerComment`. This can lead to lost history or confusion in visual regression reports.
Install
-
npm install reg-notify-github-with-api-plugin -
yarn add reg-notify-github-with-api-plugin -
pnpm add reg-notify-github-with-api-plugin
Imports
- RegNotifyGithubWithApiPlugin
import RegNotifyGithubWithApiPlugin from 'reg-notify-github-with-api-plugin';
- RegNotifyGithubWithApiPluginOption
import type { RegNotifyGithubWithApiPluginOption } from 'reg-notify-github-with-api-plugin'; - prepare command
import { prepare } from 'reg-suit'; prepare('-p notify-github-with-api');reg-suit prepare -p notify-github-with-api
Quickstart
npm i reg-notify-github-with-api-plugin -D
reg-suit prepare -p notify-github-with-api
// Add this configuration to your reg.config.json or reg.config.ts
// Ensure you replace placeholder values with your actual GitHub details and token.
// For security, it's highly recommended to use environment variables for `privateToken`.
interface RegConfig {
plugins: [
'reg-keygen-git-hash-plugin',
'reg-publish-s3-plugin', // Or 'reg-publish-gcs-plugin' for Google Cloud Storage
['reg-notify-github-with-api-plugin', {
githubUrl: process.env.GITHUB_API_URL ?? 'https://api.github.com/graphql',
owner: process.env.GITHUB_REPO_OWNER ?? 'your-org-or-username',
repository: process.env.GITHUB_REPO_NAME ?? 'your-repo',
privateToken: process.env.GITHUB_TOKEN ?? '', // Requires 'repo' scope for private repos
ref: process.env.GITHUB_PR_REF ?? undefined,
shortDescription: true,
markerComment: 'reg-visual-test-results' // Optional: Customize for multiple workflows
}]
];
}
// Example reg.config.ts (if you use TypeScript for configuration)
const config: RegConfig = {
plugins: [
'reg-keygen-git-hash-plugin',
'reg-publish-s3-plugin',
['reg-notify-github-with-api-plugin', {
githubUrl: process.env.GITHUB_API_URL || 'https://api.github.com/graphql',
owner: process.env.GITHUB_REPO_OWNER || 'your-org-or-username',
repository: process.env.GITHUB_REPO_NAME || 'your-repo',
privateToken: process.env.GITHUB_TOKEN || '',
ref: process.env.GITHUB_PR_REF,
shortDescription: true,
markerComment: 'reg-visual-test-results'
}]
]
};
export default config;