π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[infra] Allow ashilkn updates to ashil-pilot PRs
ashilkn44f891fa0d16
diff --git a/.github/checks/pr-approval/test.mjs b/.github/checks/pr-approval/test.mjsnew file mode 100644index 0000000000..925c543f00--- /dev/null+++ b/.github/checks/pr-approval/test.mjs@@ -0,0 +1,78 @@+import assert from "node:assert/strict";+import { execFileSync } from "node:child_process";+import { join } from "node:path";+import test from "node:test";+import { runInNewContext } from "node:vm";++const workflow = join(import.meta.dirname, "../../workflows/pr-approval.yml");+const condition = execFileSync(+ "ruby",+ [+ "-ryaml",+ "-e",+ 'puts YAML.safe_load(File.read(ARGV.fetch(0)), aliases: true).fetch("jobs").fetch("approve").fetch("if")',+ workflow,+ ],+ { encoding: "utf8" },+);+const pilot = { id: 293300083, login: "ashil-pilot" };+const human = { id: 77285023, login: "ashilkn" };+const otherTrusted = { id: 24503581, login: "mnvr" };+const untrusted = { id: 1, login: "untrusted" };++function allowed(author, sender, overrides = {}) {+ return runInNewContext(condition, {+ github: {+ repository: "ente/ente",+ event: {+ pull_request: { user: author, changed_files: 1, draft: false },+ sender,+ },+ triggering_actor: sender.login,+ ...overrides,+ },+ contains: (values, value) => values.includes(value),+ fromJSON: JSON.parse,+ });+}++test("only ashilkn can update an ashil-pilot PR through the exception", () => {+ assert.equal(allowed(pilot, human), true);+ assert.equal(allowed(human, pilot), false);+});++test("other accounts cannot use the cross-account exception", () => {+ for (const author of [pilot, human, otherTrusted]) {+ assert.equal(allowed(author, author), true, author.login);+ for (const sender of [otherTrusted, untrusted]) {+ if (author.id === sender.id) continue;+ assert.equal(allowed(author, sender), false);+ assert.equal(allowed(sender, author), false);+ }+ }+ assert.equal(allowed(untrusted, untrusted), false);+});++test("ashilkn updates retain repository, rerun, draft, and file-count gates", () => {+ assert.equal(allowed(pilot, human, { repository: "fork/ente" }), false);+ assert.equal(+ allowed(pilot, human, { triggering_actor: pilot.login }),+ false,+ );+ for (const pull of [{ draft: true }, { changed_files: 101 }]) {+ assert.equal(+ allowed(pilot, human, {+ event: {+ sender: human,+ pull_request: {+ user: pilot,+ changed_files: 1,+ draft: false,+ ...pull,+ },+ },+ }),+ false,+ );+ }+});diff --git a/.github/checks/run.sh b/.github/checks/run.shindex 4e80469f72..7365fff8d9 100755--- a/.github/checks/run.sh+++ b/.github/checks/run.sh@@ -10,6 +10,7 @@ node .github/checks/documentation-comments/test.mjsruby .github/checks/workflow-paths/check.rbruby .github/checks/workflow-paths/test.rbruby .github/checks/workflow-security/test.rb+node --test .github/checks/pr-approval/test.mjsnode .github/checks/rust-ci-paths/check.mjsnode --test .github/checks/rust-ci-paths/test.mjsnode --test .github/scripts/ci/test.mjsdiff --git a/.github/workflows/pr-approval.yml b/.github/workflows/pr-approval.ymlindex 1ffe174873..01ba2fd09a 100644--- a/.github/workflows/pr-approval.yml+++ b/.github/workflows/pr-approval.yml@@ -17,7 +17,13 @@ jobs:if: >-github.repository == 'ente/ente' &&contains(fromJSON('[24503581,231175576,239996999,64626875,293300083,77285023,2698932,281837475,113718372]'), github.event.pull_request.user.id) &&- github.event.sender.id == github.event.pull_request.user.id &&+ (+ github.event.sender.id == github.event.pull_request.user.id ||+ (+ github.event.pull_request.user.id == 293300083 &&+ github.event.sender.id == 77285023+ )+ ) &&github.triggering_actor == github.event.sender.login &&github.event.pull_request.changed_files <= 100 &&!github.event.pull_request.draft