generated from fensak-io/dotfensak-deno-template
-
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.
Add fensak configuration to ensure merges to release branch can only …
…happen from main branch Signed-off-by: Yoriyasu Yano <[email protected]>
- Loading branch information
1 parent
8df597b
commit 0bae751
Showing
5 changed files
with
93 additions
and
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,8 @@ | ||
# This file contains the Fensak configuration file for this GitHub Organization. | ||
# The config file specifies which rules should be applied to the different repositories in your organization. | ||
# | ||
# This contains a starting point for a fictional repo `my-repo` in your org. Update to point to your real repos and | ||
# rules to get started using Fensak. | ||
# | ||
# Refer to https://github.com/fensak-io/fensak/blob/main/fskconfig/schema.json | ||
# for the expected config schema. | ||
|
||
repos: | ||
# Each entry in this configuration represents a single repository, and the corresponding rule that should be run | ||
# to determine auto-approval for PRs in the repo. | ||
my-repo: | ||
# The path to the rule relative to the repo root. | ||
ruleFile: rules/sample.ts | ||
|
||
# The following attribute is optional. When omitted, the rule language is automatically determined based on the rule | ||
# file extension. Refer to the schema for the list of allowed values here. | ||
# ruleLang: ts | ||
|
||
# The following attribute is optional. This setting controls how many approvals should be required for PRs where the | ||
# rule does not pass. The default is 1. | ||
# requiredApprovals: 1 | ||
fensak: | ||
requiredRuleFile: rules/fensak_required_rule.ts | ||
requiredApprovals: 0 | ||
|
||
# You can add more repositories by extending the repos map with more entries like so: | ||
# | ||
# my-other-repo: | ||
# ruleFile: rules/sample.ts | ||
dashboard: | ||
requiredRuleFile: rules/fensak_required_rule.ts | ||
requiredApprovals: 0 |
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,21 @@ | ||
/** | ||
* A Fensak rule for the repositories that use release branch strategy. This rule requires that the source branch of the | ||
* release branch is set to main. This ensures that only the main branch can merge into the release branch. | ||
*/ | ||
|
||
// fensak remove-start | ||
import type { IChangeSetMetadata, IPatch } from "npm:@fensak-io/reng@^1.2.1"; | ||
// fensak remove-end | ||
|
||
// deno-lint-ignore no-unused-vars | ||
function main(_inp: IPatch[], metadata: IChangeSetMetadata): boolean { | ||
if (metadata.targetBranch === "release" && metadata.sourceBranch !== "main") { | ||
console.log( | ||
"Rejecting since merging non-main branch into the release branch.", | ||
); | ||
return false; | ||
} | ||
|
||
// Allow all other PRs. | ||
return true; | ||
} |
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,66 @@ | ||
import { | ||
assert, | ||
assertFalse, | ||
} from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
import { | ||
compileRuleFn, | ||
IGitHubRepository, | ||
patchFromGitHubPullRequest, | ||
RuleFnSourceLang, | ||
RuleLogMode, | ||
runRule, | ||
} from "npm:@fensak-io/reng@^1.2.1"; | ||
import { Octokit } from "npm:@octokit/rest@^20.0.0"; | ||
|
||
const __dirname = new URL(".", import.meta.url).pathname; | ||
const ruleFn = compileRuleFn( | ||
await Deno.readTextFile(`${__dirname}/fensak_required_rule.ts`), | ||
RuleFnSourceLang.Typescript, | ||
); | ||
const octokit = new Octokit({ | ||
auth: Deno.env.get("GITHUB_API_TOKEN"), | ||
}); | ||
const fensakRepo: IGitHubRepository = { | ||
owner: "fensak-io", | ||
name: "fensak", | ||
}; | ||
const opts = { logMode: RuleLogMode.Console }; | ||
|
||
Deno.test("Normal release PR should be approved", async () => { | ||
// View PR at | ||
// https://github.com/fensak-io/fensak/pull/125 | ||
const patches = await patchFromGitHubPullRequest(octokit, fensakRepo, 125); | ||
const result = await runRule( | ||
ruleFn, | ||
patches.patchList, | ||
patches.metadata, | ||
opts, | ||
); | ||
assert(result.approve); | ||
}); | ||
|
||
Deno.test("Normal PRs to main should be approved", async () => { | ||
// View PR at | ||
// https://github.com/fensak-io/fensak/pull/124 | ||
const patches = await patchFromGitHubPullRequest(octokit, fensakRepo, 124); | ||
const result = await runRule( | ||
ruleFn, | ||
patches.patchList, | ||
patches.metadata, | ||
opts, | ||
); | ||
assert(result.approve); | ||
}); | ||
|
||
Deno.test("PRs to release from a random branch should be rejected", async () => { | ||
// View PR at | ||
// https://github.com/fensak-io/fensak/pull/126 | ||
const patches = await patchFromGitHubPullRequest(octokit, fensakRepo, 126); | ||
const result = await runRule( | ||
ruleFn, | ||
patches.patchList, | ||
patches.metadata, | ||
opts, | ||
); | ||
assertFalse(result.approve); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.