Skip to content

Commit

Permalink
fix: Make the target branch for the PR also available in the metadata…
Browse files Browse the repository at this point in the history
… parameter

Signed-off-by: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com>
  • Loading branch information
yorinasub17 committed Oct 18, 2023
1 parent ae7e106 commit 82027cb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/engine/from_github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export async function patchFromGitHubPullRequest(
const out: IGitHubPullRequestPatches = {
metadata: {
sourceBranch: pullReq.head.ref,
targetBranch: pullReq.base.ref,
},
patchList: [],
patchFetchMap: {},
Expand Down
37 changes: 21 additions & 16 deletions src/engine/interpreter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { PatchOp } from "./patch_types.ts";
import { runRule, RuleLogMode, RuleLogLevel } from "./interpreter.ts";
import { compileRuleFn, RuleFnSourceLang } from "./compile.ts";

const nullMeta = {
sourceBranch: "foo",
targetBranch: "bar",
};

test("sanity check", async () => {
const ruleFn = `function main(inp, metadata) {
return inp.length === 1 && metadata.sourceBranch === "foo";
Expand All @@ -24,7 +29,7 @@ test("sanity check", async () => {
diff: [],
},
],
{ sourceBranch: "foo" },
nullMeta,
);
expect(result.approve).toBe(true);
});
Expand All @@ -47,7 +52,7 @@ test("sanity check old version", async () => {
diff: [],
},
],
{ sourceBranch: "foo" },
nullMeta,
);
expect(result.approve).toBe(true);
});
Expand All @@ -70,7 +75,7 @@ test("ES5 minify", async () => {
diff: [],
},
],
{ sourceBranch: "foo" },
nullMeta,
);
expect(result.approve).toBe(true);
});
Expand All @@ -95,7 +100,7 @@ test("ES6 support", async () => {
diff: [],
},
],
{ sourceBranch: "foo" },
nullMeta,
);
expect(result.approve).toBe(true);
});
Expand Down Expand Up @@ -125,7 +130,7 @@ function main(inp: IPatch[], metadata: IChangeSetMetadata) {
diff: [],
},
],
{ sourceBranch: "foo" },
nullMeta,
);
expect(result.approve).toBe(true);
});
Expand All @@ -139,7 +144,7 @@ test("basic logging", async () => {
const opts = {
logMode: RuleLogMode.Capture,
};
const result = await runRule(ruleFn, [], { sourceBranch: "foo" }, opts);
const result = await runRule(ruleFn, [], nullMeta, opts);
expect(result.approve).toBe(false);
expect(result.logs).toEqual([
{
Expand All @@ -158,7 +163,7 @@ test("logging with multiple objects", async () => {
const opts = {
logMode: RuleLogMode.Capture,
};
const result = await runRule(ruleFn, [], { sourceBranch: "foo" }, opts);
const result = await runRule(ruleFn, [], nullMeta, opts);
expect(result.approve).toBe(false);
expect(result.logs).toEqual([
{
Expand All @@ -178,7 +183,7 @@ test("logging order", async () => {
const opts = {
logMode: RuleLogMode.Capture,
};
const result = await runRule(ruleFn, [], { sourceBranch: "foo" }, opts);
const result = await runRule(ruleFn, [], nullMeta, opts);
expect(result.approve).toBe(false);
expect(result.logs).toEqual([
{
Expand All @@ -201,7 +206,7 @@ test("logging warn level", async () => {
const opts = {
logMode: RuleLogMode.Capture,
};
const result = await runRule(ruleFn, [], { sourceBranch: "foo" }, opts);
const result = await runRule(ruleFn, [], nullMeta, opts);
expect(result.approve).toBe(false);
expect(result.logs).toEqual([
{
Expand All @@ -220,7 +225,7 @@ test("logging error level", async () => {
const opts = {
logMode: RuleLogMode.Capture,
};
const result = await runRule(ruleFn, [], { sourceBranch: "foo" }, opts);
const result = await runRule(ruleFn, [], nullMeta, opts);
expect(result.approve).toBe(false);
expect(result.logs).toEqual([
{
Expand All @@ -235,7 +240,7 @@ test("main return must be boolean", async () => {
return "hello world";
}
`;
await expect(runRule(ruleFn, [], { sourceBranch: "foo" })).rejects.toThrow(
await expect(runRule(ruleFn, [], nullMeta)).rejects.toThrow(
"main function must return boolean",
);
});
Expand All @@ -246,7 +251,7 @@ test("infinite loop", async () => {
return "hello world";
}
`;
await expect(runRule(ruleFn, [], { sourceBranch: "foo" })).rejects.toThrow(
await expect(runRule(ruleFn, [], nullMeta)).rejects.toThrow(
"user defined rule timed out",
);
}, 10000);
Expand Down Expand Up @@ -277,7 +282,7 @@ test("XMLHTTPRequest not supported", async () => {
diff: [],
},
],
{ sourceBranch: "foo" },
nullMeta,
),
).rejects.toThrow("XMLHttpRequest is not defined");
});
Expand All @@ -303,7 +308,7 @@ test("fetch is not supported", async () => {
diff: [],
},
],
{ sourceBranch: "foo" },
nullMeta,
),
).rejects.toThrow("fetch is not defined");
});
Expand All @@ -327,7 +332,7 @@ test("process is not supported", async () => {
diff: [],
},
],
{ sourceBranch: "foo" },
nullMeta,
),
).rejects.toThrow("process is not defined");
});
Expand All @@ -351,7 +356,7 @@ test("Deno is not supported", async () => {
diff: [],
},
],
{ sourceBranch: "foo" },
nullMeta,
),
).rejects.toThrow("Deno is not defined");
});
2 changes: 2 additions & 0 deletions src/engine/patch_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export interface IPatch {
/**
* Represents metadata about the change set that is under evaluation.
* @property sourceBranch The branch that the change set originates from.
* @property targetBranch The branch that the change set is merging into.
*/
export interface IChangeSetMetadata {
sourceBranch: string;
targetBranch: string;
}

0 comments on commit 82027cb

Please sign in to comment.