Skip to content
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

feat: Add prCommentBehavior option #365

Merged
merged 2 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/reg-notify-github-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ If reg-suit detects visual differences, it set the commit status failure. Someti
{
clientId: string;
prComment?: boolean;
prCommentBehavior?: "default" | "once" | "new";
setCommitStatus?: boolean;
}
```

- `clientId` - _Required_ - Client ID for reg-suit GitHub app. You can get it visiting [here](https://reg-viz.github.io/gh-app/) and click the **Get client ID** button.
- `prComment` - _Optional_ - Whether to allow reg-suit to comment to pull request. Default: `true`.
- `prCommentBehavior` - _Optional_ - How the plugin comments to your pull requests. Enabled values are the following. Default: `default`.
- `"default"` : Update the PR comment if exists. Otherwise post new comment.
- `"new"` : Delete existing old comment and post new comment.
- `"once"` : Does nothing if the PR comment exists.
- `setCommitStatus` - _Optional_ - Whether to allow reg-suit to set commit status to fail if any visual differences are detected. Default: `true`.
2 changes: 1 addition & 1 deletion packages/reg-notify-github-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"dependencies": {
"open": "^7.2.1",
"reg-gh-app-interface": "^1.1.0",
"reg-gh-app-interface": "^1.2.0",
"reg-suit-util": "^0.10.10",
"request": "^2.88.2",
"request-promise": "^4.2.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import { NotifierPlugin, NotifyParams, PluginCreateOptions, PluginLogger } from

import rp from "request-promise";

type PrCommentBehavior = "default" | "once" | "new";

export interface GitHubPluginOption {
clientId?: string;
installationId?: string;
owner?: string;
repository?: string;
prComment?: boolean;
prCommentBehavior?: PrCommentBehavior;
setCommitStatus?: boolean;
customEndpoint?: string;
}
Expand Down Expand Up @@ -46,6 +49,7 @@ export class GitHubNotifierPlugin implements NotifierPlugin<GitHubPluginOption>
_apiOpt!: BaseEventBody;
_prComment!: boolean;
_setCommitStatus!: boolean;
_behavior!: PrCommentBehavior;

_apiPrefix!: string;
_repo!: Repository;
Expand All @@ -69,6 +73,7 @@ export class GitHubNotifierPlugin implements NotifierPlugin<GitHubPluginOption>
this._apiOpt = config.options as BaseEventBody;
}
this._prComment = config.options.prComment !== false;
this._behavior = config.options.prCommentBehavior ?? "default";
this._setCommitStatus = config.options.setCommitStatus !== false;
this._apiPrefix = config.options.customEndpoint || getGhAppInfo().endpoint;
this._repo = new Repository(path.join(fsUtil.prjRootDir(".git"), ".git"));
Expand Down Expand Up @@ -123,6 +128,7 @@ export class GitHubNotifierPlugin implements NotifierPlugin<GitHubPluginOption>
if (head.type === "branch" && head.branch) {
const prCommentBody: CommentToPrBody = {
...this._apiOpt,
behavior: this._behavior,
branchName: head.branch.name,
headOid: sha1,
failedItemsCount,
Expand Down
2 changes: 2 additions & 0 deletions packages/reg-notify-github-plugin/src/github-preparer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class GitHubPreparer implements PluginPreparer<GitHubPreparerOption, GitH

prepare(option: PluginCreateOptions<GitHubPreparerOption>): Promise<GitHubPluginOption> {
return Promise.resolve({
prComment: true,
prCommentBehavior: "default",
clientId: option.options.clientId,
});
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8029,10 +8029,10 @@ reg-cli@^0.17.0:
mustache "4.1.0"
x-img-diff-js "0.3.5"

reg-gh-app-interface@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/reg-gh-app-interface/-/reg-gh-app-interface-1.1.0.tgz#a71c80acad06944d21fa5d4fb3d1bf7545a8eb42"
integrity sha512-hTUJVbmV/67xdqXE+Z/vFpoo+1QdNlQDcrynlKc3d+7mY2trff3n70ETOwhtrxMwSzLxtCTcnHRSIqMeW4AnaQ==
reg-gh-app-interface@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/reg-gh-app-interface/-/reg-gh-app-interface-1.2.0.tgz#0961143d75a0f7453b5d07a4fd34591da96e6add"
integrity sha512-jgEH91LWOYf7HfoO9HfX2aM71CHZs/V6Yb3yEbECK9CB69an4yNdx24l8dBUdKywesnhE/IzJ3AfOd4a84L0Og==

regenerator-runtime@^0.11.0:
version "0.11.1"
Expand Down