From c3ebebaf3f74059ee0a6addc13f72166d36b5bc6 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sun, 16 Feb 2025 19:47:03 +0000 Subject: [PATCH] chore: Rename release workflow to draft. --- .github/workflows/draft.yml | 17 ++++++++++ .github/workflows/pages.yml | 3 -- .github/workflows/release.yml | 25 --------------- .reviewable/completion.js | 60 +++++++++++++++++++++++------------ 4 files changed, 56 insertions(+), 49 deletions(-) create mode 100644 .github/workflows/draft.yml delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/draft.yml b/.github/workflows/draft.yml new file mode 100644 index 0000000..6d2f854 --- /dev/null +++ b/.github/workflows/draft.yml @@ -0,0 +1,17 @@ +name: draft + +on: + push: + branches: [master] + pull_request_target: + branches: [master] + types: [opened, reopened, synchronize] + +# Cancel old builds when pushing new commits. +concurrency: + group: draft-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + release: + uses: TokTok/ci-tools/.github/workflows/release-drafter.yml@master diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index c872406..4171fa7 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -10,9 +10,6 @@ concurrency: cancel-in-progress: true jobs: - common: - uses: TokTok/ci-tools/.github/workflows/common-ci.yml@master - deploy: runs-on: ubuntu-latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 6f0854a..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: release - -on: - push: - branches: [master] - pull_request_target: - branches: [master] - types: [opened, reopened, synchronize] - -# Cancel old builds when pushing new commits. -concurrency: - group: release-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - release: - uses: TokTok/ci-tools/.github/workflows/release-drafter.yml@master - - netlify: - uses: TokTok/ci-tools/.github/workflows/netlify.yml@master - with: - dockerfile: Dockerfile - path: /home/builder/build - secrets: - NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} diff --git a/.reviewable/completion.js b/.reviewable/completion.js index d1c7ab5..1bef3b6 100644 --- a/.reviewable/completion.js +++ b/.reviewable/completion.js @@ -1,58 +1,76 @@ // jshint esversion: 6 -// This code will check that the pull request has been approved via GitHub review approval by a -// minimum number of reviewers and by all assignees, and that no changes were requested by any -// reviewers. Only reviewers with write access to the repository are considered. +// This code will check that the pull request has been approved via GitHub +// review approval by a minimum number of reviewers and by all assignees, and +// that no changes were requested by any reviewers. Only reviewers with write +// access to the repository are considered. // -// This is very similar to GitHub's built-in branch protection option to require pull request -// reviews before merging, but allows for much more flexibility and customization. +// This is very similar to GitHub's built-in branch protection option to require +// pull request reviews before merging, but allows for much more flexibility and +// customization. // dependencies: lodash4 -// The number of approvals required to merge. -let numApprovalsRequired = 1; +// Helper function to check if a user is a bot. +function isBotAuthor(author) { + return ( + author.username.endsWith("[bot]") || author.username.startsWith("toktok-") + ); +} + +function equals(a) { + return (b) => a === b; +} + +// The number of approvals required to merge: at least 2 humans must approve the +// code. If the author is a bot, then 2 approvals are required; otherwise, only +// 1 approval is required (because 1 human wrote the code, so they approve). +let numApprovalsRequired = isBotAuthor(review.pullRequest.author) ? 2 : 1; const approvals = review.pullRequest.approvals; -let numApprovals = _.filter(approvals, (x) => x === 'approved').length; -const numRejections = _.filter(approvals, (x) => x === 'changes_requested').length; +let numApprovals = _.filter(approvals, equals("approved")).length; +const numRejections = _.filter(approvals, equals("changes_requested")).length; const discussionBlockers = _(review.discussions) .filter((x) => !x.resolved) - .flatMap('participants') + .flatMap("participants") .filter((x) => !x.resolved) - .map(user => _.pick(user, 'username')) + .map((user) => _.pick(user, "username")) .value(); let pendingReviewers = _(discussionBlockers) - .map(user => _.pick(user, 'username')) + .map((user) => _.pick(user, "username")) .concat(review.pullRequest.requestedReviewers) .value(); -const required = _.map(review.pullRequest.assignees, 'username'); +const required = _.map(review.pullRequest.assignees, "username"); _.pull(required, review.pullRequest.author.username); if (required.length) { numApprovalsRequired = _.max([required.length, numApprovalsRequired]); numApprovals = - (_(approvals).pick(required).filter('approved').size()) + + _(approvals).pick(required).filter(equals("approved")).size() + _.min([numApprovals, numApprovalsRequired - required.length]); pendingReviewers = _(required) - .reject(username => approvals[username] === 'approved') - .reject(username => pendingReviewers.length && approvals[username]) - .map(username => ({username})) + .reject((username) => approvals[username] === "approved") + .reject((username) => pendingReviewers.length && approvals[username]) + .map((username) => ({ username })) .concat(pendingReviewers) .value(); } -pendingReviewers = _.uniqBy(pendingReviewers, 'username'); +pendingReviewers = _.uniqBy(pendingReviewers, "username"); const description = - (numRejections ? `${numRejections} change requests, ` : '') + + (numRejections ? `${numRejections} change requests, ` : "") + `${numApprovals} of ${numApprovalsRequired} approvals obtained`; const shortDescription = - (numRejections ? `${numRejections} ✗, ` : '') + `${numApprovals} of ${numApprovalsRequired} ✓`; + (numRejections ? `${numRejections} ✗, ` : "") + + `${numApprovals} of ${numApprovalsRequired} ✓`; return { completed: numApprovals >= numApprovalsRequired, - description, shortDescription, pendingReviewers + description, + shortDescription, + pendingReviewers, };