forked from paritytech/review-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Changes - Created the `AND` rule with a configuration. - This resolves paritytech#10 - Created the type for it - Created the JOI validation - It must have at least two individual conditions for it to be valid so it is not used as a `basic` rule. - Fixed bug where check summary duplicated content - This happened because it has a buffer and I had to empty it. - Created `AND` rule evaluation for pull requests. - It combines its report into one. - Fixed bug where author appeared as one of the missing reviews - Created tests for `AND` rule. - Renamed files and directories - `file` directory now is `rule` directory (as it store the types and validations for the clases)
- Loading branch information
Showing
11 changed files
with
440 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,200 @@ | ||
/* eslint-disable @typescript-eslint/unbound-method */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-call */ | ||
import { mock, MockProxy } from "jest-mock-extended"; | ||
|
||
import { PullRequestApi } from "../../github/pullRequest"; | ||
import { TeamApi } from "../../github/teams"; | ||
import { AndRule } from "../../rules/types"; | ||
import { ActionRunner } from "../../runner"; | ||
import { TestLogger } from "../logger"; | ||
|
||
describe("'And' rule parsing", () => { | ||
let api: MockProxy<PullRequestApi>; | ||
let runner: ActionRunner; | ||
let teamsApi: MockProxy<TeamApi>; | ||
let logger: TestLogger; | ||
beforeEach(() => { | ||
logger = new TestLogger(); | ||
api = mock<PullRequestApi>(); | ||
runner = new ActionRunner(api, teamsApi, logger); | ||
}); | ||
test("should get minimal config", async () => { | ||
api.getConfigFile.mockResolvedValue(` | ||
rules: | ||
- name: Test review | ||
condition: | ||
include: | ||
- '.*' | ||
exclude: | ||
- 'example' | ||
type: and | ||
reviewers: | ||
- teams: | ||
- team-example | ||
- teams: | ||
- team-abc | ||
`); | ||
const config = await runner.getConfigFile(""); | ||
expect(config.rules[0].name).toEqual("Test review"); | ||
expect(config.rules[0].type).toEqual("and"); | ||
}); | ||
|
||
describe("reviewers", () => { | ||
test("should require teams", async () => { | ||
api.getConfigFile.mockResolvedValue(` | ||
rules: | ||
- name: Test review | ||
condition: | ||
include: | ||
- '.*' | ||
exclude: | ||
- 'example' | ||
type: and | ||
reviewers: | ||
- teams: | ||
- team-example | ||
- teams: | ||
- team-abc | ||
`); | ||
const config = await runner.getConfigFile(""); | ||
const rule = config.rules[0] as AndRule; | ||
expect(rule.reviewers).toHaveLength(2); | ||
expect(rule.reviewers[0].teams).toContainEqual("team-example"); | ||
expect(rule.reviewers[0].users).toBeUndefined(); | ||
expect(rule.reviewers[1].teams).toContainEqual("team-abc"); | ||
expect(rule.reviewers[1].users).toBeUndefined(); | ||
}); | ||
test("should require users", async () => { | ||
api.getConfigFile.mockResolvedValue(` | ||
rules: | ||
- name: Test review | ||
condition: | ||
include: | ||
- '.*' | ||
exclude: | ||
- 'example' | ||
type: and | ||
reviewers: | ||
- users: | ||
- user-example | ||
- users: | ||
- user-special | ||
`); | ||
const config = await runner.getConfigFile(""); | ||
const rule = config.rules[0] as AndRule; | ||
expect(rule.reviewers[0].users).toContainEqual("user-example"); | ||
expect(rule.reviewers[0].teams).toBeUndefined(); | ||
expect(rule.reviewers[1].users).toContainEqual("user-special"); | ||
expect(rule.reviewers[1].teams).toBeUndefined(); | ||
}); | ||
|
||
test("should fail without reviewers", async () => { | ||
api.getConfigFile.mockResolvedValue(` | ||
rules: | ||
- name: Test review | ||
condition: | ||
include: | ||
- '.*' | ||
exclude: | ||
- 'example' | ||
type: and | ||
`); | ||
await expect(runner.getConfigFile("")).rejects.toThrowError('"reviewers" is required'); | ||
}); | ||
|
||
test("should fill the reviewers array", async () => { | ||
api.getConfigFile.mockResolvedValue(` | ||
rules: | ||
- name: Test review | ||
condition: | ||
include: | ||
- '.*' | ||
exclude: | ||
- 'example' | ||
type: and | ||
reviewers: | ||
- teams: | ||
- team-example | ||
- min_approvals: 2 | ||
users: | ||
- abc | ||
teams: | ||
- xyz | ||
`); | ||
const config = await runner.getConfigFile(""); | ||
const rule = config.rules[0] as AndRule; | ||
expect(rule.reviewers).toHaveLength(2); | ||
expect(rule.reviewers[0].teams).toContainEqual("team-example"); | ||
expect(rule.reviewers[0].users).toBeUndefined(); | ||
expect(rule.reviewers[1].min_approvals).toEqual(2); | ||
expect(rule.reviewers[1].users).toContainEqual("abc"); | ||
expect(rule.reviewers[1].teams).toContainEqual("xyz"); | ||
}); | ||
}); | ||
|
||
test("should default min_approvals to 1", async () => { | ||
api.getConfigFile.mockResolvedValue(` | ||
rules: | ||
- name: Test review | ||
condition: | ||
include: | ||
- '.*' | ||
exclude: | ||
- 'example' | ||
type: and | ||
reviewers: | ||
- users: | ||
- user-example | ||
- teams: | ||
- team-example | ||
`); | ||
const config = await runner.getConfigFile(""); | ||
const [rule] = config.rules; | ||
if (rule.type === "and") { | ||
expect(rule.reviewers[0].min_approvals).toEqual(1); | ||
} else { | ||
throw new Error(`Rule type ${rule.type} is invalid`); | ||
} | ||
}); | ||
|
||
test("should fail with min_approvals in negative", async () => { | ||
api.getConfigFile.mockResolvedValue(` | ||
rules: | ||
- name: Test review | ||
condition: | ||
include: | ||
- '.*' | ||
exclude: | ||
- 'example' | ||
type: and | ||
reviewers: | ||
- min_approvals: -99 | ||
users: | ||
- user-example | ||
`); | ||
await expect(runner.getConfigFile("")).rejects.toThrowError( | ||
'"reviewers[0].min_approvals" must be greater than or equal to 1', | ||
); | ||
}); | ||
|
||
test("should fail with min_approvals in 0", async () => { | ||
api.getConfigFile.mockResolvedValue(` | ||
rules: | ||
- name: Test review | ||
condition: | ||
include: | ||
- '.*' | ||
exclude: | ||
- 'example' | ||
type: and | ||
reviewers: | ||
- min_approvals: 0 | ||
users: | ||
- user-example | ||
`); | ||
await expect(runner.getConfigFile("")).rejects.toThrowError( | ||
'"reviewers[0].min_approvals" must be greater than or equal to 1', | ||
); | ||
}); | ||
}); |
This file contains 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 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
Oops, something went wrong.