Skip to content

Commit

Permalink
Merge branch 'develop' into pnf/23946
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwalsh0 authored Jun 19, 2024
2 parents cc91236 + 2115516 commit dc7c25a
Show file tree
Hide file tree
Showing 263 changed files with 13,964 additions and 3,112 deletions.
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,10 @@ jobs:
name: build:debug
command: find dist/ -type f -exec md5sum {} \; | sort -k 2
- run:
name: Move mmi build to 'dist-mv2' to avoid conflict with production build
name: Move mm build to 'dist-mv2' to avoid conflict with production build
command: mv ./dist ./dist-mv2
- run:
name: Move mmi zips to 'builds-mv2' to avoid conflict with production build
name: Move mm zips to 'builds-mv2' to avoid conflict with production build
command: mv ./builds ./builds-mv2
- store_artifacts:
path: builds-mv2
Expand Down Expand Up @@ -859,7 +859,7 @@ jobs:
at: .
- run:
name: Build extension for testing
command: ENABLE_CONFIRMATION_REDESIGN=1 yarn build:test
command: ENABLE_CONFIRMATION_REDESIGN=true yarn build:test
- run:
name: Move test build to 'dist-test' to avoid conflict with production build
command: mv ./dist ./dist-test-confirmations
Expand All @@ -881,7 +881,7 @@ jobs:
at: .
- run:
name: Build extension for testing
command: ENABLE_CONFIRMATION_REDESIGN=1 yarn build:test:mv2
command: ENABLE_CONFIRMATION_REDESIGN=true yarn build:test:mv2
- run:
name: Move test build to 'dist-test-confirmations-mv2' to avoid conflict with production build
command: mv ./dist ./dist-test-confirmations-mv2
Expand Down Expand Up @@ -1086,7 +1086,7 @@ jobs:
fi
no_output_timeout: 5m
environment:
ENABLE_CONFIRMATION_REDESIGN: 1
ENABLE_CONFIRMATION_REDESIGN: true
- store_artifacts:
path: test-artifacts
destination: test-artifacts
Expand Down Expand Up @@ -1372,7 +1372,7 @@ jobs:
fi
no_output_timeout: 5m
environment:
ENABLE_CONFIRMATION_REDESIGN: 1
ENABLE_CONFIRMATION_REDESIGN: true
- store_artifacts:
path: test-artifacts
destination: test-artifacts
Expand Down
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ module.exports = {
excludedFiles: [
'app/scripts/controllers/app-state.test.js',
'app/scripts/controllers/mmi-controller.test.js',
'app/scripts/controllers/metametrics.test.js',
'app/scripts/controllers/permissions/**/*.test.js',
'app/scripts/controllers/preferences.test.js',
'app/scripts/lib/**/*.test.js',
Expand Down Expand Up @@ -300,6 +301,7 @@ module.exports = {
'**/__snapshots__/*.snap',
'app/scripts/controllers/app-state.test.js',
'app/scripts/controllers/mmi-controller.test.ts',
'app/scripts/controllers/metametrics.test.js',
'app/scripts/controllers/permissions/**/*.test.js',
'app/scripts/controllers/preferences.test.js',
'app/scripts/lib/**/*.test.js',
Expand Down
89 changes: 89 additions & 0 deletions .github/scripts/add-team-label-to-pr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import * as core from '@actions/core';
import { context, getOctokit } from '@actions/github';
import { GitHub } from '@actions/github/lib/utils';

import { retrieveLabel } from './shared/label';
import { Labelable, addLabelByIdToLabelable } from './shared/labelable';
import { retrievePullRequest } from './shared/pull-request';

main().catch((error: Error): void => {
console.error(error);
process.exit(1);
});

async function main(): Promise<void> {
// "GITHUB_TOKEN" is an automatically generated, repository-specific access token provided by GitHub Actions.
// We can't use "GITHUB_TOKEN" here, as its permissions are scoped to the repository where the action is running.
// "GITHUB_TOKEN" does not have access to other repositories, even when they belong to the same organization.
// As we want to get files which are not necessarily located in the same repository,
// we need to create our own "RELEASE_LABEL_TOKEN" with "repo" permissions.
// Such a token allows to access other repositories of the MetaMask organisation.
const personalAccessToken = process.env.RELEASE_LABEL_TOKEN;
if (!personalAccessToken) {
core.setFailed('RELEASE_LABEL_TOKEN not found');
process.exit(1);
}

// Initialise octokit, required to call Github GraphQL API
const octokit: InstanceType<typeof GitHub> = getOctokit(personalAccessToken, {
previews: ['bane'], // The "bane" preview is required for adding, updating, creating and deleting labels.
});

// Retrieve pull request info from context
const pullRequestRepoOwner = context.repo.owner;
const pullRequestRepoName = context.repo.repo;
const pullRequestNumber = context.payload.pull_request?.number;
if (!pullRequestNumber) {
core.setFailed('Pull request number not found');
process.exit(1);
}

// Retrieve pull request
const pullRequest: Labelable = await retrievePullRequest(
octokit,
pullRequestRepoOwner,
pullRequestRepoName,
pullRequestNumber,
);

// Get the team label id based on the author of the pull request
const teamLabelId = await getTeamLabelIdByAuthor(
octokit,
pullRequestRepoOwner,
pullRequestRepoName,
pullRequest.author,
);

// Add the team label by id to the pull request
await addLabelByIdToLabelable(octokit, pullRequest, teamLabelId);
}

// This helper function gets the team label id based on the author of the pull request
const getTeamLabelIdByAuthor = async (
octokit: InstanceType<typeof GitHub>,
repoOwner: string,
repoName: string,
author: string,
): Promise<string> => {
// Retrieve the teams.json file from the repository
const { data } = (await octokit.request(
'GET /repos/{owner}/{repo}/contents/{path}',
{ owner: repoOwner, repo: 'MetaMask-planning', path: 'teams.json' },
)) as { data: { content: string } };

// Parse the teams.json file content to json from base64
const teamMembers: Record<string, string> = JSON.parse(atob(data.content));

// Get the label name based on the author
const labelName = teamMembers[author];

if (!labelName) {
core.setFailed(`Team label not found for author: ${author}`);
process.exit(1);
}

// Retrieve the label id based on the label name
const labelId = await retrieveLabel(octokit, repoOwner, repoName, labelName);

return labelId;
};
2 changes: 1 addition & 1 deletion .github/scripts/shared/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async function createLabel(
}

// This function retrieves the label on a specific repo
async function retrieveLabel(
export async function retrieveLabel(
octokit: InstanceType<typeof GitHub>,
repoOwner: string,
repoName: string,
Expand Down
23 changes: 16 additions & 7 deletions .github/scripts/shared/labelable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ export interface Labelable {
export function findLabel(
labelable: Labelable,
labelToFind: Label,
): {
id: string;
name: string;
} | undefined {
):
| {
id: string;
name: string;
}
| undefined {
// Check if label is present on labelable
return labelable.labels.find(
(label) => label.name === labelToFind.name,
);
return labelable.labels.find((label) => label.name === labelToFind.name);
}

// This function adds label to a labelable object (i.e. a pull request or an issue)
Expand All @@ -51,6 +51,15 @@ export async function addLabelToLabelable(
label,
);

await addLabelByIdToLabelable(octokit, labelable, labelId);
}

// This function adds label by id to a labelable object (i.e. a pull request or an issue)
export async function addLabelByIdToLabelable(
octokit: InstanceType<typeof GitHub>,
labelable: Labelable,
labelId: string,
): Promise<void> {
const addLabelsToLabelableMutation = `
mutation AddLabelsToLabelable($labelableId: ID!, $labelIds: [ID!]!) {
addLabelsToLabelable(input: {labelableId: $labelableId, labelIds: $labelIds}) {
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/add-team-label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Add team label to PR when it is opened

on:
pull_request:
types:
- opened

jobs:
add-team-label:
runs-on: ubuntu-latest
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 'lts/*'

- run: corepack enable

- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # This is needed to checkout all branches

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: yarn

- name: Install dependencies
run: yarn --immutable

- name: Add team label to PR
id: add-team-label-to-pr
env:
RELEASE_LABEL_TOKEN: ${{ secrets.RELEASE_LABEL_TOKEN }}
run: yarn run add-team-label-to-pr
1 change: 1 addition & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
'./app/scripts/controllers/app-state.test.js',
'./app/scripts/controllers/permissions/**/*.test.js',
'./app/scripts/controllers/mmi-controller.test.ts',
'./app/scripts/controllers/metametrics.test.js',
'./app/scripts/controllers/preferences.test.js',
'./app/scripts/constants/error-utils.test.js',
'./app/scripts/metamask-controller.test.js',
Expand Down
10 changes: 5 additions & 5 deletions .storybook/3.COLORS.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ We follow a 3 tiered system for color design tokens and css variables.
<div
style={{
textAlign: 'center',
backgroundColor: 'var(--brand-colors-white-white000)',
backgroundColor: 'var(--brand-colors-white)',
padding: 32,
}}
>
Expand All @@ -36,9 +36,9 @@ These colors **SHOULD NOT** be used in your styles directly. They are used as a

```css
/** !!!DO NOT USE BRAND COLORS DIRECTLY IN YOUR CODE!!! */
var(--brand-colors-white-white000)
var(--brand-colors-white-white010)
var(--brand-colors-grey-grey030)
var(--brand-colors-white)
var(--brand-colors-black)
var(--brand-colors-grey-grey800)
```

### **Theme colors** (tier 2)
Expand Down Expand Up @@ -168,7 +168,7 @@ Don't use static hex values or brand color tokens in your code.
* Not theme compatible and will break UI when using dark theme
**/
.card {
background-color: var(--brand-colors-white-white000);
background-color: var(--brand-colors-white);
color: var(--brand-colors-grey-grey800);
}
```
Expand Down
16 changes: 8 additions & 8 deletions .storybook/4.SHADOW.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ As well as the neutral colors for shadow 2 other colors exist that are used for
style={{
height: 100,
backgroundColor: 'var(--color-primary-default)',
boxShadow: 'var(--shadow-size-lg) var(--color-primary-shadow)',
boxShadow: 'var(--shadow-size-lg) var(--color-shadow-primary)',
borderRadius: '4px',
display: 'grid',
alignContent: 'center',
Expand All @@ -129,7 +129,7 @@ As well as the neutral colors for shadow 2 other colors exist that are used for
style={{
height: 100,
backgroundColor: 'var(--color-error-default)',
boxShadow: 'var(--shadow-size-lg) var(--color-error-shadow)',
boxShadow: 'var(--shadow-size-lg) var(--color-shadow-error)',
borderRadius: '4px',
display: 'grid',
alignContent: 'center',
Expand All @@ -144,8 +144,8 @@ As well as the neutral colors for shadow 2 other colors exist that are used for
| Color | CSS |
| ----------- | ----------------------------- |
| **neutral** | `var(--color-shadow-default)` |
| **primary** | `var(--color-primary-shadow)` |
| **danger** | `var(--color-error-shadow)` |
| **primary** | `var(--color-shadow-primary)` |
| **danger** | `var(--color-shadow-error)` |

## Example usage

Expand Down Expand Up @@ -232,7 +232,7 @@ Using both size and color tokens, different shadows can be applied to components
justifyContent: 'center',
height: 100,
textAlign: 'center',
boxShadow: 'var(--shadow-size-sm) var(--color-primary-shadow)',
boxShadow: 'var(--shadow-size-sm) var(--color-shadow-primary)',
backgroundColor: 'var(--color-primary-default)',
color: 'var(--color-primary-inverse)',
}}
Expand All @@ -247,7 +247,7 @@ Using both size and color tokens, different shadows can be applied to components
justifyContent: 'center',
height: 100,
textAlign: 'center',
boxShadow: 'var(--shadow-size-sm) var(--color-error-shadow)',
boxShadow: 'var(--shadow-size-sm) var(--color-shadow-error)',
backgroundColor: 'var(--color-error-default)',
color: 'var(--color-error-inverse)',
}}
Expand All @@ -263,8 +263,8 @@ Using both size and color tokens, different shadows can be applied to components
| **Dropdown** | `box-shadow: var(--shadow-size-sm) var(--color-shadow-default);` |
| **Toast** | `box-shadow: var(--shadow-size-md) var(--color-shadow-default);` |
| **Modal** | `box-shadow: var(--shadow-size-lg) var(--color-shadow-default);` |
| **Button Primary Hover** | `box-shadow: var(--shadow-size-sm) var(--color-primary-shadow);` |
| **Button Danger Hover** | `box-shadow: var(--shadow-size-sm) var(--color-error-shadow);` |
| **Button Primary Hover** | `box-shadow: var(--shadow-size-sm) var(--color-shadow-primary);` |
| **Button Danger Hover** | `box-shadow: var(--shadow-size-sm) var(--color-shadow-error);` |

## Takeaways

Expand Down
Loading

0 comments on commit dc7c25a

Please sign in to comment.