Skip to content

Commit

Permalink
Merge branch 'trunk' into fix/rdv-regressions-on-treatment
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanUngureanu committed Dec 20, 2024
2 parents 3069531 + cc8c2f2 commit df12898
Show file tree
Hide file tree
Showing 110 changed files with 5,078 additions and 2,601 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gardening.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
composer build-development
working-directory: ./projects/github-actions/repo-gardening

- name: Checkout the PR
- name: Check out the PR
if: github.event_name == 'pull_request_target' && github.event.pull_request.state != 'closed'
uses: actions/checkout@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion docs/git-workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ If you're working directly with Jetpack trunk and need to update an external con
This method assumes you are using the `gh` shorthand from the [Github CLI](https://cli.github.com/):

```sh
# Use the Github CLI to checkout the PR with the PR number - for example gh pr checkout 12345.
# Use the Github CLI to check out the PR with the PR number - for example gh pr checkout 12345.
gh pr checkout xxxxx

# Run merge-base to check where that branch differed from trunk - example git merge-base update/broken-jetpack-feature trunk.
Expand Down
2 changes: 1 addition & 1 deletion projects/github-actions/repo-gardening/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ To get the channel ID of the channel where you'd like to post, copy one of the m
Certain tasks require filesystem access to the PR, which `pull_request_target` does not provide. To accommodate this, you'll need to include a step to check the PR out in a subdirectory, like

```yaml
- name: Checkout the PR
- name: Check out the PR
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v4
with:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Gardening: Prevent error if more than 100 labels are added to a PR.


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Gardening: Add an "all the things" label if more than 90 labels are on a PR.


Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { getInput } = require( '@actions/core' );
const debug = require( '../../utils/debug' );
const getFiles = require( '../../utils/get-files' );
const getLabels = require( '../../utils/labels/get-labels' );

/* global GitHub, WebhookPayloadPullRequest */

Expand Down Expand Up @@ -49,7 +50,7 @@ function cleanName( name ) {
}

/**
* Build a list of labels to add to the issue, based off our file list.
* Build a list of labels to add to the pull request, based off our file list.
*
* @param {GitHub} octokit - Initialized Octokit REST client.
* @param {string} owner - Repository owner.
Expand All @@ -59,7 +60,7 @@ function cleanName( name ) {
* @param {boolean} isRevert - Whether the pull request is a revert.
* @return {Promise<Array>} Promise resolving to an array of keywords we'll search for.
*/
async function getLabelsToAdd( octokit, owner, repo, number, isDraft, isRevert ) {
async function getFileDerivedLabels( octokit, owner, repo, number, isDraft, isRevert ) {
const keywords = new Set();

// Get next valid milestone.
Expand Down Expand Up @@ -320,7 +321,7 @@ async function getLabelsToAdd( octokit, owner, repo, number, isDraft, isRevert )
}

/**
* Assigns any issues that are being worked to the author of the matching PR.
* Adds appropriate labels to the specified PR.
*
* @param {WebhookPayloadPullRequest} payload - Pull request event payload.
* @param {GitHub} octokit - Initialized Octokit REST client.
Expand All @@ -330,26 +331,83 @@ async function addLabels( payload, octokit ) {
const { owner, name } = repository;
const { draft, title } = pull_request;

// GitHub allows 100 labels on a PR.
// Limit to less than that to allow a buffer for future manual labels.
const maxLabels = 90;
const bigProjectLabel = '[Project] All the things!';

// Get labels to add to the PR.
const isDraft = !! ( pull_request && draft );

// If the PR title includes the word "revert", mark it as such.
const isRevert = title.toLowerCase().includes( 'revert' );

const labels = await getLabelsToAdd( octokit, owner.login, name, number, isDraft, isRevert );
const fileDerivedLabels = await getFileDerivedLabels(
octokit,
owner.login,
name,
number,
isDraft,
isRevert
);

// Grab current labels on the PR.
// We can't rely on payload, as it could be outdated by the time this runs.
const currentLabels = await getLabels( octokit, owner.login, name, number );

// This is an array of labels that GitHub doesn't already have.
let labelsToAdd = fileDerivedLabels.filter( label => ! currentLabels.includes( label ) );

if ( ! labels.length ) {
debug( 'add-labels: Could not find labels to add to that PR. Aborting' );
// Nothing new was added, so abort.
if ( labelsToAdd.length === 0 ) {
debug( 'add-labels: No new labels to add to that PR. Aborting.' );
return;
}

debug( `add-labels: Adding labels ${ labels } to PR #${ number }` );
// Determine how many labels can safely be added.
let maxLabelsToAdd = Math.max( 0, maxLabels - currentLabels.length );

// Overkill, but let's prevent this label from counting toward the max.
const hasBigProjectLabel = currentLabels.includes( bigProjectLabel );
if ( hasBigProjectLabel ) {
maxLabelsToAdd++;
}

// If there are too many labels, we need to reduce the label count to keep GitHub happy.
if ( labelsToAdd.length > maxLabelsToAdd ) {
debug( `add-labels: Too many labels! Grouping project labels into '${ bigProjectLabel }'.` );

// Filter out project-type labels in deference to bigProjectLabel.
// In theory we could also remove any existing project-type labels here, but for now
// let's not as that would prevent manually adding specific project labels.
const projectLabelRegex = /^(\[Action\]|\[Package\]|\[Plugin\]|\[JS Package\])/;
labelsToAdd = labelsToAdd.filter( label => ! projectLabelRegex.test( label ) );

if ( ! hasBigProjectLabel ) {
// Add to the beginning of the labels array in case the array gets truncated later on.
labelsToAdd.unshift( bigProjectLabel );
}
} else if ( hasBigProjectLabel ) {
await octokit.rest.issues.removeLabel( {
owner: owner.login,
repo: name,
issue_number: number,
name: bigProjectLabel,
} );
}
// In the rare chance there would still be too many labels...
if ( labelsToAdd.length > maxLabelsToAdd ) {
debug( `add-labels: Limiting to the first ${ maxLabels }.` );
labelsToAdd.splice( maxLabelsToAdd );
}

debug( `add-labels: Adding labels ${ labelsToAdd } to PR #${ number }` );

await octokit.rest.issues.addLabels( {
owner: owner.login,
repo: name,
issue_number: number,
labels,
labels: labelsToAdd,
} );
}

Expand Down
4 changes: 4 additions & 0 deletions projects/js-packages/charts/changelog/add-charts-build
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Adding build option for Charts.
6 changes: 6 additions & 0 deletions projects/js-packages/charts/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
]
},
"scripts": {
"build-development": [
"pnpm run build"
],
"build-production": [
"NODE_ENV=production pnpm run build"
],
"test-coverage": [
"pnpm run test-coverage"
],
Expand Down
19 changes: 19 additions & 0 deletions projects/js-packages/charts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Charts
export { BarChart } from './src/components/bar-chart';
export { LineChart } from './src/components/line-chart';
export { PieChart } from './src/components/pie-chart';
export { PieSemiCircleChart } from './src/components/pie-semi-circle-chart';

// Chart components
export { BaseTooltip } from './src/components/tooltip';
export { Legend } from './src/components/legend';

// Providers
export { ThemeProvider } from './src/providers/theme';

// Hooks
export { default as useChartMouseHandler } from './src/hooks/use-chart-mouse-handler';

// Types
export type * from './src/components/shared/types';
export type { BaseTooltipProps } from './src/components/tooltip';
5 changes: 4 additions & 1 deletion projects/js-packages/charts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
"clean": "rm -rf node_modules",
"test": "jest --config=tests/jest.config.cjs",
"test-coverage": "pnpm run test --coverage",
"storybook": "cd ../storybook && pnpm run storybook:dev"
"storybook": "cd ../storybook && pnpm run storybook:dev",
"compile-ts": "tsc --pretty",
"build": "pnpm run clean-build && pnpm run compile-ts",
"clean-build": "rm -rf build/"
},
"dependencies": {
"@react-spring/web": "9.7.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from './bar-chart';
export { default as BarChart } from './bar-chart';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BarChart from '../index';
import { BarChart } from '../index';
import data from './sample-data';
import type { Meta, StoryObj } from '@storybook/react';

Expand Down
4 changes: 3 additions & 1 deletion projects/js-packages/charts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Charts
export { default as BarChart } from './components/bar-chart';
export { BarChart } from './components/bar-chart';
export { LineChart } from './components/line-chart';
export { PieChart } from './components/pie-chart';
export { PieSemiCircleChart } from './components/pie-semi-circle-chart';

// Chart components
export { BaseTooltip } from './components/tooltip';
export { Legend } from './components/legend';

// Providers
export { ThemeProvider } from './providers/theme';

// Hooks
export { default as useChartMouseHandler } from './hooks/use-chart-mouse-handler';

// Types
export type * from './components/shared/types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Meta, StoryObj } from '@storybook/react';
import { ThemeProvider, jetpackTheme, wooTheme } from '../.';
import { LineChart, BarChart, PieSemiCircleChart } from '../../..';
import { LineChart, BarChart, PieSemiCircleChart } from '../../../.';
import barSampleData from '../../../components/bar-chart/stories/sample-data';

const meta: Meta< typeof LineChart > = {
Expand Down
2 changes: 1 addition & 1 deletion projects/js-packages/charts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"outDir": "./build/"
},
// List all sources and source-containing subdirs.
"include": [ "./src" ]
"include": [ "./index.ts", "./src" ]
}
3 changes: 2 additions & 1 deletion projects/packages/classic-theme-helper/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// PhanUndeclaredClassMethod : 20+ occurrences
// PhanTypeMismatchArgumentInternal : 10+ occurrences
// PhanTypePossiblyInvalidDimOffset : 8 occurrences
// PhanTypeSuspiciousNonTraversableForeach : 6 occurrences
// PhanTypeMismatchArgumentProbablyReal : 5 occurrences
// PhanUndeclaredClassReference : 4 occurrences
// PhanTypeSuspiciousNonTraversableForeach : 3 occurrences
// PhanTypeInvalidDimOffset : 2 occurrences
// PhanTypeMismatchArgument : 2 occurrences
// PhanTypeComparisonToArray : 1 occurrence
Expand All @@ -30,6 +30,7 @@
'src/custom-content-types.php' => ['PhanUndeclaredClassMethod'],
'src/custom-post-types/class-jetpack-portfolio.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanTypeSuspiciousNonTraversableForeach', 'PhanUndeclaredClassMethod'],
'src/custom-post-types/class-jetpack-testimonial.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredClassMethod'],
'src/custom-post-types/class-nova-restaurant.php' => ['PhanTypeSuspiciousNonTraversableForeach'],
'src/site-breadcrumbs.php' => ['PhanUndeclaredClassMethod'],
],
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Custom Post Types: Added Restaurant Menu CPT files.
Loading

0 comments on commit df12898

Please sign in to comment.