Skip to content

Commit

Permalink
Bump reng to the latest version so that metadata is available
Browse files Browse the repository at this point in the history
Signed-off-by: Yoriyasu Yano <[email protected]>
  • Loading branch information
yorinasub17 committed Oct 18, 2023
1 parent 6d5f5f2 commit 858cbb4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"test": "jest"
},
"devDependencies": {
"@fensak-io/reng": "^1.0.7",
"@fensak-io/reng": "^1.1.2",
"@octokit/rest": "^20.0.2",
"@jest/globals": "^29.7.0",
"eslint": "^8.50.0",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rules/sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* the root README.md file.
*/

function main(inp) {
function main(inp, _metadata) {
const numPatches = inp.length;
if (numPatches == 0) {
// No files updated, so approve.
Expand Down
23 changes: 19 additions & 4 deletions rules/sample.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,45 @@ const testRepo = {
const opts = { logMode: RuleLogMode.Console };

test("No changes should be approved", async () => {
const result = await runRule(ruleFn, [], opts);
const result = await runRule(ruleFn, [], { sourceBranch: "foo" }, opts);
expect(result.approve).toBe(true);
});

test("Changes only to README should be approved", async () => {
// View PR at
// https://github.com/fensak-io/dotfensak-deno-template/pull/1
const patches = await patchFromGitHubPullRequest(octokit, testRepo, 1);
const result = await runRule(ruleFn, patches.patchList, opts);
const result = await runRule(
ruleFn,
patches.patchList,
patches.metadata,
opts,
);
expect(result.approve).toBe(true);
});

test("Changes to non-README files should be rejected", async () => {
// View PR at
// https://github.com/fensak-io/dotfensak-deno-template/pull/2
const patches = await patchFromGitHubPullRequest(octokit, testRepo, 2);
const result = await runRule(ruleFn, patches.patchList, opts);
const result = await runRule(
ruleFn,
patches.patchList,
patches.metadata,
opts,
);
expect(result.approve).toBe(false);
});

test("Change containing more than one file should be rejected", async () => {
// View PR at
// https://github.com/fensak-io/dotfensak-deno-template/pull/4
const patches = await patchFromGitHubPullRequest(octokit, testRepo, 4);
const result = await runRule(ruleFn, patches.patchList, opts);
const result = await runRule(
ruleFn,
patches.patchList,
patches.metadata,
opts,
);
expect(result.approve).toBe(false);
});

0 comments on commit 858cbb4

Please sign in to comment.