Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@danj/hey-email

HEY.com email for Kody: search threads, read messages, download PDF attachments, and write drafts. Sending is barred until you allow it.

FollowFork

Files

sending-policy-check.mjs

42 lines · 1.4 KB · JavaScript
import { execFileSync } from 'node:child_process'

const baseRef = process.env.SENDING_BASE_REF || 'origin/main'

function finish(status, reason, detail) {
  const log = status === 'pass' ? console.log : console.error
  log(`sending-policy-check: ${detail}`)
  log(`status=${status}`)
  if (reason) log(`reason=${reason}`)
  process.exit(status === 'pass' ? 0 : 1)
}

async function baseSending() {
  let source
  try {
    source = execFileSync('git', ['show', `${baseRef}:src/config.js`], {
      encoding: 'utf8',
      stdio: ['ignore', 'pipe', 'pipe'],
    })
  } catch (error) {
    if (/does not exist in|exists on disk, but not in/.test(String(error.stderr))) return undefined
    finish('blocked', `cannot read src/config.js at ${baseRef}`, String(error.stderr ?? error.message).trim())
  }
  const config = await import(`data:text/javascript,${encodeURIComponent(source)}`)
  return config.SENDING
}

let SENDING, base
try {
  ;({ SENDING } = await import('../src/config.js'))
  base = await baseSending()
} catch (error) {
  finish('blocked', 'cannot load a sending configuration', String(error?.message ?? error))
}
const summary = `SENDING=${JSON.stringify(SENDING)}, ${baseRef} has ${JSON.stringify(base)}`

// Only the owner turns sending on, on main. A branch may inherit 'allowed' from main.
if (SENDING === 'allowed' && base !== 'allowed') {
  finish('fail', 'this branch turns sending on', summary)
}

finish('pass', null, summary)