Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 3 additions & 50 deletions .github/workflows/ai-disclosure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ name: AI disclosure
# did written under it. This check fails until exactly one box is ticked, and
# the main ruleset requires it. Editing the description runs it again.
#
# It reads the description from the event, through an environment variable,
# and needs no token and no checkout. Dependabot pull requests are exempt.
# modulane/ai-disclosure reads the description from the event and needs no
# token and no checkout. Dependabot pull requests are exempt.
on:
pull_request:
types: [opened, edited, reopened, synchronize]
Expand All @@ -27,51 +27,4 @@ jobs:

steps:
- name: Check the AI use section
env:
BODY: ${{ github.event.pull_request.body }}
AUTHOR: ${{ github.event.pull_request.user.login }}
run: |
if [ "$AUTHOR" = 'dependabot[bot]' ]; then
echo 'Dependabot pull request: no disclosure needed.'
exit 0
fi

node - <<'JS'
const body = (process.env.BODY ?? '').replace(/<!--[\s\S]*?-->/g, '')
const fail = (message) => {
console.log(`::error::${message}`)
process.exit(1)
}

const section = body.match(/^##[ \t]+AI use[ \t]*$([\s\S]*?)(?=^##[ \t]|(?![\s\S]))/im)
if (!section) {
fail('The description has no "## AI use" section. Copy it from the pull request template and tick one box.')
}

const box = /^[ \t]*[-*][ \t]+\[([ xX])\][ \t]+(.*)$/
const lines = section[1].split(/\r?\n/)
const ticked = lines.map((line) => line.match(box)).filter((m) => m && m[1] !== ' ')
const none = ticked.some((m) => /^no ai tool/i.test(m[2]))
const used = ticked.some((m) => /^ai tools were used/i.test(m[2]))

if (none === used) {
fail('In the "AI use" section, tick exactly one box: "No AI tool was used" or "AI tools were used".')
}

if (used) {
// The description can follow the box on its line, or the lines under it.
const details = lines
.map((line) => {
const m = line.match(box)
return m ? (/^ai tools were used/i.test(m[2]) ? m[2].replace(/^[^:]*:?/, '') : '') : line
})
.join(' ')
.replace(/\s+/g, ' ')
.trim()
if (details.length < 20) {
fail('"AI tools were used" is ticked: under it, name each tool and what it did.')
}
}

console.log(none ? 'Disclosed: no AI tool was used.' : 'Disclosed: AI tools were used, and how.')
JS
uses: modulane/ai-disclosure@5d2b11a0b28a8103f1b8d9ac31c7c7d79688b218 # v1.0.0
Loading