Skip to content

Commit

Permalink
Merge branch 'trunk' into add/protect-fixer-status-to-initial-state
Browse files Browse the repository at this point in the history
  • Loading branch information
dkmyta committed Sep 12, 2024
2 parents 6ad1341 + b68d4ee commit a9ddd99
Show file tree
Hide file tree
Showing 39 changed files with 665 additions and 217 deletions.
5 changes: 3 additions & 2 deletions .phan/stubs/wpcom-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* `bin/teamcity-builds/jetpack-stubs/stub-defs.php` and regenerate the stubs
* by triggering the Jetpack Staging → Update WPCOM Stubs job in TeamCity.
*
* Stubs automatically generated from WordPress.com commit a64dc4c8302d07cdb2c6f67e03d7414f923a0b21.
* Stubs automatically generated from WordPress.com commit 2ecbaded3770357dd642a1095d8eb62a6c3793a8.
*/

namespace {
Expand Down Expand Up @@ -182,9 +182,10 @@ public static function get_from_cache()
}
/**
* @param int $blog_id
* @param bool $include_available
* @return array
*/
public static function get_site_specific_features_data($blog_id = 0)
public static function get_site_specific_features_data($blog_id = 0, $include_available = \true)
{
}
public static function api_only_get_active_plans_v1_4($blog_id = \false, $coupon_code = \null, $use_query_param_data = \false)
Expand Down
18 changes: 15 additions & 3 deletions projects/github-actions/test-results-to-slack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
name: 'Send Slack notification'
runs-on: ubuntu-latest
needs: run-tests
# Notify even if tests failed.
if: ${{ !cancelled() }}

steps:
- name: Download test artifacts
Expand All @@ -74,16 +76,26 @@ jobs:
The action relies on the following parameters.
- (Required) `github_token` is a GitHub Access Token used to access GitHub's API. The token should be stored in a [secret](https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository)
- (Required) `slack_token` is the Auth token of a bot that is installed on your Slack workspace. The token should be stored in a [secret](https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository). See the [instructions here](https://slack.com/intl/en-hu/help/articles/115005265703-Create-a-bot-for-your-workspace) on how to create a bot.
- (Required) `github_token` is a GitHub Access Token used to access GitHub's API. The token should be stored in a [secret](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository).
- (Required) `slack_token` is the Auth token of a bot that is installed on your Slack workspace. See [Slack token](#slack-token) below for details. The token should be stored in a [secret](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository).
- (Required) `slack_channel` is the Slack channel ID where the messages will be sent to. Check the channel's details in your Slack app to find the channel ID.
- (Optional) `slack_username` is the Slack username the bot will use to send messages. Defaults to "GitHub Reporter".
- (Optional) `slack_icon_emoji` is the icon emoji to use for messages. If not set it will use your app's default icon.
- (Optional) `suite_name` is the name of the test suite. It will be included in the message, and it can also be used to define notification rules. See more in the Rules section.
- (Optional) `rules_configuration_path` is the path to the configuration file that defines the rules. See more in the Rules section.
- (Optional) `playwright_report_path` is the path to the JSON report, output from Playwright test runner JSON reporter. See [Playwright's docs]( https://playwright.dev/docs/test-reporters#json-reporter) for details on how to generate this file. If specified, it will be parsed and failures details will be included in the message. You can use the glob pattern to specify multiple files. For example: `playwright_report_path: 'artifacts/**/report.json'`.
- (Optional) `playwright_report_path` is the path to the JSON report, output from Playwright test runner JSON reporter. See [Playwright's docs](https://playwright.dev/docs/test-reporters#json-reporter) for details on how to generate this file. If specified, it will be parsed and failures details will be included in the message. You can use the glob pattern to specify multiple files. For example: `playwright_report_path: 'artifacts/**/report.json'`.
- (Optional) `playwright_output_dir` is the path to the Playwright's configured output directory, where results and attachments are saved. It is needed when the artefacts are downloaded from a previous job, and the absolute paths to attachments found in the JSON report are not valid anymore. This path will be used to convert the paths to those attachments. You can use the glob pattern. For example: `playwright_output_dir: 'artifacts/**/results'`

### Slack token

You will need to [create a Slack bot for your workspace](https://slack.com/intl/en-hu/help/articles/115005265703-Create-a-bot-for-your-workspace) for the action to use. The bot will need the following scopes:

- `chat:write` - To post messages to the configured channel.
- `chat:write.public` - If the bot is not a member of the configured channel.
- `chat:write.customize` - For the `slack_username` and `slack_icon_emoji` parmeters to work.
- `channels:history` - For the bot to find its messages from previous runs to update.
- `files:write` - For the bot to upload PNG images (if any) along with the report.

### Rules

You can configure different rules, to send notifications in multiple channels.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Document required Slack scopes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Add more helpful error messages and help steps on license key activation error.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { JetpackLogo, Spinner } from '@automattic/jetpack-components';
import { Button, TextControl, SelectControl } from '@wordpress/components';
import { createInterpolateElement } from '@wordpress/element';
import { sprintf, __ } from '@wordpress/i18n';
import { Icon, warning } from '@wordpress/icons';
import PropTypes from 'prop-types';
import React, { useCallback, useEffect, useMemo, useState } from 'react';

import ActivationScreenError from '../activation-screen-error';
import { LICENSE_ERRORS } from '../activation-screen-error/constants';
import './style.scss';

/**
Expand Down Expand Up @@ -145,15 +145,26 @@ const ActivationScreenControls = props => {
licenseError,
onLicenseChange,
} = props;
const hasLicenseError = licenseError !== null && licenseError !== undefined;

useEffect( () => {
jetpackAnalytics.tracks.recordEvent( 'jetpack_wpa_license_key_activation_view' );
}, [] );

const className = hasLicenseError
? 'jp-license-activation-screen-controls--license-field-with-error'
: 'jp-license-activation-screen-controls--license-field';
const errorTypeMatch = licenseError?.match( /\[[a-z_]+\]/ );
const errorType = errorTypeMatch && errorTypeMatch[ 0 ];

const { ACTIVE_ON_SAME_SITE } = LICENSE_ERRORS;
const isLicenseAlreadyAttached = ACTIVE_ON_SAME_SITE === errorType;
const className = useMemo( () => {
if ( ! licenseError ) {
return 'jp-license-activation-screen-controls--license-field';
}
if ( isLicenseAlreadyAttached ) {
return 'jp-license-activation-screen-controls--license-field-with-success';
}

return 'jp-license-activation-screen-controls--license-field-with-error';
}, [ licenseError, isLicenseAlreadyAttached ] );

const hasAvailableLicenseKey = availableLicenses && availableLicenses.length;

Expand Down Expand Up @@ -189,11 +200,8 @@ const ActivationScreenControls = props => {
value={ license }
/>
) }
{ hasLicenseError && (
<div className="jp-license-activation-screen-controls--license-field-error">
<Icon icon={ warning } />
<span>{ licenseError }</span>
</div>
{ licenseError && (
<ActivationScreenError licenseError={ licenseError } errorType={ errorType } />
) }
</div>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@


.jp-license-activation-screen-controls--license-field,
.jp-license-activation-screen-controls--license-field-with-error {
.jp-license-activation-screen-controls--license-field-with-error,
.jp-license-activation-screen-controls--license-field-with-success {
max-width: 500px;
.components-input-control__label.components-input-control__label.components-input-control__label {
font-weight: 600;
Expand Down Expand Up @@ -67,21 +68,10 @@
}
}

.jp-license-activation-screen-controls--license-field-error {
display: flex;
flex-direction: row;
align-items: flex-start;
color: var(--jp-red);
max-width: 500px;

svg {
margin-right: 4px;
fill: var(--jp-red);
min-width: 24px;
}

span {
font-size: var(--font-body);
.jp-license-activation-screen-controls--license-field-with-success {
input.components-text-control__input,
select.components-select-control__input {
border: 1px solid var(--jp-green);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe( 'ActivationScreenControls', () => {
expect( node ).toBeInTheDocument();
expect(
// eslint-disable-next-line testing-library/no-node-access
node.closest( '.jp-license-activation-screen-controls--license-field-error' )
node.closest( '.activation-screen-error__message' )
).toBeInTheDocument();
} );
} );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const LICENSE_ERRORS = {
NOT_SAME_OWNER: '[not_same_owner]',
ACTIVE_ON_SAME_SITE: '[active_on_same_site]',
ATTACHED_LICENSE: '[attached_license]',
PRODUCT_INCOMPATIBILITY: '[product_incompatibility]',
REVOKED_LICENSE: '[revoked_license]',
INVALID_INPUT: '[invalid_input]',
MULTISITE_INCOMPATIBILITY: '[multisite_incompatibility]',
} as const;
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import jetpackAnalytics from '@automattic/jetpack-analytics';
import { Icon, warning, check } from '@wordpress/icons';
import React, { useEffect } from 'react';
import { LICENSE_ERRORS } from './constants';
import { useGetErrorContent } from './use-get-error-content';
import type { FC } from 'react';

import './style.scss';

type LicenseErrorKeysType = keyof typeof LICENSE_ERRORS;
type LicenseErrorValuesType = ( typeof LICENSE_ERRORS )[ LicenseErrorKeysType ];

interface Props {
licenseError: string;
errorType: LicenseErrorValuesType;
}

const ActivationScreenError: FC< Props > = ( { licenseError, errorType } ) => {
useEffect( () => {
if ( licenseError ) {
jetpackAnalytics.tracks.recordEvent( 'jetpack_wpa_license_activation_error_view', {
error: licenseError,
error_type: errorType,
} );
}
}, [ licenseError, errorType ] );

const { errorMessage, errorInfo } = useGetErrorContent( licenseError, errorType );

if ( ! licenseError ) {
return null;
}

const { ACTIVE_ON_SAME_SITE } = LICENSE_ERRORS;
const isLicenseAlreadyAttached = ACTIVE_ON_SAME_SITE === errorType;

const errorMessageClass = isLicenseAlreadyAttached
? 'activation-screen-error__message--success'
: 'activation-screen-error__message--error';

return (
<>
<div className={ `activation-screen-error__message ${ errorMessageClass }` }>
<Icon icon={ isLicenseAlreadyAttached ? check : warning } size={ 20 } />
<span>{ errorMessage }</span>
</div>
{ errorInfo && <div className="activation-screen-error__info">{ errorInfo }</div> }
</>
);
};

export default ActivationScreenError;
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
.activation-screen-error__message {
display: flex;
flex-direction: row;
align-items: flex-start;
max-width: 500px;
margin-top: calc(var(--spacing-base)*.5);

svg {
margin-left: -3px;
}

span {
font-size: 13px;
line-height: 20px;
font-weight: 500;
letter-spacing: -0.044em;
}
}

.activation-screen-error__message--error {
color: var(--jp-red);
svg {
fill: var(--jp-red);
}
}

.activation-screen-error__message--success {
color: var(--jp-green);
svg {
fill: var(--jp-green);
}
}

.activation-screen-error__info {
background-color: var(--jp-gray-0);
color: var(--jp-gray-80);
font-size: var(--font-body-small);
line-height: calc(var(--font-title-small) - 2px);
border: 1px solid var(--jp-green-0);
border-radius: var(--jp-border-radius);
padding: var(--jp-modal-padding-small);
margin: 32px 0 8px;

> p {
margin: 0 0 1em;
font-size: var(--font-body-small);
}
> p:last-child {
margin-bottom: 0;
}

ol > li::marker {
font-weight: bold;
}

a {
color: var(--jp-green-50);
}
a:hover,
a:active {
color: var(--jp-green-70);
}
}

.jp-license-activation-screen-controls {
.activation-screen-error__info {
> p {
margin: 0 0 1em;
font-size: var(--font-body-small);
}
> p:last-child {
margin-bottom: 0;
}
}
}
Loading

0 comments on commit a9ddd99

Please sign in to comment.