Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions .github/workflows/draft.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 0 additions & 25 deletions .github/workflows/release.yml

This file was deleted.

60 changes: 39 additions & 21 deletions .reviewable/completion.js
Original file line number Diff line number Diff line change
@@ -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,
};
Loading