Skip to content

Commit

Permalink
Merge branch 'master' into table-title-idref
Browse files Browse the repository at this point in the history
  • Loading branch information
tw15egan authored Mar 31, 2020
2 parents 622d348 + 2490120 commit b5edac6
Show file tree
Hide file tree
Showing 117 changed files with 2,979 additions and 910 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/add-review-labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Add Review Labels
on: pull_request_review
jobs:
reviewer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: ./actions/add-review-labels
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AUTO_LABEL_USERS: 'asudoh,emyarod,tw15egan'
Binary file added .yarn/offline-mirror/@actions-core-1.2.3.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/@octokit-graphql-4.3.1.tgz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added .yarn/offline-mirror/@octokit-request-5.3.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@octokit-rest-16.43.1.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/@octokit-types-2.5.0.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/fast-glob-3.2.2.tgz
Binary file not shown.
Binary file added .yarn/offline-mirror/tunnel-0.0.6.tgz
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions actions/add-review-labels/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/__mocks__/**
**/__tests__/**
**/examples/**
**/tasks/**
6 changes: 6 additions & 0 deletions actions/add-review-labels/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM node:slim

WORKDIR /usr/src/action
COPY . .
RUN yarn install --production
ENTRYPOINT ["node", "/usr/src/action/index.js"]
12 changes: 12 additions & 0 deletions actions/add-review-labels/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Add review labels
description: A custom action that adds review labels to a Pull Request
inputs:
GITHUB_TOKEN:
description: A GitHub token to execute GitHub tasks
required: true
AUTO_LABEL_USERS:
description:
Opt-in users who want the ready to merge label automatically applied
runs:
using: 'docker'
image: 'Dockerfile'
162 changes: 162 additions & 0 deletions actions/add-review-labels/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/**
* Copyright IBM Corp. 2020, 2020
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

'use strict';

const github = require('@actions/github');
const core = require('@actions/core');

async function run() {
const { context } = github;
const token = core.getInput('GITHUB_TOKEN', {
required: true,
});
const autoLabelUsers = core.getInput('AUTO_LABEL_USERS').split(',');
const octokit = new github.GitHub(token);
const { pull_request: pullRequest, repository, review } = context.payload;
const { state, draft } = pullRequest;

// We only want to work with Pull Requests that are marked as open
if (state !== 'open') {
return;
}

// We only want to work with Pull Requests that are not draft PRs
if (draft) {
return;
}

const {
data: permissionLevel,
} = await octokit.repos.getCollaboratorPermissionLevel({
owner: repository.owner.login,
repo: repository.name,
username: review.user.login,
});

// If the reviewer doesn't have one of the following permission levels
// then ignore the event
const acceptedPermissionLevels = new Set(['admin', 'write']);
if (!acceptedPermissionLevels.has(permissionLevel.permission)) {
return;
}

// If the review was not an approval then we'll ignore the event
if (review.state !== 'approved') {
return;
}

const { data: allReviews } = await octokit.pulls.listReviews({
owner: repository.owner.login,
repo: repository.name,
pull_number: pullRequest.number,
per_page: 100,
});

// The `listReviews` endpoint will return all of the reviews for the pull
// request. We only care about the most recent reviews so we'll go through the
// list and get the most recent review for each reviewer
const reviewers = {};
const reviews = [];

// Process reviews in reverse order since they are listed from oldest to newest
for (const review of allReviews.reverse()) {
const { author_association: association, user } = review;
// If we've already saved a review for this user we already have the most
// recent review
if (reviewers[user.login]) {
continue;
}

// If the author of the review is not a collaborator we ignore it
if (association !== 'COLLABORATOR') {
continue;
}

reviewers[user.login] = true;
reviews.push(review);
}

const approved = reviews.filter(review => {
return review.state === 'APPROVED';
});

const additionalReviewLabel = 'status: one more review 👀';
const readyForReviewLabel = 'status: ready for review 👀';
const readyToMergeLabel = 'status: ready to merge 🎉';
const visualReviewLabel = 'status: visual review 🔍';
const contentReviewLabel = 'status: content review ✍️';
const needsReviewLabels = new Set([visualReviewLabel, contentReviewLabel]);

if (approved.length > 0) {
const hasReadyLabel = pullRequest.labels.find(label => {
return label.name === readyForReviewLabel;
});
if (hasReadyLabel) {
await octokit.issues.removeLabel({
owner: repository.owner.login,
repo: repository.name,
issue_number: pullRequest.number,
name: readyForReviewLabel,
});
}
}

if (approved.length === 1) {
const hasAdditionalReviewLabel = pullRequest.labels.find(label => {
return label.name === additionalReviewLabel;
});
if (!hasAdditionalReviewLabel) {
await octokit.issues.addLabels({
owner: repository.owner.login,
repo: repository.name,
issue_number: pullRequest.number,
labels: [additionalReviewLabel],
});
}
return;
}

if (approved.length >= 2) {
const hasAdditionalReviewLabel = pullRequest.labels.find(label => {
return label.name === additionalReviewLabel;
});
if (hasAdditionalReviewLabel) {
await octokit.issues.removeLabel({
owner: repository.owner.login,
repo: repository.name,
issue_number: pullRequest.number,
name: additionalReviewLabel,
});
}

const allNeedsReviewLabels = pullRequest.labels.filter(label => {
return needsReviewLabels.has(label.name);
});
if (allNeedsReviewLabels.length > 0) {
return;
}

const shouldAutoLabel = autoLabelUsers.find(user => {
return user === pullRequest.user.login;
});
if (shouldAutoLabel) {
await octokit.issues.addLabels({
owner: repository.owner.login,
repo: repository.name,
issue_number: pullRequest.number,
labels: [readyToMergeLabel],
});
}
return;
}
}

run().catch(error => {
console.log(error);
process.exit(1);
});
20 changes: 20 additions & 0 deletions actions/add-review-labels/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@carbon/actions-add-review-labels",
"private": true,
"version": "0.0.1",
"license": "Apache-2.0",
"main": "index.js",
"repository": "https://github.com/carbon-design-system/carbon/tree/master/actions/add-review-labels",
"bugs": "https://github.com/carbon-design-system/carbon/issues",
"keywords": [
"ibm",
"carbon",
"carbon-design-system",
"components",
"react"
],
"dependencies": {
"@actions/core": "^1.2.3",
"@actions/github": "^2.1.1"
}
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"workspaces": {
"packages": [
"packages/*"
"packages/*",
"actions/*"
],
"nohoist": []
},
Expand All @@ -20,7 +21,7 @@
"doctoc": "doctoc --title '## Table of Contents'",
"format": "prettier --write '**/*.{js,md,scss,ts}' '!**/{build,es,lib,storybook,ts,umd}/**'",
"format:diff": "prettier --list-different '**/*.{js,md,scss,ts}' '!**/{build,es,lib,storybook,ts,umd}/**' '!packages/components/**'",
"lint": "eslint packages",
"lint": "eslint packages actions",
"lint:docs": "alex 'docs/**/*.md' -q",
"lint:styles": "stylelint '**/*.{css,scss}' --config ./packages/stylelint-config-elements",
"sync": "carbon-cli sync",
Expand All @@ -42,7 +43,7 @@
"@babel/preset-env": "^7.7.7",
"@babel/preset-react": "^7.7.4",
"@babel/runtime": "^7.7.7",
"@carbon/cli": "10.8.0",
"@carbon/cli": "10.8.1",
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"@ibma/aat": "https://able.ibm.com/tools/dist/ibma-aat-2.0.6.tgz",
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@carbon/cli",
"description": "Task automation for working with the Carbon Design System",
"version": "10.8.0",
"version": "10.8.1",
"license": "Apache-2.0",
"bin": {
"carbon-cli": "./bin/carbon-cli.js"
Expand All @@ -26,6 +26,7 @@
"chalk": "^2.4.2",
"child-process-promise": "^2.2.1",
"clipboardy": "^2.1.0",
"fast-glob": "^3.2.2",
"fs-extra": "^8.0.1",
"inquirer": "^6.4.1",
"prettier": "^1.19.1",
Expand Down
65 changes: 35 additions & 30 deletions packages/cli/src/commands/sync/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
const fs = require('fs-extra');

const REPO_URL_BASE =
'https://github.com/carbon-design-system/carbon/tree/master/packages';
'https://github.com/carbon-design-system/carbon/tree/master';

// This is our default set of keywords to include in each `package.json` packageJson
const DEFAULT_KEYWORDS = [
Expand Down Expand Up @@ -71,39 +71,44 @@ function sortFields(a, b) {

function run({ packagePaths }) {
return Promise.all(
packagePaths.map(async ({ basename, packageJsonPath, packageJson }) => {
packageJson.repository = `${REPO_URL_BASE}/${basename}`;
packageJson.bugs =
'https://github.com/carbon-design-system/carbon/issues';
packageJson.license = 'Apache-2.0';
packageJson.publishConfig = {
access: 'public',
};
packagePaths.map(
async ({ packageJsonPath, packageJson, packageFolder }) => {
packageJson.repository = `${REPO_URL_BASE}/${packageFolder}`;
packageJson.bugs =
'https://github.com/carbon-design-system/carbon/issues';
packageJson.license = 'Apache-2.0';

if (Array.isArray(packageJson.keywords)) {
const keywordsToAdd = DEFAULT_KEYWORDS.filter(keyword => {
return packageJson.keywords.indexOf(keyword) === -1;
});
if (keywordsToAdd.length > 0) {
packageJson.keywords = [...packageJson.keywords, ...keywordsToAdd];
if (!packageJson.private) {
packageJson.publishConfig = {
access: 'public',
};
}

if (Array.isArray(packageJson.keywords)) {
const keywordsToAdd = DEFAULT_KEYWORDS.filter(keyword => {
return packageJson.keywords.indexOf(keyword) === -1;
});
if (keywordsToAdd.length > 0) {
packageJson.keywords = [...packageJson.keywords, ...keywordsToAdd];
}
} else {
packageJson.keywords = DEFAULT_KEYWORDS;
}
} else {
packageJson.keywords = DEFAULT_KEYWORDS;
}

// Construct our new packageJson packageJson with sorted fields
const file = Object.keys(packageJson)
.sort(sortFields)
.reduce(
(acc, key) => ({
...acc,
[key]: packageJson[key],
}),
{}
);
// Construct our new packageJson packageJson with sorted fields
const file = Object.keys(packageJson)
.sort(sortFields)
.reduce(
(acc, key) => ({
...acc,
[key]: packageJson[key],
}),
{}
);

await fs.writeJson(packageJsonPath, file, { spaces: 2 });
})
await fs.writeJson(packageJsonPath, file, { spaces: 2 });
}
)
);
}

Expand Down
Loading

0 comments on commit b5edac6

Please sign in to comment.